Class ServerContext
ServerContext class 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.
For example, an Exporter implementation may supply context information for incoming
calls dispatched to its exported remote objects via the ServerContext.doWithServerContext method.
- Since:
- 2.0
- Author:
- Sun Microsystems, Inc.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines the interface for server context providers, which are consulted bygetServerContext()if no server context has been explicitly associated with the current thread via a previous call todoWithServerContext(java.lang.Runnable, java.util.Collection). -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddoWithServerContext(Runnable runnable, Collection context) Sets the server context for the current thread to the suppliedcontextcollection and invokes therunmethod of the suppliedrunnableobject.static CollectionReturns the server context collection for the current thread.static ObjectgetServerContextElement(Class type) Returns the first element in the current server context collection (obtained by callingServerContext.getServerContext) that is an instance of the given typetype.
-
Method Details
-
doWithServerContext
Sets the server context for the current thread to the suppliedcontextcollection and invokes therunmethod of the suppliedrunnableobject. 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
IllegalStateExceptionis thrown.- Parameters:
runnable- the action to perform in the server contextcontext- the context to set- Throws:
NullPointerException- ifcontextorrunnableisnullIllegalStateException- if the context is already set for this thread- See Also:
-
getServerContext
Returns the server context collection for the current thread. If no server context collection has been explicitly specified via a previous call toServerContext.doWithServerContext, then an ordered list of providers (obtained as specified below) implementing theServerContext.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 aServerNotActiveExceptionis thrown.The list of server context providers is obtained as follows. For each resource named
META-INF/services/net.jini.export.ServerContext$Spithat 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 toServerContext.Spiand 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 includeClientHostandClientSubject.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.
- Returns:
- the server context for the current thread
- Throws:
ServerNotActiveException- if no context is set for the current thread
-
getServerContextElement
Returns the first element in the current server context collection (obtained by callingServerContext.getServerContext) that is an instance of the given typetype. If no element in the collection is an instance of the typetype, thennullis returned.- Parameters:
type- the type of the element- Returns:
- the first element in the server context collection that is an instance of the type
typeornull - Throws:
ServerNotActiveException- if no server context is set for the current thread
-