wt.method
Class RemoteMethodServer

java.lang.Object
  extended bywt.method.RemoteMethodServer

public class RemoteMethodServer
extends Object

Class that provides access to a remote method server. Instances of this class are local (non-remote) objects that encapsulate the communication with a remote method server object. This encapsulation includes object location, and automatic recovery from communication errors.

The local object represents the "concept" of a remote method server, not a particular instance of the remote server object. This allows the local object to manage connecting to a server object, and reconnecting to new server objects during error recovery.

Error recovery consists of automatically retrying calls that fail due to communication failures. Argument classes that are consumed by serialization should throw a NotSerializableException to abort retries if re-serialization is not valid.

If the calling thread is an instance of wt.util.WTThread, interrupting the thread while it is invoking a remote method will cause the corresponding remote thread in the method server to be interrupted. This allows the client to abort long running server operations by interrupting the calling thread.

Supported API: true
Extendable: false


Field Summary
private  int activeCalls
           
private  Object activeCallsLock
           
private  Object AUTHENTICATOR_KEY
           
private  Object authenticatorLock
           
private static boolean BUFFERED_INPUT
           
private static boolean CLIENT_METHOD_TIMING
           
private static Hashtable codebaseMaps
           
private  Object CURRENT_SERVER_KEY
           
private  MethodAuthenticator currentAuthenticator
           
private  int currentMethodServer
           
private static Object DEFAULT_INSTANCE_KEY
           
private static boolean defaultPrivateAffinity
           
private static boolean defaultPrivateAuthentication
           
private static Object lock
           
private static int MARSHAL_RETRY
           
private  int maxActiveCalls
           
private static int OTHER_RETRY
           
private  String password
           
private  Object PASSWORD_KEY
           
private static Object PRIVATE_AFFINITY_KEY
           
private static Object PRIVATE_AUTH_KEY
           
private static String RESOURCE
           
private static int SERVER_COUNT
           
static boolean ServerFlag
          Method server flag - used to control conditional behavior in forwarding methods.
private  RemoteServerManager serverManager
           
private  MethodServer[] servers
           
private static String SERVICE_NAME
           
private  String serviceName
           
private static boolean usePrivateAffinity
           
private static boolean usePrivateAuthenticators
           
private  Object USER_NAME_KEY
           
private  String userName
           
private static boolean VERBOSE_CLIENT
           
 
Constructor Summary
protected RemoteMethodServer(RemoteServerManager server_manager, String service_name)
          Construct a new RemoteMethodServer object.
 
Method Summary
 Vector getAllInfo()
          Get some general info from all remote method server instances

Supported API: false
 MethodAuthenticator getAuthenticator()
          Get the MethodAuthenticator to use for the current thread.
private  MethodServer getCurrentMethodServer()
           
static RemoteMethodServer getDefault()
          Get default instance of RemoteMethodServer.
static boolean getDefaultPrivateAffinity()
          Get default value of whether or not calls from different contexts will use private server affinity or share server affinity with other contexts accessing the same server.
static boolean getDefaultPrivateAuthentication()
          Return default value of whether or not calls from will use a private method authenticator or share authentication with other contexts accessing the same server.
 MethodServerInfo getInfo()
          Get some general info from a remote method server instance

Supported API: false
static RemoteMethodServer getInstance(URL server_codebase)
          Get instance of RemoteMethodServer corresponding to the given server codebase URL.
static RemoteMethodServer getInstance(URL server_codebase, String service_name)
          Get instance of RemoteMethodServer corresponding to the given server codebase URL.
protected  String getMessage(String key)
          Get text of a localized message.
protected  MethodServer getMethodServer(MethodServer prev_method_server, Exception report_exception)
          Get a remote method server instance associated with this RemoteMethodServer object.
 String getPassword()
          Get the password set for this instance by the setPassword method.
static boolean getPrivateAffinity()
          Return whether or not calls from the current context will use private server affinity or share server affinity with other contexts accessing the same server.
static boolean getPrivateAuthentication()
          Return whether or not calls from the current context will use a private method authenticator or share authentication with other contexts accessing the same server.
 String getUserName()
          Get the user name set for this instance by the setUserName method.
protected  MethodAuthenticator handleAuthenticationException(Throwable server_exception, MethodAuthenticator authenticator, MethodArgs invoke_args)
          Handle AuthenticationExceptions thrown from the server.
protected  MethodServer handleServerLoadException(Throwable server_exception, MethodServer prev_method_server)
          Handle load balancing to a new server when current server throws a ServerLoadException.
protected  MethodAuthenticator initAuthenticator(MethodAuthenticator authenticator)
          Initialize a new method authenticator.
 Object invoke(String target_method, String target_class, Object target_object, Class[] arg_types, Object[] args)
          Invoke the specified target method with the remote method server.
protected  boolean isAuthenticationException(Object obj)
          Check if an object is an instance of AuthenticationException.
protected  boolean isServerLoadException(Object obj)
          Check if an object is an instance of ServerLoadException.
static void main(String[] args)
          Simple tester Displays info from the default server.
private static RemoteException newRemoteException(String msg, Throwable t)
           
static void ping()
          Simple ping tester.
private static void printRemoteException(RemoteException e)
           
 void setAuthenticator(MethodAuthenticator authenticator)
          Set the MethodAuthenticator to use for the current thread.
private  void setCurrentMethodServer(MethodServer server)
           
static void setDefaultPrivateAffinity(boolean private_affinity)
          Set default value of whether or not calls from different contexts will use private server affinity or share server affinity with other contexts accessing the same server.
static void setDefaultPrivateAuthentication(boolean private_auth)
          Set default value of whether or not calls will use a private method authenticator or share authentication with other contexts accessing the same server.
 void setPassword(String password)
          Set the password that will be made available to a method authenticator capable of password based authentication.
static void setPrivateAffinity(boolean private_affinity)
          Set whether or not calls from the current context will maintain server affinity separately from other contexts or share server affinity with other contexts accessing the same remote method server.
static void setPrivateAuthentication(boolean private_auth)
          Set whether or not calls from the current context will use a private method authenticator or share authentication with other contexts accessing the same server.
 void setUserName(String user_name)
          Set the user name that will be made available to a method authenticator capable of user name based authentication.
 void stopAllServers()
          Get some general info from all remote method server instances

Supported API: false
 boolean streamingSupported()
          Determine if streaming calls are supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

ServerFlag

public static boolean ServerFlag
Method server flag - used to control conditional behavior in forwarding methods. Should be set to true only within the method server itself.


MARSHAL_RETRY

private static final int MARSHAL_RETRY

OTHER_RETRY

private static final int OTHER_RETRY

BUFFERED_INPUT

private static final boolean BUFFERED_INPUT

CLIENT_METHOD_TIMING

private static final boolean CLIENT_METHOD_TIMING

VERBOSE_CLIENT

private static final boolean VERBOSE_CLIENT

SERVICE_NAME

private static final String SERVICE_NAME

SERVER_COUNT

private static final int SERVER_COUNT

codebaseMaps

private static Hashtable codebaseMaps

lock

private static final Object lock

DEFAULT_INSTANCE_KEY

private static final Object DEFAULT_INSTANCE_KEY

PRIVATE_AUTH_KEY

private static final Object PRIVATE_AUTH_KEY

defaultPrivateAuthentication

private static boolean defaultPrivateAuthentication

PRIVATE_AFFINITY_KEY

private static final Object PRIVATE_AFFINITY_KEY

defaultPrivateAffinity

private static boolean defaultPrivateAffinity

AUTHENTICATOR_KEY

private final Object AUTHENTICATOR_KEY

USER_NAME_KEY

private final Object USER_NAME_KEY

PASSWORD_KEY

private final Object PASSWORD_KEY

CURRENT_SERVER_KEY

private final Object CURRENT_SERVER_KEY

usePrivateAuthenticators

private static boolean usePrivateAuthenticators

usePrivateAffinity

private static boolean usePrivateAffinity

serverManager

private RemoteServerManager serverManager

serviceName

private String serviceName

currentMethodServer

private int currentMethodServer

servers

private MethodServer[] servers

currentAuthenticator

private MethodAuthenticator currentAuthenticator

authenticatorLock

private Object authenticatorLock

userName

private String userName

password

private String password

activeCalls

private int activeCalls

activeCallsLock

private Object activeCallsLock

maxActiveCalls

private int maxActiveCalls
Constructor Detail

RemoteMethodServer

protected RemoteMethodServer(RemoteServerManager server_manager,
                             String service_name)
Construct a new RemoteMethodServer object.

Supported API: false

Parameters:
server_manager - RemoteServerManager object used to get server reference
See Also:
RemoteServerManager
Method Detail

getInstance

public static RemoteMethodServer getInstance(URL server_codebase)
Get instance of RemoteMethodServer corresponding to the given server codebase URL.

Supported API: true

Parameters:
server_codebase - the server codebase URL

getInstance

public static RemoteMethodServer getInstance(URL server_codebase,
                                             String service_name)
Get instance of RemoteMethodServer corresponding to the given server codebase URL.

Supported API: true

Parameters:
server_codebase - the server codebase URL
service_name - the service name registered by the server

getDefault

public static RemoteMethodServer getDefault()
Get default instance of RemoteMethodServer. The default instance is the one corresponding to the server codebase of the current thread as returned by the WTProperties class.

Supported API: true

See Also:
WTProperties

getPrivateAuthentication

public static boolean getPrivateAuthentication()
Return whether or not calls from the current context will use a private method authenticator or share authentication with other contexts accessing the same server.

Supported API: true

Returns:
private authentication setting

setPrivateAuthentication

public static void setPrivateAuthentication(boolean private_auth)
Set whether or not calls from the current context will use a private method authenticator or share authentication with other contexts accessing the same server. Normally, all contexts that share access to a remote method server will use the same security context. This method allows multi-user applications to establish separate security contexts for different calling contexts.

The setting affects calls originating in threads that share the current thread's WTContext. The default for a WTContext is to use shared authentication.

Supported API: true

Parameters:
private_auth - true indicates private, false indicates shared

getDefaultPrivateAuthentication

public static boolean getDefaultPrivateAuthentication()
Return default value of whether or not calls from will use a private method authenticator or share authentication with other contexts accessing the same server.

Supported API: true

Returns:
private authentication setting

setDefaultPrivateAuthentication

public static void setDefaultPrivateAuthentication(boolean private_auth)
Set default value of whether or not calls will use a private method authenticator or share authentication with other contexts accessing the same server.

Supported API: true

Parameters:
private_auth - true indicates private, false indicates shared

getPrivateAffinity

public static boolean getPrivateAffinity()
Return whether or not calls from the current context will use private server affinity or share server affinity with other contexts accessing the same server.

Supported API: true

Returns:
private authentication setting

setPrivateAffinity

public static void setPrivateAffinity(boolean private_affinity)
Set whether or not calls from the current context will maintain server affinity separately from other contexts or share server affinity with other contexts accessing the same remote method server. Normally, all contexts that share access to a remote method server will use the same server instance. This method allows multi-user applications to establish separate server affinity for different calling contexts.

The setting affects calls originating in threads that share the current thread's WTContext. The default for a WTContext is to use shared server affinity.

Supported API: true

Parameters:
private_affinity - true indicates private, false indicates shared

getDefaultPrivateAffinity

public static boolean getDefaultPrivateAffinity()
Get default value of whether or not calls from different contexts will use private server affinity or share server affinity with other contexts accessing the same server.

Supported API: true

Returns:
private authentication setting

setDefaultPrivateAffinity

public static void setDefaultPrivateAffinity(boolean private_affinity)
Set default value of whether or not calls from different contexts will use private server affinity or share server affinity with other contexts accessing the same server.

Supported API: true

Parameters:
private_affinity - true indicates private, false indicates shared

setUserName

public void setUserName(String user_name)
Set the user name that will be made available to a method authenticator capable of user name based authentication. This information is managed by the RemoteMethodServer object because it manages the use of method authenticators. If private authentication is set for the current thread's WTContext, this user name will not be shared with other contexts.

Supported API: true

Parameters:
user_name - User name, or null to remove setting.

getUserName

public String getUserName()
Get the user name set for this instance by the setUserName method.

Supported API: true

Returns:
User name, or null if not set.

setPassword

public void setPassword(String password)
Set the password that will be made available to a method authenticator capable of password based authentication. This information is managed by the RemoteMethodServer object because it manages the use of method authenticators. If private authentication is set for the current thread's WTContext, this password will not be shared with other contexts. The password is encoded in memory so it does not remain in clear text.

Supported API: true

Parameters:
password - Password, or null to remove setting.

getPassword

public String getPassword()
Get the password set for this instance by the setPassword method.

Supported API: true

Returns:
User name, or null if not set.

invoke

public Object invoke(String target_method,
                     String target_class,
                     Object target_object,
                     Class[] arg_types,
                     Object[] args)
              throws RemoteException,
                     InvocationTargetException
Invoke the specified target method with the remote method server. The method is dynamically invoked within the server and any uncaught exceptions thrown by the remote method are thrown here wrapped in a InvocationTargetException.

Supported API: true

Parameters:
target_method - the target method name
target_class - the target class (for static methods only)
target_object - the target object (for instance methods only)
arg_types - an array of argument types used when looking up the method
args - an array of argument objects for the method
Throws:
RemoteException - any exception trying to call the target method
InvocationTargetException - any exception thrown by the target method
See Also:
Method.invoke(java.lang.Object, java.lang.Object[])

isServerLoadException

protected boolean isServerLoadException(Object obj)
Check if an object is an instance of ServerLoadException. Exists as a separate method to avoid loading ServerLoadException during JIT compiling. Supported API: false


handleServerLoadException

protected MethodServer handleServerLoadException(Throwable server_exception,
                                                 MethodServer prev_method_server)
Handle load balancing to a new server when current server throws a ServerLoadException. Supported API: false


isAuthenticationException

protected boolean isAuthenticationException(Object obj)
Check if an object is an instance of AuthenticationException. Exists as a separate method to avoid loading AuthenticationException during JIT compiling. Supported API: false


handleAuthenticationException

protected MethodAuthenticator handleAuthenticationException(Throwable server_exception,
                                                            MethodAuthenticator authenticator,
                                                            MethodArgs invoke_args)
Handle AuthenticationExceptions thrown from the server. Returns the new MethodAuthenticator that should be used to endorse the call or null if none was supplied or it failed to initialize. Supported API: false


initAuthenticator

protected MethodAuthenticator initAuthenticator(MethodAuthenticator authenticator)
Initialize a new method authenticator. Calls the init method of the authenticator and returns the initialized authenticator if successful or null if not. A multi-user server application may chose to perform this initialization remotely in its own clients.

Supported API: false

Parameters:
authenticator - the MethodAuthenticator object
Returns:
the initialized MethodAuthenticator object

getAuthenticator

public MethodAuthenticator getAuthenticator()
Get the MethodAuthenticator to use for the current thread. If the current context uses a private authenticator, that one will be returned, otherwise the shared authenticator will be returned.

Supported API: true


setAuthenticator

public void setAuthenticator(MethodAuthenticator authenticator)
Set the MethodAuthenticator to use for the current thread. If the current context does not use a private authenticator, this will set the shared authenticator. Setting to null removes the current authenticator.

Supported API: true


getMethodServer

protected MethodServer getMethodServer(MethodServer prev_method_server,
                                       Exception report_exception)
                                throws RemoteException
Get a remote method server instance associated with this RemoteMethodServer object. This is used to establish the association with a remote method server object, or to reestablish a new association during exception handling.

Supported API: false

Parameters:
prev_method_server - previous remote instance (null to force new association)
Throws:
RemoteException

getCurrentMethodServer

private MethodServer getCurrentMethodServer()

setCurrentMethodServer

private void setCurrentMethodServer(MethodServer server)

getInfo

public MethodServerInfo getInfo()
                         throws RemoteException
Get some general info from a remote method server instance

Supported API: false

Throws:
RemoteException

getAllInfo

public Vector getAllInfo()
                  throws RemoteException
Get some general info from all remote method server instances

Supported API: false

Throws:
RemoteException

stopAllServers

public void stopAllServers()
                    throws RemoteException
Get some general info from all remote method server instances

Supported API: false

Throws:
RemoteException

printRemoteException

private static void printRemoteException(RemoteException e)

streamingSupported

public boolean streamingSupported()
                           throws RemoteException
Determine if streaming calls are supported. Streaming is not be supported when RMI is tunneled over HTTP or HTTPS requests since the argument and response objects are buffered in memory when building HTTP request and response bodies.

Supported API: true

Throws:
RemoteException

ping

public static void ping()
                 throws RemoteException
Simple ping tester. Invokes a ping method that is built into the remote method server.

Supported API: true

Throws:
RemoteException

newRemoteException

private static RemoteException newRemoteException(String msg,
                                                  Throwable t)

getMessage

protected String getMessage(String key)
Get text of a localized message. Exists as a separate method to avoid loading WTMessage when JIT compiling. Supported API: false


main

public static void main(String[] args)
                 throws RemoteException
Simple tester Displays info from the default server. If an integer argument is supplied, it pings the server that many times.

Supported API: true

Throws:
RemoteException