public final class ServerContext extends Object
ServerContextclass contains static methods to execute some action within an appropriate server context for the current thread and to obtain the server context for the current thread.
|Modifier and Type||Class and Description|
Defines the interface for server context providers, which are consulted by
|Modifier and Type||Method and Description|
Sets the server context for the current thread to the supplied
Returns the server context collection for the current thread.
Returns the first element in the current server context collection (obtained by calling
public static void doWithServerContext(Runnable runnable, Collection context)
contextcollection and invokes the
runmethod of the supplied
runnableobject. When this method returns, the thread's server context is unset.
If a server context is currently set for the current thread, that server context cannot be
reset; that is, a server context cannot be overwritten or nested. If a server context is
already set for the current thread, an
IllegalStateException is thrown.
public static Collection getServerContext() throws ServerNotActiveException
ServerContext.doWithServerContext, then an ordered list of providers (obtained as specified below) implementing the
ServerContext.Spiinterface is consulted.
ServerContext.Spi.getServerContext()is called on each provider in turn; the first non-
nullreturn value is returned by this method. If no provider is able to supply a server context collection, then a
The list of server context providers is obtained as follows. For each resource named
META-INF/services/net.jini.export.ServerContext$Spi that is visible to the
system class loader, the contents of the resource are parsed as UTF-8 text to produce a list
of class names. The resource must contain a list of fully-qualified class names, one per
line. Space and tab characters surrounding each name, as well as blank lines, are ignored.
The comment character is '#'; all characters on each line starting with the first
comment character are ignored. Each class name (that is not a duplicate of any previous class
name) is loaded through the system class loader, and the resulting class must be assignable
ServerContext.Spi and have a public no-argument constructor. The constructor is
invoked to create a fallback context provider instance. An implementation is permitted to
search for provider instances eagerly (i.e., upon startup), and cache the verifier instances
rather than recreating them on every call.
The contents of the collection are determined by the caller of
ServerContext.doWithServerContext. The context information available from a given element
of the collection is determined by that element's type. Examples of types that a given
element might implement include
The order of the elements in the collection is insignificant. The collection may be empty.
The caller of this method cannot assume that the returned collection is modifiable.
ServerNotActiveException- if no context is set for the current thread
public static Object getServerContextElement(Class type) throws ServerNotActiveException
ServerContext.getServerContext) that is an instance of the given type
type. If no element in the collection is an instance of the type
type- the type of the element
ServerNotActiveException- if no server context is set for the current thread
Copyright © GigaSpaces.