|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.rmi.server.RemoteObject
java.rmi.server.RemoteServer
danbikel.switchboard.AbstractSwitchboardUser
public abstract class AbstractSwitchboardUser
Provides a convenient default implementation of the interface
SwitchboardUser
, so that subclasses that need to
implement the Client
and Server
interfaces
need only implement the methods introduced in those subinterfaces,
as is the case with the AbstractClient
and
AbstractServer
implementations provided by this package.
Put another way, the interface hierarchy of SwitchboardUser
,
Client
and Server
is mirrored by the
implementation hierarchy of AbstractSwitchboardUser
,
AbstractClient
and AbstractServer
:
Interface Hierarchy Implementation Hierarchy ------------------- ------------------------ SwitchboardUser AbstractSwitchboardUser / \ / \ / \ / \ Client Server AbstractClient AbstractServer
AbstractClient
,
AbstractServer
,
Serialized FormNested Class Summary | |
---|---|
protected class |
AbstractSwitchboardUser.Alive
Class to implement a thread that detects whether the switchboard has gone down, by noticing when it has been too long since its last call to alive() . |
protected static class |
AbstractSwitchboardUser.SBUserRetry
Provides an appropriate overridden definition of Retry.keepTrying()
that checks the value of timeToDie . |
Field Summary | |
---|---|
protected Object |
aliveSynch
|
protected int |
aliveTimeout
|
protected String |
className
The name of the runtime type of the subclass, cached here in this abstract class' constructor for convenience. |
protected static int |
defaultMaxSwitchboardTries
The fallback-default maximum number of times to try contacting the switchboard after it goes down or when registering for the first time. |
protected static int |
defaultTimeout
The fallback-default timeout value for client- (switchboard-) side sockets. |
protected Object |
dieSynch
The object on which to synchronize death. |
protected int |
id
The unique ID of this switchboard user, assigned by the switchboard. |
protected static int |
infiniteTries
The value to specify for switchboard users to try indefinitely to re-acquire the switchboard when first starting up or in the event of a switchboard crash. |
protected int |
maxSwitchboardTries
The maximum number of times the getSwitchboard(java.lang.String) method will
try to get a new Switchboard when the current instance
has gone down or when registering for the first time. |
protected boolean |
registered
Flag that indicates whether this client is currently registered. |
protected SwitchboardRemote |
switchboard
A handle onto the switchboard. |
protected String |
switchboardName
The bootstrap registry name of the switchboard. |
protected int |
timeout
The value for which switchboard-side (RMI client-side) sockets will timeout (a value of 0 indicates infinite timeout). |
protected boolean |
timeToDie
The boolean indicating that this object is ready to die, and will wait for the length of the timeout value before actually committing suicide (by unexporting itself via the unexportWhenDead()
method). |
Fields inherited from class java.rmi.server.RemoteObject |
---|
ref |
Constructor Summary | |
---|---|
protected |
AbstractSwitchboardUser()
A no-arg constructor for concrete subclasses that wish to have stand-alone (non-exported) constructors. |
protected |
AbstractSwitchboardUser(int timeout)
Constructs a switchboard user whose switchboard-side (RMI client-side) sockets will have the specified timeout. |
protected |
AbstractSwitchboardUser(int timeout,
int port)
Constructs a switchboard user accepting RMI calls on the specified port, and whose switchboard-side (RMI client-side) sockets will have the specified timeout. |
protected |
AbstractSwitchboardUser(int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
Constructs a switchboard user receiving RMI calls on the specified port, constructing client- and server-side sockets from the specified socket factories. |
Method Summary | |
---|---|
boolean |
alive()
A simple "ping" method for the switchboard to continually make sure its users are alive. |
protected void |
cleanup()
Does nothing; called by the default implementation of unexportWhenDead() . |
void |
die(boolean now)
Tells the switchboard user to commit suicide. |
protected static void |
disableHttp(String property)
|
protected void |
getAliveTimeout()
Sets aliveTimeout to be a reasonable value. |
protected void |
getSwitchboard(String name)
Repeatedly tries to get the switchboard stub from the bootstrap registry. |
protected void |
getSwitchboard(String name,
boolean verbose)
Repeatedly tries to get the switchboard stub from the bootstrap registry. |
protected void |
getSwitchboard(String name,
boolean verbose,
PrintWriter err)
Repeatedly tries to get the switchboard stub from the bootstrap registry. |
static SwitchboardRemote |
getSwitchboard(String name,
int tries)
Repeatedly tries the specified number of times to get the switchboard stub from the bootstrap registry. |
static SwitchboardRemote |
getSwitchboard(String name,
int tries,
boolean verbose)
Repeatedly tries the specified number of times to get the switchboard stub from the bootstrap registry. |
static SwitchboardRemote |
getSwitchboard(String name,
int tries,
boolean verbose,
PrintWriter err)
Repeatedly tries the specified number of times to get the switchboard stub from the bootstrap registry. |
String |
host()
Returns the host on which this switchboard user is running. |
int |
id()
Returns the ID number for this switchboard user. |
protected int |
nonZeroTimeout()
Returns the value of timeout (set at construction time),
or defaultTimeout if timeout is 0. |
protected abstract void |
reRegister()
|
protected static void |
setPolicyFile(Class cl,
String resource)
Sets the system property "java.security.policy" to be the URL of the specified resource obtained from the specified class. |
protected static void |
setPolicyFile(String resource)
Sets the system property "java.security.policy" to be the URL of the specified resource obtained from the SwitchboardRemote class. |
protected void |
startAliveThread()
Starts a thread using the AbstractSwitchboardUser.Alive class
to detect when the switchboard goes down and re-register this user. |
void |
unexportWhenDead()
Unexports this object when it considers itself dead. |
Methods inherited from class java.rmi.server.RemoteServer |
---|
getClientHost, getLog, setLog |
Methods inherited from class java.rmi.server.RemoteObject |
---|
equals, getRef, hashCode, toString, toStub |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final int defaultTimeout
protected static final int infiniteTries
protected static final int defaultMaxSwitchboardTries
infiniteTries
.
maxSwitchboardTries
,
Constant Field Valuesprotected String className
protected SwitchboardRemote switchboard
protected String switchboardName
protected volatile boolean registered
protected Object dieSynch
notify
or
notifyAll
method, for otherwise the semantics of
certain methods of this class will be corrupted. However, subclasses
may wait on this object.
protected volatile boolean timeToDie
unexportWhenDead()
method).
protected int timeout
protected int maxSwitchboardTries
getSwitchboard(java.lang.String)
method will
try to get a new Switchboard
when the current instance
has gone down or when registering for the first time. A value of
infiniteTries
indicates an infinite number of tries.
protected int id
protected Object aliveSynch
protected int aliveTimeout
Constructor Detail |
---|
protected AbstractSwitchboardUser()
protected AbstractSwitchboardUser(int timeout) throws RemoteException
timeout
- the timeout value for switchboard-side (RMI client-side)
sockets, in milliseconds; a value of 0 indicates infinite timeout
RemoteException
protected AbstractSwitchboardUser(int timeout, int port) throws RemoteException
timeout
- the timeout value for switchboard-side (RMI client-side)
sockets, in milliseconds; a value of 0 indicates infinite timeoutport
- the port on which to receive RMI calls
RemoteException
protected AbstractSwitchboardUser(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException
port
- the port on which this object will receive RMI callscsf
- the client-side socket factoryssf
- the server-side server socket factory
RemoteException
Method Detail |
---|
protected static void setPolicyFile(String resource)
SwitchboardRemote
class.
resource
- the resource to obtain from SwitchboardRemote
that will be the value of the system property
"java.security.policy"protected static void setPolicyFile(Class cl, String resource)
resource
- the resource to obtain from the specified class
that will be the value of the system property
"java.security.policy"protected static void disableHttp(String property)
protected void getSwitchboard(String name) throws MalformedURLException
maxSwitchboardTries
. There will be no error output
for the repeated attempts (no verbosity).
MalformedURLException
protected void getSwitchboard(String name, boolean verbose) throws MalformedURLException
maxSwitchboardTries
. Each attempt that results in an
error will be printed out to System.err
.
MalformedURLException
protected void getSwitchboard(String name, boolean verbose, PrintWriter err) throws MalformedURLException
maxSwitchboardTries
. If verbose
is
true
, each attempt that results in an
error will be printed out to the specified PrintWriter
.
name
- the name of the switchboard in the bootstrap registryverbose
- if true
, indicates to print out
each failed attempt to get the switchboard to the specified error
writererr
- the character stream to which to output error messages
MalformedURLException
public static SwitchboardRemote getSwitchboard(String name, int tries) throws MalformedURLException
name
- the name of the switchboard in the bootstrap registrytries
- the number of times to try to get the switchboard from
the bootstrap registry
MalformedURLException
- if the specified name is a malformed URLpublic static SwitchboardRemote getSwitchboard(String name, int tries, boolean verbose) throws MalformedURLException
name
- the name of the switchboard in the bootstrap registrytries
- the number of times to try to get the switchboard from
the bootstrap registryverbose
- if true
, indicates to print error messages
to System.err
if an exception is raised during any of the
attempts to get the switchboard
MalformedURLException
- if the specified name is a malformed URLpublic static SwitchboardRemote getSwitchboard(String name, int tries, boolean verbose, PrintWriter err) throws MalformedURLException
name
- the name of the switchboard in the bootstrap registrytries
- the number of times to try to get the switchboard from
the bootstrap registryverbose
- if true
, indicates to print error messages
to the specified PrintWriter
if an exception is raised
during any of the attempts to get the switchboarderr
- the writer to which error messages should be printed if
verbose
is true
(no messages are printed if
verbose
is false
)
MalformedURLException
- if the specified name is a malformed URLpublic String host() throws RemoteException
host
in interface SwitchboardUser
RemoteException
protected void cleanup()
unexportWhenDead()
. If a subclass has additional cleanup to be done
prior to unexporting, this method should be overridden.
public void unexportWhenDead() throws RemoteException
dieSynch
, continually checking the
timeToDie
flag. When this flag is true, it means the
die(boolean)
method has been invoked. This method then grabs
the lock on dieSynch
one last time, waiting
a maximum of timeout
, or defaultTimeout
if
timeout
is 0.
N.B.: Concrete subclasses should either devote a separate thread to call this method immediately after construction, or ensure that it is called as the last method in the subclass' main thread.
RemoteException
public void die(boolean now) throws RemoteException
now
value of false
, to allow the
switchboard a final successful call to alive
, which
will return false. The switchboard will typically invoke this
method on its users with a now
value of
true
.
die
in interface SwitchboardUser
now
- if false
, indicates that this switchboard user
should wait gracefully for a final invocation by the switchboard
of its alive()
method, so that it can return false; otherwise,
this method should cause the switchboard user to die as soon as possible
RemoteException
public boolean alive() throws RemoteException
SwitchboardUser
false
after invocation of
die(false)
to indicate to switchboard that user is
dying safely. However, implementations should also not wait
indefinitely for this last call, instead using an appropriate
maximum timeout value (such as the timeout of the transport
layer, if available) before unexporting themselves.
alive
in interface SwitchboardUser
RemoteException
AbstractSwitchboardUser
protected final int nonZeroTimeout()
timeout
(set at construction time),
or defaultTimeout
if timeout
is 0.
public int id() throws RemoteException
SwitchboardUser
id
in interface SwitchboardUser
RemoteException
protected void getAliveTimeout() throws RemoteException
aliveTimeout
to be a reasonable value. This
default implementation sets aliveTimeout
to be
twice the maximum time the switchboard will try to call
a users' alive()
method. That is,
the value set by this method is equal to the value of the expression
2 * ((switchboard.getKeepAliveMaxRetries() + 1) * switchboard.getKeepAliveInterval());
RemoteException
protected void startAliveThread() throws RemoteException
AbstractSwitchboardUser.Alive
class
to detect when the switchboard goes down and re-register this user.
RemoteException
protected abstract void reRegister() throws RemoteException
RemoteException
|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |