GigaSpaces XAP 10.0.1 API

net.jini.export
Class ServerContext

java.lang.Object
  extended by net.jini.export.ServerContext

public final class ServerContext
extends Object

The 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:
ClientHost, ClientSubject

Nested Class Summary
static interface ServerContext.Spi
          Defines the interface for server context providers, which are consulted by getServerContext() if no server context has been explicitly associated with the current thread via a previous call to doWithServerContext(java.lang.Runnable, java.util.Collection).
 
Method Summary
static void doWithServerContext(Runnable runnable, Collection context)
          Sets the server context for the current thread to the supplied context collection and invokes the run method of the supplied runnable object.
static Collection getServerContext()
          Returns the server context collection for the current thread.
static Object getServerContextElement(Class type)
          Returns the first element in the current server context collection (obtained by calling ServerContext.getServerContext) that is an instance of the given type type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

doWithServerContext

public static void doWithServerContext(Runnable runnable,
                                       Collection context)
Sets the server context for the current thread to the supplied context collection and invokes the run method of the supplied runnable object. 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.

Parameters:
runnable - the action to perform in the server context
context - the context to set
Throws:
NullPointerException - if context or runnable is null
IllegalStateException - if the context is already set for this thread
See Also:
getServerContextElement(java.lang.Class)

getServerContext

public static Collection getServerContext()
                                   throws ServerNotActiveException
Returns the server context collection for the current thread. If no server context collection has been explicitly specified via a previous call to ServerContext.doWithServerContext, then an ordered list of providers (obtained as specified below) implementing the ServerContext.Spi interface is consulted. ServerContext.Spi.getServerContext() is called on each provider in turn; the first non-null return value is returned by this method. If no provider is able to supply a server context collection, then a ServerNotActiveException is thrown.

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 to 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 ClientHost and ClientSubject.

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

public static Object getServerContextElement(Class type)
                                      throws ServerNotActiveException
Returns the first element in the current server context collection (obtained by calling ServerContext.getServerContext) that is an instance of the given type type. If no element in the collection is an instance of the type type, then null is returned.

Parameters:
type - the type of the element
Returns:
the first element in the server context collection that is an instance of the type type or null
Throws:
ServerNotActiveException - if no server context is set for the current thread

GigaSpaces XAP 10.0.1 API

Copyright © GigaSpaces.