|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object PIRL.Messenger.Dispatcher
public class Dispatcher
A Dispatcher is a Messenger manager for communication between client processes.
A Dispatcher is typically used as a background daemon application process that accepts connections from clients on a designated communications ports, allocates a Messenger to each client, manages the Messengers, and handles a core set of Messenger management Messages. When a Distpatcher is started it will send a "Hello" broadcast on a designated multicast port to any clients listening on the local host system who might be interested in making a connection.
A Dispatcher may be subclassed to add a additional Message protocol support
A Configuration file is used to Configure a Dispatcher's operating variables before it begins running.
A log file may be specified where client connection/deconnection and other important events are reported.
Support is provided for authenticated client connections using a public key to exchange an encoded private password that is decoded by a private key paired with the public key.
Messenger
Field Summary | |
---|---|
static String |
ACK_ACTION
Messenger management Message Actions and their parameters. |
static String |
ACTION_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
ADDRESS_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
CLASS_ID_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
CONFIGURATION_SOURCE_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static SimpleDateFormat |
DATE_FORMAT
Format for log message timestamps. |
static String |
DATE_FORMATTING
Formatting pattern for log message timestamps. |
static String |
DEFAULT_DISPATCHER_NAME
The default name of the Dispatcher: "Dispatcher". |
static String |
DEFAULT_HELLO_ADDRESS
The default private multicast address to use in the Hello datagram. |
static int |
DEFAULT_HELLO_PORT
The default port on which to send the Hello datagram. |
static int |
DEFAULT_IDENTIFY_TIMEOUT
The default maximum amount of time, in seconds, to wait for a new Messenger client to respond to an identify message. |
static int |
DEFAULT_PORT
The default communications port number. |
protected String |
Dispatcher_ID
The ID of of the Dispatcher. |
static String |
DONE_ACTION
Messenger management Message Actions and their parameters. |
static String |
EXCEPTION_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static int |
EXIT_COMMAND_LINE_SYNTAX
Command line syntax problem exit status. |
static int |
EXIT_CONFIG_FILE_PROBLEM
The log file could not be opened for writing exit status. |
static int |
EXIT_IO_ERROR
IOException failure exit status. |
static int |
EXIT_NO_LOG_FILE
The log file could not be opened for writing exit status. |
static int |
EXIT_SECURITY_VIOLATION
SecurityException exit status. |
static int |
EXIT_SUCCESS
Success exit status. |
static int |
EXIT_UNKNOWN_EXCEPTION
Unknown exception (possible programming flaw). |
static String |
EXPLANATION_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
HELLO_ADDRESS_PARAMETER_NAME
The configuration parameter name for the Hello multicast address. |
static String |
HELLO_MESSAGE
The content of the Hello broadcast datagram message. |
static String |
HELLO_PORT_PARAMETER_NAME
The configuration parameter name for the Hello port. |
static String |
HELLO_RATE_PARAMETER_NAME
The configuration parameter name for the Hello repeat rate (seconds). |
static String |
ID
Class identification name with source code version and date. |
static String |
IDENTIFY_ACTION
Messenger management Message Actions and their parameters. |
static String |
IDENTIFY_TIMEOUT_PARAMETER_NAME
The configuration parameter name for the maximum wait time, in seconds, for a new Messenger client connection to respond to the identify message. |
static String |
IDENTITY_ACTION
Messenger management Message Actions and their parameters. |
static String |
KEY_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
LINK_MESSENGER_ACTION
Messenger management Message Actions and their parameters. |
static String |
LOG_PATHNAME_PARAMETER_NAME
The configuration parameter name for the log file pathname. |
protected PrintStream |
Log_Stream
Log output stream. |
static String |
MEMORY_ALLOCATED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MEMORY_AVAILABLE_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MEMORY_FREE_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MEMORY_STATUS_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGE_BYTES_RECEIVED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGE_BYTES_SENT_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_RECEIVED_CORRUPTED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_RECEIVED_DROPPED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_RECEIVED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_SENT_CORRUPTED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_SENT_DROPPED_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_SENT_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSAGES_UNFORWARDABLE_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
MESSENGER_STATUS_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
protected Vector<Messenger> |
Messengers
List of connected Messenger clients. |
static String |
MESSENGERS_REPORT_ACTION
Messenger management Message Actions and their parameters. |
static int |
MINIMUM_IDENTIFY_TIMEOUT
The minimum Messenger client identify timeout in seconds. |
static String |
NACK_ACTION
Messenger management Message Actions and their parameters. |
static String |
NAME_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
NL
Text new-line sequence. |
static String |
ORIGINAL_MESSAGE_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
PASSWORD_PARAMETER_NAME
The configuration parameter name for the authentication password. |
static String |
PORT_PARAMETER_NAME
The configuration parameter name for the communicaitons port number value. |
protected boolean |
Report_Messenger_Connections
Automatically send connection notifications. |
protected Vector<Messenger> |
Report_to_Messengers
List of Messenger clients that have requested connection notifications. |
static String |
ROUTE_TO_PARAMETER_NAME
Messenger management Message Actions and their parameters. |
static String |
START_MESSENGER_REPORTING_ACTION
Messenger management Message Actions and their parameters. |
static String |
START_STOP_MARKER
Log file marker written when a Dispatcher is started and after it has shutdown. |
static String |
STATUS_REPORT_ACTION
Messenger management Message Actions and their parameters. |
static String |
STDOUT
Log "filename" for logging to stdout. |
static String |
STOP_MESSENGER_REPORTING_ACTION
Messenger management Message Actions and their parameters. |
protected Configuration |
The_Configuration
The Dispatcher Configuration. |
static boolean |
UNAUTHENTICATED_CONNECTIONS_ALLOWED
Controls whether or not annonymous connections are allowed. |
static String |
UNDELIVERABLE_ACTION
Messenger management Message Actions and their parameters. |
static String |
UNLINK_MESSENGER_ACTION
Messenger management Message Actions and their parameters. |
Constructor Summary | |
---|---|
Dispatcher()
Construct a Dispatcher. |
|
Dispatcher(Configuration configuration)
Construct a Dispatcher with a configuration. |
|
Dispatcher(Configuration configuration,
int port)
Construct a Dispatcher with a configuration and a specified communication port. |
|
Dispatcher(String name)
Construct a named Dispatcher. |
|
Dispatcher(String name,
Configuration configuration)
Construct a named Dispatcher with a configuration. |
|
Dispatcher(String name,
Configuration configuration,
int port)
Construct a named Dispatcher with a configuration and a specified communication port. |
Method Summary | |
---|---|
protected boolean |
Authenticate(Message identity)
Authenticate a client identity. |
static Message |
Authentication(Message identify,
Message identity)
Provide client identity authentication information. |
protected String |
Config_Pathname(String name)
Get an application specifiic configuration parameter pathname. |
protected void |
Configure(Configuration configuration)
Configures the Dispatcher. |
static String |
Default_Configuration_Source()
Get the default configuration source. |
static String |
Default_Dispatcher_Name()
Get the default Dispatcher name. |
static void |
Default_Dispatcher_Name(String name)
Set the default Dispatcher name. |
static String |
Default_Log_Filename()
Get the default log filename. |
String |
Dispatcher_Name()
Get the Dispatcher name. |
Dispatcher |
Dispatcher_Name(String name)
Set the Dispatcher name. |
String |
Hello_Address()
Get the Dispatcher Hello broadcast multicast address. |
int |
Hello_Port()
Get the Dispatcher Hello broadcast port number. |
int |
Identify_Timeout()
Get the maximum time to wait for a response to a new client identify request. |
Dispatcher |
Identify_Timeout(int seconds)
Set the maximum time to wait for a response to a new client identify request. |
Message |
Identity()
Get the Dispatcher identity. |
protected Dispatcher |
Identity(Message identity)
Set the Dispatcher identity. |
Message |
Listener_Identity()
Get the identity of this Dispatcher. |
String |
Location()
Get the Dispatcher location. |
String |
Log_Pathname()
Get the log file pathname. |
String |
Log_Pathname(String pathname)
Set the pathname to the log file. |
PrintStream |
Log_Stream()
Get the log stream. |
void |
Log_Time(String report)
Writes a log report with a timestamp. |
void |
Log()
Writes an empty log line. |
void |
Log(String report)
Writes a log report. |
boolean |
Logging()
Test if logging is enabled. |
boolean |
Logging(boolean enabled)
Enable or disable logging. |
protected Messenger |
Lookup_Messenger(String address)
Get a Messenger for an address. |
static void |
main(String[] args)
|
void |
Message_Delivered(Message_Delivered_Event event)
Receives delivery of a message. |
Message |
Messenger_Identities(Messenger source_messenger,
String name)
Assemble a Message that includes the identities of selected connected Messengers. |
protected void |
Messenger_Link(Messenger source_messenger,
Message message)
Link two Messengers for I/O forwarding. |
protected void |
Messenger_Quit(Messenger messenger,
Message message)
Disconnect a Messenger. |
protected void |
Messenger_Quit(Messenger messenger,
String report)
Disconnect a Messenger. |
protected void |
Messenger_Unlink(Messenger source_messenger,
Message message)
Unlink two Messengers. |
protected void |
NACK(Messenger messenger,
Message message)
|
int |
Port()
Get the Dispatcher communication port number. |
boolean |
Report_Messenger_Connections()
Test if automatic reporting of the current Messagers list is enabled. |
Dispatcher |
Report_Messenger_Connections(boolean enabled)
Enable or disable automatic reporting of the current Messagers list whenever it changes. |
protected void |
Report_Messengers()
Sends a report of all the Messenger identities to each of the Messengers that have
requested connection
reports . |
static Value |
Route_To(Messenger messenger)
Get the Message route-to values for a Messenger. |
protected static Value |
Route(Messenger source_messenger,
Messenger client_messenger)
|
Exception |
Run_Exception()
Get any Exception that might have occured when the Dispatcher was used as a Runnable . |
void |
run()
Run the connection listener. |
protected boolean |
Send(Messenger messenger,
Message message)
Send a Message via a Messenger. |
protected boolean |
Send(Messenger messenger,
Message message,
boolean report_failure)
Send a Message via a Messenger. |
protected void |
Shutdown()
Shutdown the Dispatcher. |
protected void |
Start_Messenger_Reporting(Messenger messenger)
Start automatic Messenger connection reporting for a Messenger. |
void |
Start()
Start the Dispatcher. |
boolean |
Started()
Tests if this Dispatcher has been started. |
protected void |
Status_Report(Messenger source_messenger,
Message message)
Send a status report message. |
protected void |
Stop_Messenger_Reporting(Messenger messenger)
Stop automatic Messenger connection reporting for a Messenger. |
static void |
Usage()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ID
protected String Dispatcher_ID
It is initialized to the ID
. Subclasses are expected to set
this to their own ID.
public static final String DEFAULT_DISPATCHER_NAME
protected Configuration The_Configuration
public static final String PORT_PARAMETER_NAME
public static final String IDENTIFY_TIMEOUT_PARAMETER_NAME
public static final String PASSWORD_PARAMETER_NAME
public static final String LOG_PATHNAME_PARAMETER_NAME
public static final String HELLO_PORT_PARAMETER_NAME
public static final String HELLO_ADDRESS_PARAMETER_NAME
public static final String HELLO_RATE_PARAMETER_NAME
public static final int DEFAULT_PORT
public static final int DEFAULT_HELLO_PORT
public static final String DEFAULT_HELLO_ADDRESS
public static final String HELLO_MESSAGE
public static final int DEFAULT_IDENTIFY_TIMEOUT
public static final int MINIMUM_IDENTIFY_TIMEOUT
DEFAULT_IDENTIFY_TIMEOUT
,
Constant Field Valuespublic static final boolean UNAUTHENTICATED_CONNECTIONS_ALLOWED
protected Vector<Messenger> Messengers
protected Vector<Messenger> Report_to_Messengers
protected volatile boolean Report_Messenger_Connections
public static final String ACTION_PARAMETER_NAME
public static final String IDENTIFY_ACTION
public static final String KEY_PARAMETER_NAME
public static final String IDENTITY_ACTION
public static final String NAME_PARAMETER_NAME
public static final String ADDRESS_PARAMETER_NAME
public static final String ROUTE_TO_PARAMETER_NAME
public static final String CLASS_ID_PARAMETER_NAME
public static final String MESSENGERS_REPORT_ACTION
public static final String START_MESSENGER_REPORTING_ACTION
public static final String STOP_MESSENGER_REPORTING_ACTION
public static final String LINK_MESSENGER_ACTION
public static final String UNLINK_MESSENGER_ACTION
public static final String STATUS_REPORT_ACTION
public static final String CONFIGURATION_SOURCE_PARAMETER_NAME
public static final String MESSENGER_STATUS_PARAMETER_NAME
public static final String MESSAGES_SENT_PARAMETER_NAME
public static final String MESSAGE_BYTES_SENT_PARAMETER_NAME
public static final String MESSAGES_SENT_DROPPED_PARAMETER_NAME
public static final String MESSAGES_SENT_CORRUPTED_PARAMETER_NAME
public static final String MESSAGES_RECEIVED_PARAMETER_NAME
public static final String MESSAGE_BYTES_RECEIVED_PARAMETER_NAME
public static final String MESSAGES_RECEIVED_DROPPED_PARAMETER_NAME
public static final String MESSAGES_RECEIVED_CORRUPTED_PARAMETER_NAME
public static final String MESSAGES_UNFORWARDABLE_PARAMETER_NAME
public static final String MEMORY_STATUS_PARAMETER_NAME
public static final String MEMORY_AVAILABLE_PARAMETER_NAME
public static final String MEMORY_ALLOCATED_PARAMETER_NAME
public static final String MEMORY_FREE_PARAMETER_NAME
public static final String UNDELIVERABLE_ACTION
public static final String ACK_ACTION
public static final String NACK_ACTION
public static final String ORIGINAL_MESSAGE_PARAMETER_NAME
public static final String DONE_ACTION
public static final String EXPLANATION_PARAMETER_NAME
public static final String EXCEPTION_PARAMETER_NAME
public static final String STDOUT
Log_Pathname(String)
,
Constant Field Valuesprotected PrintStream Log_Stream
public static final String DATE_FORMATTING
DATE_FORMAT
,
Constant Field Valuespublic static final SimpleDateFormat DATE_FORMAT
DATE_FORMATTING
public static final String START_STOP_MARKER
public static final String NL
public static final int EXIT_SUCCESS
public static final int EXIT_COMMAND_LINE_SYNTAX
public static final int EXIT_CONFIG_FILE_PROBLEM
public static final int EXIT_NO_LOG_FILE
public static final int EXIT_IO_ERROR
public static final int EXIT_SECURITY_VIOLATION
public static final int EXIT_UNKNOWN_EXCEPTION
Constructor Detail |
---|
public Dispatcher(String name, Configuration configuration, int port)
start
it operating.
name
- The Dispatcher name
.configuration
- The Configuration to use to configure
the Dispatcher when it is
started
.port
- The communications port number. If less than or equal
to zero the value of the configuration PORT_PARAMETER_NAME
parameter will be used, or the DEFAULT_PORT
if no
configuration parameter is found.
public Dispatcher(Configuration configuration, int port)
The Dispatcher name
will be the DEFAULT_DISPATCHER_NAME
.
start
it operating.
configuration
- The Configuration to use to configure
the Dispatcher when it is
started
.port
- The communications port number. If less than or equal
to zero the value of the configuration PORT_PARAMETER_NAME
parameter will be used, or the DEFAULT_PORT
if no
configuration parameter is found.
public Dispatcher(String name, Configuration configuration)
The communication port number will be obtained from the configuration
PORT_PARAMETER_NAME
parameter, or the DEFAULT_PORT
will be used if no configuration parameter is found.
start
it operating.
name
- The Dispatcher name
.configuration
- The Configuration to use to configure
the Dispatcher when it is
started
.
public Dispatcher(Configuration configuration)
The
The communication port number will be obtained from the configuration
start
it operating.
Dispatcher name
will be the DEFAULT_DISPATCHER_NAME
.
PORT_PARAMETER_NAME
parameter, or the DEFAULT_PORT
will be used if no configuration parameter is found.
public Dispatcher(String name)
When the Dispatcher is
The communication port number will be obtained from the configuration
start
it operating.
configured
a default configuration source will be sought.
PORT_PARAMETER_NAME
parameter, or the DEFAULT_PORT
will be used if no configuration parameter is found.
name
- The Dispatcher name
.
public Dispatcher()
The
When the Dispatcher is
The communication port number will be obtained from the configuration
start
it operating.
Dispatcher name
will be the DEFAULT_DISPATCHER_NAME
.
configured
a default configuration source will be sought.
PORT_PARAMETER_NAME
parameter, or the DEFAULT_PORT
will be used if no configuration parameter is found.
Method Detail |
---|
public static String Default_Dispatcher_Name()
Default_Dispatcher_Name(String)
public static void Default_Dispatcher_Name(String name)
name
- The default Dispatcher name. If null, the
DEFAULT_DISPATCHER_NAME
is used.public String Dispatcher_Name()
Dispatcher_Name(String)
public Dispatcher Dispatcher_Name(String name)
The NAME_PARAMETER_NAME
in the Dispatcher identity
is set to the Dispatcher name.
name
- The Dispatcher name. If null, the default Dispatcher name
is used.
public int Port()
public int Hello_Port()
public String Hello_Address()
public String Location()
The format of the location string is:
host[:port]
The host may be a hostname or IP address. The hostname is
fully qualified
. The communications
port number
is appended after a colon (':')
delimiter.
public Message Identity()
Identity(Message)
protected Dispatcher Identity(Message identity) throws PVL_Exception
The following parameters will always be set in the identity Message:
ACTION_PARAMETER_NAME
IDENTITY_ACTION
.
NAME_PARAMETER_NAME
Dispatcher name
.
CLASS_ID_PARAMETER_NAME
Dispatcher_ID
.
Configuration.HOST
Host.FULL_HOSTNAME
.
Configuration.USER
identity
- A Message containing the Dispatcher
identification information. If null an empty Message is provided
before setting the required parameters.
PVL_Exception
- if the identity Message can not be assembled
either because the specified identity Message can not be copied
or the required parameters can not be set.public int Identify_Timeout()
Identify_Timeout(int)
public Dispatcher Identify_Timeout(int seconds)
If a new client connection does not respond to the identity request before the timeout expires the client connection is dropped.
seconds
- The identify reponse timeout (seconds). If less than
or equal to zero the DEFAULT_IDENTIFY_TIMEOUT will be used.
Identify_Timeout(int)
public Dispatcher Report_Messenger_Connections(boolean enabled)
Whenever a client connects or disconnects a report is sent to all
Messengers that have requested connection reports
that provides the identities of all
Messengers in the modified list of connected Messagers. For Message
protocol operations that may generate a flurry of connection events
it can be desirable to suspend automatic connection event reporting
until after the protocol operation has been completed. This can
significantly reduce the amount of connection list change processing
that clients are required to manage.
enabled
- If true whenever the list of connected Messagers
changes it will be reported to all Messengers that have requested
connection reports; if false reports will only be provided on
demand.
Report_Messengers()
public boolean Report_Messenger_Connections()
Report_Messenger_Connections(boolean)
public Exception Run_Exception()
Runnable
.
When used as a Runnable the Dispatcher connection listener must first be
started
. If this throws an exception it is held since
it can not be thrown from a Runnable.
started
as a result of running
the Dispatcher. This will be null if no exception was
thrown.public static String Default_Configuration_Source()
The default configuration source is tried if no Configuration is
supplied to configure
the Dispatcher
and a configuration source based on the Dispatcher name
can not be found.
default Dispatcher name
plus the
".conf" extension.protected void Configure(Configuration configuration) throws Configuration_Exception, SecurityException
If no Configuration is provided a search will be made for a default
configuration source. The Dispatcher name
plus the ".conf" extension will be tried first. If this fails, the
default configuration source
will be tried.
The Configuration is set to be case insensitive
before
parameters are sought.
Configuration parameters that may be used:
PORT_PARAMETER_NAME
DEFAULT_PORT
.
IDENTIFY_TIMEOUT_PARAMETER_NAME
DEFAULT_IDENTIFY_TIMEOUT
; the minium value is
MINIMUM_IDENTIFY_TIMEOUT
.
PASSWORD_PARAMETER_NAME
UNAUTHENTICATED_CONNECTIONS_ALLOWED
is true unauthenticated
connections will be allowed.
LOG_PATHNAME_PARAMETER_NAME
logging
has not been enabled, and a
log pathname is found, the pathname is used to set the log file
and logging is then enabled.
N.B.: A configuration log pathname will not override an
application set log file if logging has been enabled by the
application.
HELLO_PORT_PARAMETER_NAME
HELLO_MESSAGE
on this port to
notify any clients that may listening that they may open a
connection. If the port number is zero no Hello broadcast will
be sent. DEFAULT_HELLO_PORT
is the default port number.
If the port number is not positive no broadcast will be done.
HELLO_ADDRESS_PARAMETER_NAME
DEFAULT_HELLO_ADDRESS
is the default
multicast address. If the address is empty no broadcast will be
done.
N.B.: All parameters are sought in the in the Configuration Group
with the Dispatcher name
.
configuration
- The Configuration to use. If null and
defatult configuration source will sought.
Configuration_Exception
- If there was a problem parsing the
configuration source, accessing its contents, or establishing
a log file.
SecurityException
- If the connection authentication keys
could not be generated, no PASSWORD_PARAMETER_NAME
was
found but UNAUTHENTICATED_CONNECTIONS_ALLOWED
is false,
or a log file could not be opened due to a security violation.protected String Config_Pathname(String name)
If the specified name is null or an absolute pathname
it is
returned unmodified. Otherwise the name is added to the absolute
pathname of the Dispatcher name
Group.
name
- A parameter name. May be null.
public static String Default_Log_Filename()
default Dispatcher name
plus the
".log" extension.public String Log_Pathname()
log pathname
that was set, or the
default log filename
if
a log pathname has not been set.public String Log_Pathname(String pathname) throws FileNotFoundException
If a log stream
is already open it is flushed.
If it is not the stdout, it is closed.
If the pathname is STDOUT
the log stream is set to the
stdout
stream. Otherwise the pathname is checked
for an existing file. N.B.: An existing file is appended. If
the file does not exist an attempt is made to create it. The
log stream
is put in auto-flush mode.
pathname
- The pathname to the log file. If null or the
empty String the default log
filename
will be used.
FileNotFoundException
- If an existing file could not be
appended, possibly because it is not a regular file, or the
file could not be created for writing.Log_Stream()
public PrintStream Log_Stream()
log file
has been
established.Log_Pathname(String)
public boolean Logging()
Logging(boolean)
public boolean Logging(boolean enabled)
If logging is being enabled from a disabled state, and no log stream
is open, the current log pathname
is used to open a log stream.
If logging is being disabled from an enabled state the log stream is flushed but the log stream remains open.
N.B.: Logging may be enabled and disabled while the Dispatcher is in operation.
enabled
- true if logging is to be enabled; false otherwise.
public void Log_Time(String report)
If logging is disabled nothing is done.
The current date and time is written using the DATE_FORMAT
on a line by itself. This is followed by the report text. If the
report text is null a single empty line is written.
report
- The report text to be logged. If null a single empty
line is written.Logging(boolean)
,
Log_Pathname(String)
public void Log(String report)
If logging is disabled nothing is done.
report
- The report text to be logged. If null a single empty
line is written.Logging(boolean)
,
Log_Pathname(String)
public void Log()
Log(String)
public void Start() throws Configuration_Exception, SecurityException, IOException
If the Dispatcher has already been started nothing is done.
The Dispatcher is first configured
.
If logging
has been enabled a startup
message is logged.
Then the communications socket is established.
The connection listener is then run
which listens for
and handles Messenger client connections.
N.B.: Once the Dispatcher is started it will continue to run until interrupted, a fatal exception occurs, or the JVM exits.
Configuration_Exception
- If there was a problem configuring
the Dispatcher.
SecurityException
- If, during configuration, the connection
authentication keys could not be generated, no PASSWORD_PARAMETER_NAME
was found but UNAUTHENTICATED_CONNECTIONS_ALLOWED
is false, or a log file
could not be opened due to a security violation. This exception
will also be thrown if a security violation was encountered while
establishing the communication channel.
IOException
- If there was a problem while establishing the
communication channel.public boolean Started()
Start()
public void run()
N.B.: A check is first made that the Dispatcher connection
listener has been started
and, if it has not,
it is told to start
. This enables the Dispatcher
to be used a Thread Runnable. However, starting the connection
listener causes an exception to be thrown the Runnable will not run.
In this case the () run exception
must be
specifically retrieved.
While the listener socket that was bound when the Dispatcher
was constructed is open the thread continually listens for new
connections. Each connection is a potential new client.
Each connection is allocated a new Messenger that uses the
socket as its communication channel and this Dispatcher as
its employer
.
Each client must complete a protocol handshake:
Identify
sending
the client via the new Messenger an Identify
request Message. This Message contains an Action
parameter with the Identify
value. If authentication is
required or the Dispatcher has been configured with password a
Key
parameter will also be included that
has an encoded public key value.
Authentication
Key
parameter in a copy
of its usual Identity Message to the required password value and
then passing both the Identify and Identity Messages to the
Authentication utility which will replace the password value of the
Identity Key parameter with an encrypted and encoded value created
using the public key from the Identify Message. If client
authentication is not required no authentication information needs
to be provided. The Identity Message is sent by the client in
response to the Identify Message.
Identity
receive
an
Identity Message in response to its Identify request within the
timeout
period or the Messenger will be
told that it is done
which
will drop the connenction. The identity Message and its route-from
addressing is logged
.
Authenticate
UNAUTHENTICATED_CONNECTIONS_ALLOWED
is true and the Dispatcher has
not been configured
with a
password then client Identity authentication always succeeds. When
password authentication is required for the Identity authentication
to succeed the Identity Message must include a KEY_PARAMETER_NAME
parameter with a value that can be decoded and
decrypted using the Dispatcher's private key to produce a password
value that is identical to the one with which it has been
configured.
Identity
Message to the client. If authentication
failed a NACK
Message will be sent
containing the client's Identity without any Key parameter plus an
Explanation
parameter saying
that the Identity did not authenticate.
done
which closes down the Messenger and
closes its connection.
After conclusion of the protcol handshake the route-to address list
of the identity Message is set to its route-from list and the Message
is bound the Messenger as its (@link Messenger#Identity(Message)
identity}. The Messenger is added to the list of connected Messengers
and is told to asynchronously listen for Messages. Then the list of
Report_to_Messengers
are
sent a Message that includes the identities of the connected
Messengers
.
Each connection step is logged.
run
in interface Runnable
SocketChannel
protected void Messenger_Quit(Messenger messenger, String report)
The messenger is removed from the list of connected Messengers and
the list of Messengers to receive reports of connected Messengers. If
the Messenger was removed from the connected list, the disconnection
is logged with the Messenger details and the report (if non-null),
and the Messenger is told that it is done
in case it has not already initiated its communication shutdown
procedures.
When the Messengers list is empty the shutdown-in-progress flag, that
may have been set in the shutdown
procedure, is
reset.
messenger
- The Messenger to be disconnected.report
- A report to be logged. May be null.protected void Messenger_Quit(Messenger messenger, Message message)
If a message is specified and it contains an EXPLANATION_PARAMETER_NAME
and/or an EXCEPTION_PARAMETER_NAME
the values of those parameters are assembled into report to be included
in the log. If there are any additional parameters, other than the
ACTION_PARAMETER_NAME
, a description of all remaining parameters
are also included in the log report.
messenger
- The Messenger to be disconnected.message
- A Message to be logged. May be null.Messenger_Quit(Messenger, String)
protected void Shutdown()
The communications channel is closed. If there are any registered
Messengers they are told they are Done
and a shutdown-in-progress flag is set. This flag is checked
up to five times with a two second delay between checks until either
the flag is found to be reset or the maximum number of checks have
been done. Finally a shutdown notice is logged that indicates
whether the shutdown of all the Messegers was completed.
protected Messenger Lookup_Messenger(String address)
The list of connected Messengers is searched for one that has an
address
that matches the one that is
specified.
address
- The address String associated with a Messenger.
If null or the empty String null is returned.
public static Message Authentication(Message identify, Message identity)
During the handshake protocol, while establishing a conneciton to a
Dispatcher, authentication information will need to be exchanged
unless UNAUTHENTICATED_CONNECTIONS_ALLOWED
. In the IDENTIFY_ACTION
Message that the Dispatcher sends to initiate the
handshake for a new client connection a KEY_PARAMETER_NAME
parameter will provide a public key value that must be used to
produce an encoded password value returned in the KEY_PARAMETER_NAME
parameter of the required IDENTITY_ACTION
Message response.
The authentication key in the Identify Message is used with the authentication key in the Identity Message to produce an encoded authentication key in the Identity Message. If either the Identify or Identity Message do not have an authentication key then the returned Message will not have this parameter. The mechanism by which the Identify key is used to encode the Identity key is opaque.
N.B.: The Identity Message that is provided is modified, not copied.
identify
- A Message from which to obtain a KEY_PARAMETER_NAME
parameter with a public key authentication
value. If null the identity Message is returned with any KEY_PARAMETER_NAME
parameter removed.identity
- A Message from which to obtain a KEY_PARAMETER_NAME
parameter with a private password authentication
value. The value is replaced with encoded authentication
information that combines the public key with the password. If null
null is returned.
KEY_PARAMETER_NAME
parameter if, and only if,
the original value was successfully encoded into the appropriate
authentication response value.Authentication
protected boolean Authenticate(Message identity)
If no password was obtained from the configuration
and UNAUTHENTICATED_CONNECTIONS_ALLOWED
is
true, the identity is accepted without further authentication.
Authentication requires that the identity contain a KEY_PARAMETER_NAME
parameter value that is used as the encoded authentication password
to authenticate
the client identity. The decoded authentication
password from the identity, after being decrypted using the
Dispatcher's private key, must match the Dispatcher password.
Authentication
public Message Listener_Identity()
This method implements the Message_Delivered_Listener
interface.
Listener_Identity
in interface Message_Delivered_Listener
identity
information.Identity()
public void Message_Delivered(Message_Delivered_Event event)
This method implements the Message_Delivered_Listener
interface.
The following message actions
are recognized:
IDENTIFY_ACTION
identity Message
.
MESSENGERS_REPORT_ACTION
currently connected messenger identities
that have been
selected by the request message.
START_MESSENGER_REPORTING_ACTION
Starts connected
Messenger reporting
for the requesting Messenger.
STOP_MESSENGER_REPORTING_ACTION
Stops connected
Messenger reporting
for the requesting Messenger.
LINK_MESSENGER_ACTION
Messenger_Link(Messenger, Message)
Messenger-to-Messenger communication} is established between the
requesting Messenger and another Messenger for which an address
is provided.
UNLINK_MESSENGER_ACTION
Messenger_Unlink(Messenger, Message)
Messenger-to-Messenger communication} is removed between the
requesting Messenger and another Messenger for which an address
is provided.
DONE_ACTION
quit
and is to be
disconnected.
UNDELIVERABLE_ACTION
sent
could
not be delivered. The undeliverable Message is logged.
NACK_ACTION
sent
was
rejected. The rejected Message is logged.
Any other messages are logged as unrecognized and a NACK
is sent back to the Messenger from
which the message was received.
Message_Delivered
in interface Message_Delivered_Listener
event
- The Message_Delivered_Event
containing the
Message that was delivered and a reference to the Messenger that
sent it.protected boolean Send(Messenger messenger, Message message, boolean report_failure)
If failure reporting is enabled and the Messenger throws an exception
while sending the Message this is logged with the Messenger
description, the Message routing addresses, the Message description
and the exception description. In any case if the exception is an
IOException the Messenger is quit
.
messenger
- The Messenger used to send the Message. If null
nothing is done.message
- The Message to be sent. If null nothing is done.report_failure
- true if failure reporting is enabled; false
otherwise.
protected boolean Send(Messenger messenger, Message message)
The Message is sent
with
failure reporting enabled.
messenger
- The Messenger used to send the Message. If null
nothing is done.message
- The Message to be sent. If null nothing is done.
Send(Messenger, Message, boolean)
public Message Messenger_Identities(Messenger source_messenger, String name)
A connected Messenger is the client Messenger that initiated a
connection, completed the identification Message handshake with the
Dispatcher Messenger allocated to the client, and that is
currently active (in the Messengers). Connected Messengers may be
selected by NAME_PARAMETER_NAME
value. If no name is specified
all connected Messengers are selected. However, the source Messenger
to whom the Message will be sent is never selected.
The assembled Message includes an IDENTITY_ACTION
group for
each selected Messenger. The parameters in this group are the identity
Message parameters bound to the
Messenger. In addition, a ROUTE_TO_PARAMETER_NAME
is added to
each identity that is an array of Messenger addresses
for each Messenger on the route from
the source Messenger to the connected Messenger. The Value of this
parameter can be used to set the route-to list
of a Message to be sent from the source Messenger to
the destination connected Messenger.
Since the route-to list of each connected Messenger identity Message
is in Dispatcher-to-client
order the route-to list of the source Messenger must be reversed to
produce a correct route-to address list in source-to-client order.
This reversed address list is then completed with the route-to list
of the client Messenger being identified. N.B.: Message
route-to address lists are in LIFO order: the last address of the
list is for the first Messenger on the transmission route, and the
first address is for the destination client Messenger.
source_messenger
- The Messenger to whom the returned
Message is intended. Route-to address lists for each identified
Messenger will be relative to this Messenger. If null, or the
Messenger has no identity
, or the
identity has no () route-to list
the
returned Message will only contain an EXPLANATION_PARAMETER_NAME
parameter with a brief message value
describing the problem.name
- The NAME_PARAMETER_NAME
value used to select
connected Messengers. If null, all Messengers will be selected.
The source_messenger is never selected.
EXPLANATION_PARAMETER_NAME
parameter with a brief message value describing the problem.protected void Report_Messengers()
Messenger identities
to each of the Messengers that have
requested connection
reports
.
protected void Start_Messenger_Reporting(Messenger messenger)
The specified Messenger is added, if it is not already present,
to the list of Messengers that will be sent the list of all
connected Messenger identities
whenever a new Messenger connects or
disconnects.
The Messenger is sent the current connected Messengers list.
messenger
- The Messenger to receive automatic Messenger
connection reporting. If null, nothing is done.Stop_Messenger_Reporting(Messenger)
protected void Stop_Messenger_Reporting(Messenger messenger)
The specified Messenger is removed, if it is present,
from the list of Messengers that will be sent the list of all
connected Messenger identities
.
messenger
- The Messenger to receive automatic Messenger
connection reporting. If null, nothing is done.Start_Messenger_Reporting(Messenger)
protected void Messenger_Link(Messenger source_messenger, Message message)
The specified Message must contain an ADDRESS_PARAMETER_NAME
value that specifies the address of known Messenger
to which the source Messenger is to be linked. The
linked Messenger is added
to the forwarding list
of the source Messenger and the source
Messenger is added to the forwarding list of the linked Messenger.
The specified Message is returned to the source Messenger with the
addition of an ACK_ACTION
token and an IDENTITY_ACTION
group containing the identity
of the linked Messenger.
If a Messenger with the address to link to is not known the reply
Message contains a NACK_ACTION
token and an EXPLANATION_PARAMETER_NAME
, instead of a Messenger identity, that
describes the reason that the link could not be done.
N.B.: If the Message contains either an ACK_ACTION
or
NACK_ACTION
token nothing is done.
source_messenger
- The source Messenger that is initiating
the Messenger link. If null nothing is done.message
- The Message contain the address of the Messenger to
be linked. If null nothing is done.Messenger_Unlink(Messenger, Message)
protected void Messenger_Unlink(Messenger source_messenger, Message message)
The specified Message must contain an ADDRESS_PARAMETER_NAME
value that specifies the address of known Messenger
from which the source Messenger is to be unlinked. The
linked Messenger is removed
from the forwarding list
of the source Messenger and the source
Messenger is removed from the forwarding list of the linked Messenger.
N.B.: No reply is sent to the source Messenger.
source_messenger
- The source Messenger that is initiating
the Messenger link. If null nothing is done.message
- The Message contain the address of the Messenger to
be linked. If null nothing is done.Messenger_Link(Messenger, Message)
protected static Value Route(Messenger source_messenger, Messenger client_messenger)
public static Value Route_To(Messenger messenger)
The route_to values specify the Message routing addresses
used by a Messenger when a Message
is sent
.
messenger
- A Messenger for which to get the Message route-to
address values
protected void Status_Report(Messenger source_messenger, Message message)
The status report contains the Dispatcher identity
plus its communications IDENTIFY_TIMEOUT_PARAMETER_NAME
, PORT_PARAMETER_NAME
,
#HELLO_PORT_PARAMETER_NAME} and HELLO_ADDRESS_PARAMETER_NAME
parameters.
The Dispatcher identification is followed by a MESSENGER_STATUS_PARAMETER_NAME
group containing each connected
Messenger's identity
with the identities
of each of its forwarding
Messengers
and its Message statistics:
MESSAGES_SENT_PARAMETER_NAME
from Messenger.Messages_Sent()
MESSAGE_BYTES_SENT_PARAMETER_NAME
from Messenger.Message_Bytes_Sent()
MESSAGES_SENT_DROPPED_PARAMETER_NAME
from Messenger.Messages_Sent_Dropped()
MESSAGES_SENT_CORRUPTED_PARAMETER_NAME
from Messenger.Messages_Sent_Corrupted()
MESSAGES_RECEIVED_PARAMETER_NAME
from Messenger.Messages_Received()
MESSAGE_BYTES_RECEIVED_PARAMETER_NAME
from Messenger.Message_Bytes_Received()
MESSAGES_RECEIVED_DROPPED_PARAMETER_NAME
from Messenger.Messages_Received_Dropped()
MESSAGES_RECEIVED_CORRUPTED_PARAMETER_NAME
from Messenger.Messages_Received_Corrupted()
MESSAGES_UNFORWARDABLE_PARAMETER_NAME
from Messenger.Messages_Unforwardable()
Each Messenger that registered an error condition
will also have an EXCEPTION_PARAMETER_NAME
describing the exception following the Message statistics.
Following the Messenger identities a MEMORY_STATUS_PARAMETER_NAME
group contains memory use parameters:
MEMORY_AVAILABLE_PARAMETER_NAME
- the maximum amount of
memory available to the Java Runtime Environment.
MEMORY_ALLOCATED_PARAMETER_NAME
- the amount of memory
currently allocated by the application.
MEMORY_FREE_PARAMETER_NAME
- the amount of allocated memory
currently unused.
source_messenger
- The Messagner to use to send the status
report Message.message
- The Message to reply
to
.protected void NACK(Messenger messenger, Message message)
public static void main(String[] args)
public static void Usage()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |