public class ServerChannel extends Object implements ReplyListener, TimerListener, TransactionListener, MulticastListener, OneWayListener
Communication channel between a server application and the OBCOM
NetServer. Once the communcation is established with the NetServer, the
application is able to receive transaction requests, send multicast data, and
provide other services to the clients of a NetServer. A server application is
constructed by extending the ServerChannel
class and then overriding
the "processXXXX
" methods. For example, the processTransaction
method is called
each time the server receives a transaction request from a NetServer client
application (see ClientChannel
for details about building NetServer
client applications). The following example uses ServerChannel
to
implement a server application named "JSERVER"
. This server is very
simple: it just echos the data received in all transaction requests:
import cl.obcom.netclient.*; public class JServer extends ServerChannel { // Called when a transaction request arrives: just echo it protected void processTransaction(String name, Message message) { sendAckReply("The reply message is " + message.getData()); } // Startup method of the JServer public static void main(String[] args) { JServer server = new JServer(); server.execute("JSERVER", "net://localhost:10102", "file:///C:/desktop/recs/*.asp"); } }
Constructor and Description |
---|
ServerChannel()
Constructs a new
ServerChannel instance. |
Modifier and Type | Method and Description |
---|---|
Object |
beginTransaction(String name,
Message message)
Called before a transaction request is processed by
processTransaction . |
void |
cancelTimer()
Cancels the execution of the
processTimer method. |
void |
commitTransaction(String name,
Object context)
Called after a transaction request has been successfuly processed by
processTransaction . |
void |
connect(String serverName,
String netserURI)
Connects this
ServerChannel to the NetServer specified by the
supplied arguments. |
void |
connect(String serverName,
String netserURI,
LayoutManager layouts)
Connects this
ServerChannel to the NetServer specified by the
supplied arguments. |
void |
connect(String serverName,
String netserURI,
String layoutsURI)
Connects this
ServerChannel to the NetServer specified by the
supplied arguments. |
void |
disableMulticast(String name)
Disables the reception of multicast messages identified by the
specified
name . |
void |
enableMulticast(String name)
Enables the reception of multicast messages identified by the
specified
name . |
void |
enableMulticast(String name,
MulticastListener listener)
Enables the reception of multicast messages identified by the
specified
name . |
void |
execute(String serverName,
String netserURI)
Starts the execution of this
ServerChannel using the supplied
arguments. |
void |
execute(String serverName,
String netserURI,
LayoutManager layouts)
Starts the execution of this
ServerChannel using the supplied
arguments. |
void |
execute(String serverName,
String netserURI,
String layoutsURL)
Starts the execution of this
ServerChannel using the supplied
arguments. |
Layout |
getLayout(String name)
Returns the message layout identified by the supplied
name . |
LayoutManager |
getLayoutManager()
Returns the
LayoutManager in use by this ServerChannel . |
String |
getMetaServerPID()
Returns the MetaServer Process ID of this
ServerChannel . |
String |
getName()
Returns the name of this
ServerChannel . |
String |
getNetServerHost()
Returns the NetServer host address (name or IP number).
|
int |
getNetServerPort()
Returns the NetServer port number.
|
URI |
getNetServerURI()
Returns the NetServer URI (protocol, host and port).
|
boolean |
getReplyMissing()
Returns
true if no reply message has been sent for the current
transaction. |
int |
getSessionID()
Returns the session ID of this
ServerChannel . |
long |
getTimeout()
Returns the server's event timeout in milliseconds.
|
String |
getTimestamp()
Returns an NetServer timestamp.
|
String |
getTranBootHost()
Returns the boot host name of the current transaction.
|
String |
getTranClientName()
Returns the client name of the current transaction.
|
String |
getTranDefaultHost()
Returns the default host name of the current transaction.
|
String |
getTranLocalHost()
Returns the local host name of the current transaction.
|
String |
getTranOriginator()
Returns the originator name of the current transaction.
|
String |
getTranOriginatorSession()
Returns the originator session name of the current transaction.
|
String |
getTranOriginatorStation()
Returns the originator station name of the current transaction.
|
String |
getTranProcessName()
Returns the process name of the current transaction.
|
String |
getTranSecurityHost()
Returns the security host name of the current transaction.
|
int |
getTranSequence()
Returns the sequence code of the current transaction.
|
int |
getTranSessionID()
Returns the session ID of the current transaction.
|
String |
getTranTimestamp()
Returns the timestamp of the current transaction.
|
String |
getVersion()
Returns the implementation version of this
ServerChannel . |
static Properties |
loadProperties(String fileName)
Returns the properties contained in the file
fileName . |
void |
processHalt()
Called when a halt message is received from the NetServer.
|
void |
processInit(boolean initialize)
Called when an initialize or reinitialize message is received from the
NetServer.
|
void |
processMulticast(String name,
Message message)
Called when a multicast message is received from the NetServer.
|
void |
processOneWay(String name,
Message message)
Called when a one-way
message is received. |
void |
processReply(int sequence,
Message message,
Object context)
Called when an asynchronous transaction reply message is received from
the NetServer.
|
void |
processTimeout()
Called when a timeout event occurs.
|
void |
processTimer()
Called when a timer event occurs.
|
void |
processTransaction(String name,
Message message)
Called when a transaction request message is received from the NetServer.
|
TransactionListener |
registerTransaction(String name,
TransactionListener listener)
Registers a
listener for transactions identified by name . |
void |
releaseHold()
Releases the hold on this server so it can continue to receive
messages.
|
void |
rollbackTransaction(String name,
Object context,
Exception exception)
Called when an
exception is thrown while processing a
transaction. |
void |
runAsync(Runnable runnable)
Submits a runnable for later execution on the server's thread.
|
void |
sendAckReply(Object reply)
Sends a transaction reply message with an
ACK code, indicating successful completion. |
void |
sendConsole(String command)
Sends a console command to the NetServer.
|
void |
sendError(String name,
String description)
Sends an error report message to the NetServer.
|
void |
sendMulticast(String name,
Object value)
Sends a multicast message to the NetServer.
|
void |
sendMulticast(String name,
Object value,
boolean encrypted)
Sends an multicast message to the NetServer.
|
void |
sendNakReply(Object reply)
Sends a transaction reply message with a
NAK code, indicating unsuccessful completion. |
int |
sendOneWay(String name,
Object message)
Sends a one-way message to the named destination with encryption.
|
void |
sendOperator(String command)
Sends a operator command to the NetServer.
|
void |
sendReply(Object reply,
int replyCode)
Sends a transaction reply message with the supplied
replyCode . |
void |
sendReply(Object reply,
int replyCode,
boolean hold)
Sends a transaction reply message with the supplied
replyCode and required server hold state. |
int |
sendRequest(String service,
Object request)
Sends an asynchronous transaction to the specified
service with
supplied request data. |
int |
sendRequest(String service,
Object request,
ReplyListener listener)
Sends an asynchronous transaction to the specified
service with
supplied request data and listener . |
int |
sendRequest(String service,
Object request,
ReplyListener listener,
Object context)
Sends an asynchronous transaction to the specified
service
with supplied request data, listener and context . |
Message |
sendTransaction(String service,
Object request)
Sends an synchronous transaction request to the specified
service using the supplied request data. |
Message |
sendTransaction(String service,
Object request,
long timeout)
Sends an synchronous transaction request to the specified
service using the supplied request data and timeout option. |
void |
setTimeout(long timeout)
Changes the server's event timeout.
|
void |
startTimer(long period)
Schedules the execution of the
processTimer method
of this ServerChannel at approximately regular intervals
separated by period . |
void |
startTimer(long period,
TimerListener listener)
Schedules the execution of the
processTimer method of the supplied listener at approximately
regular intervals separated by period . |
void |
stop()
Stops the execution of this
ServerChannel . |
TransactionListener |
unregisterTransaction(String name)
Unregisters the transaction listener identified by
name . |
boolean |
waitForEvent(ServerEvent event,
long timeout)
Blocks waiting for the next server event or until a specified amount of
time has elapsed.
|
public String getName()
ServerChannel
. The value returned is the
same as the server name provided to the execute
method or the connect
method, except that all alpha (A-Z)
characters are in upper-case.ServerChannel
.execute(String, String, LayoutManager)
,
connect(String, String, LayoutManager)
public URI getNetServerURI()
execute
method, or null
if this ServerChannel
is not
executing.null
.execute(String, String, LayoutManager)
public String getNetServerHost()
execute
method, or null
if this ServerChannel
is not
executing.null
.execute(String, String, LayoutManager)
public int getNetServerPort()
execute
method, or
0
(zero) if this ServerChannel
is not executing.0
(zero).execute(String, String, LayoutManager)
public int getSessionID()
ServerChannel
. This value has
meaning only when connected to the NetServer. The value returned by this
method is undefined if not connected to the NetServer.ServerChannel
.execute(String, String, LayoutManager)
,
connect(String, String, LayoutManager)
public String getMetaServerPID()
ServerChannel
. If this
ServerChannel
is not running as a thread of a MetaServer, it
returns null
.ServerChannel
.public String getVersion()
ServerChannel
. The
returned string consists of four decimal integers separated by periods
"."
, for example "1.9.2042.25539"
. These four integers
represent the major
, minor
, build
and revision
version numbers, respectively.ServerChannel
.public LayoutManager getLayoutManager()
LayoutManager
in use by this ServerChannel
.
The LayoutManager
returned is the same one provided to the execute
method.LayoutManager
in use by this ServerChannel
.execute(String, String, LayoutManager)
,
LayoutManager
public Layout getLayout(String name)
name
. If
the message layout is not available in the cache, it is downloaded,
compiled, stored in the cache and returned back to the caller of this
method. Layouts are downloaded using the LayoutManager
provided
to the execute
method.name
- the name of the required message layout.execute(String, String, LayoutManager)
,
Layout
public void stop()
ServerChannel
. The communication
channel with the NetServer is closed, and all other resources are
released. The execution of this ServerChannel
can be started
again using an execute
method, or the connect
plus waitForEvent
methods. It is legal,
but useless, to call this method if this ServerChannel
is not
executing or waiting for an event.public void connect(String serverName, String netserURI)
Connects this ServerChannel
to the NetServer specified by the
supplied arguments. See connect
for further details. This is just a convenience method
implemented by the following call statement:
connect(serverName, netserURI, (LayoutManager) null);
serverName
- the name of this ServerChannel
.netserURI
- the NetServer URI as "protocol://host:port"
.connect(String, String, LayoutManager)
public void connect(String serverName, String netserURI, String layoutsURI)
Connects this ServerChannel
to the NetServer specified by the
supplied arguments. See connect
for further details. This is just a convenience method
implemented by the following call statement:
connect(serverName, netserURI, new LayoutManager(layoutsURL));
serverName
- the name of this ServerChannel
.netserURI
- the NetServer URI as "protocol://host:port"
.layoutsURI
- the URI used to create a LayoutManager
.connect(String, String, LayoutManager)
public void connect(String serverName, String netserURI, LayoutManager layouts)
ServerChannel
to the NetServer specified by the
supplied arguments. The serverName
argument is the name of this
Server, which must be registered with the NetServer.
The netserURI
argument must have the form "protocol://address:port
", where address
is the host name or IP
address of the NetServer listening on the specified port
. The
protocol
can be "net
" for classic connections, or "nets
" for SSL/TLS connections.
The layouts
argument provides a LayoutManager
used to
download and cache message layouts. If layouts
is null
no
layouts will be downloaded and automatically assigned to messages.
serverName
- the name of this ServerChannel
.netserURI
- the NetServer URI as "protocol://host:port"
.layouts
- a LayoutManager
used to download layouts.NullPointerException
- if an argument is null
or empty.IllegalStateException
- if the server is already executing.IllegalArgumentException
- if an argument is invalid.ConnectException
- when the connection to the server fails.public void execute(String serverName, String netserURI)
Starts the execution of this ServerChannel
using the supplied
arguments. See execute
for further details. This this is just a convenience method implemented
by the following call statement:
execute(serverName, netserURI, (LayoutManager) null);
serverName
- the name of this ServerChannel
.netserURI
- the NetServer URI as "protocol://host:port"
.execute(String, String, LayoutManager)
public void execute(String serverName, String netserURI, String layoutsURL)
Starts the execution of this ServerChannel
using the supplied
arguments. See execute
for further details. This this is just a convenience method implemented
by the following call statement:
execute(serverName, netserURI, new LayoutManager(layoutsURL));
serverName
- the name of this ServerChannel
.netserURI
- the NetServer URI as "protocol://host:port"
.layoutsURL
- a URL used to create a LayoutManager
.execute(String, String, LayoutManager)
public void execute(String serverName, String netserURI, LayoutManager layouts)
ServerChannel
using the supplied
arguments. The serverName
argument is the name of this Server,
which must be registered with the NetServer.
The netserURI
argument must have the form "protocol://address:port
", where address
is the host name or IP
address of the NetServer listening on the specified port
. The
protocol
can be "net
" for classic connections, or "nets
" for SSL/TLS connections.
The layouts
argument provides a LayoutManager
used to
download and cache message layouts. If layouts
is null
no
layouts will be downloaded and automatically assigned to messages.
After validating the arguments, this method connects to the NetServer and
sends a registration message with the name of this server. It then
waits for messages to arrive and dispatches them to the apropiate "processXXXX
" methods.
This method returns to its caller when this ServerChannel
has
been halted by a system operator, when the stop
method is called, or when an unrecoverable error occurs. To halt this
server, a system operator needs to execute a "halt server
"
command in an NetServer Console.
serverName
- the name of this ServerChannel
.netserURI
- the NetServer URI as "protocol://host:port"
.layouts
- a LayoutManager
used to (down)load message layouts.IllegalStateException
- if the server is already executing.NullPointerException
- if an argument is null
or empty.IllegalArgumentException
- if an argument is invalid.NetException
- if an unrecoverable error occurs.stop()
,
connect(String, String, LayoutManager)
,
processInit(boolean)
,
processReply(int, Message, Object)
,
processTimer()
,
processTransaction(String, Message)
public String getTranBootHost()
null
.null
if there is no current transaction.Message.Label.BootHost
public String getTranClientName()
null
.null
if
there is no current transaction.Message.Label.TranClient
public String getTranDefaultHost()
null
.null
if there is no current transaction.Message.Label.DefaultHost
public String getTranLocalHost()
null
.null
if there is no current transaction.Message.Label.LocalHost
public String getTranOriginator()
null
.null
if there is no current transaction.Message.Label.TranOriginator
public String getTranOriginatorSession()
null
.null
if there is no current transaction.getTranOriginator()
public String getTranOriginatorStation()
null
.null
if there is no current transaction.getTranOriginator()
public String getTranProcessName()
null
.null
if
there is no current transaction.Message.Label.ProcessName
public String getTranSecurityHost()
null
.null
if there is no current transaction.Message.Label.SecurityHost
public int getTranSequence()
0
.0
if
there is no current transaction.Message.getSequence()
public int getTranSessionID()
0
.0
if
there is no current transaction.Message.getSessionID()
public String getTranTimestamp()
null
.null
if
there is no current transaction.Message.Label.TranTimestamp
public boolean getReplyMissing()
true
if no reply message has been sent for the current
transaction. If no transaction is currently being processed, it returns
false
. All transaction requests must send a reply, so if the
method processTransaction
completes and getReplyMissing
is still true
, then a
NAK
reply message will be sent back to the client.true
if no reply message has been sent for the current
transaction.sendReply(Object, int, boolean)
,
processTransaction(String, Message)
public boolean waitForEvent(ServerEvent event, long timeout)
false
if the event is QUIT
, otherwise it returns true
. All event
related information is returned in the supplied event
argument
(see ServerEvent
). If timeout
is zero, the method will
block forever waiting for an event to occur.
All the resources of this ServerChannel
are released, and its
communication channels are closed when a QUIT
event occurs, or when an exception is thrown. The application using this
method is responsible for releasing its own resources.
event
- used to return the type and message of the event.timeout
- the maximum time to wait in milliseconds.false
if the event is QUIT
,
otherwise true
.NullPointerException
- if event
is null
.IllegalArgumentException
- if timeout
is negative.NetException
- if an unexpected error occurs while waiting.connect(String, String, LayoutManager)
,
stop()
public void processInit(boolean initialize) throws Exception
reinit server
" command from an
NetServer Console.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation executes the releaseHold
method to allow the server to receive
transactions from the NetServer.
initialize
- is true
when an initialize message was
received.Exception
- if an error occurs.releaseHold()
public void runAsync(Runnable runnable)
runnable
- a runnable to be executed later on the server's thread.NullPointerException
- if runnable
is null.public long getTimeout()
processTimeout
everytime the
timeout expires while waiting for an event.processTimeout()
,
setTimeout(long)
public void setTimeout(long timeout)
timeout
is
zero, the server will block forever waiting for the next event. If the
value of timeout
is positive, the server will call the method
processTimeout
everytime the timeout expires
while waiting for an event. If the value of timeout
is negavite,
an exception is thrown.timeout
- maximum time to wait for an event in milliseconds.IllegalArgumentException
- if timeout
is negative.processTimeout()
,
getTimeout()
public void processTimeout() throws Exception
setTimeout
method.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation executes setTimeout(0)
to stop the generation of timeout events.
Exception
- if an error occurs.getTimeout()
,
setTimeout(long)
public void startTimer(long period)
processTimer
method
of this ServerChannel
at approximately regular intervals
separated by period
.period
- time (in seconds) between successive executions of the
processTimer
method.processTimer()
,
cancelTimer()
public void startTimer(long period, TimerListener listener)
processTimer
method of the supplied listener
at approximately
regular intervals separated by period
.period
- time (in seconds) between successive executions of the
processTimer
method.listener
- the listener for timer events (can be null).TimerListener.processTimer()
,
cancelTimer()
public void cancelTimer()
processTimer
method.
If the method is running when this call occurs, the method will run to
completion, but will never run again until a call to the startTimer
is executed.startTimer(long)
,
processTimer()
public void processTimer() throws Exception
startTimer
method.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation executes the cancelTimer
method to stop the generation of timer events.
processTimer
in interface TimerListener
Exception
- if an error occurs.startTimer(long)
,
cancelTimer()
public void processReply(int sequence, Message message, Object context) throws Exception
sendRequest
method. Normally, though, transaction request are
synchronous, in which the server process is blocked until the reply
message is received.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation simply ignores the
asynchronous reply message
.
processReply
in interface ReplyListener
sequence
- the sequence of the reply message.message
- the data of the reply.context
- user-defined context information of this message.Exception
- if an error occurs.sendRequest(String, Object)
public Object beginTransaction(String name, Message message) throws Exception
processTransaction
. This method should execute
initialization logic common to all transactions, such as starting a
database transaction. The user-defined context object returned by this
method is later supplied as an input argument to the commitTransaction
or rollbackTransaction
methods.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation does nothing and returns the
request message
.
name
- the name of the transaction.message
- the data of the transaction.Exception
- if an error occurs.processTransaction(String, Message)
,
commitTransaction(String, Object)
,
rollbackTransaction(String, Object, Exception)
public void processTransaction(String name, Message message) throws Exception
name
and a message
containing the request data, and every transaction request must be
answered (replied to), otherwise the client that send the request will be
blocked forever waiting for the reply.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation uses the sendNakReply
method to send a NAK
reply message explaining the
requiered transaction is not implemented.
processTransaction
in interface TransactionListener
name
- the name of the transaction.message
- the data of the transaction.Exception
- if an error occurs.beginTransaction(String, Message)
,
commitTransaction(String, Object)
,
rollbackTransaction(String, Object, Exception)
public void commitTransaction(String name, Object context) throws Exception
processTransaction
. This method should
execute termination logic common to all successful transactions, such
performing a database commit.
This method is meant to be overriden by classes that extend
ServerChannel
. This default implementation does nothing.
name
- the name of the transaction.context
- the user-defined context object returned by the
beginTransaction
method.Exception
- if an error occurs.beginTransaction(String, Message)
,
processTransaction(String, Message)
,
rollbackTransaction(String, Object, Exception)
public void rollbackTransaction(String name, Object context, Exception exception) throws Exception
exception
is thrown while processing a
transaction. This can happen while executing beginTransaction
, processTransaction
or
commitTransaction
. This method should execute
termination logic common to all failed transactions, such as performing a
database rollback. Any exceptions thrown by this method generate a NAK
reply message.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation uses the sendNakReply
method to send a NAK
reply message containing the
error message of the exception
.
name
- the name of the transaction.context
- the user-defined context object returned by the
beginTransaction
method.exception
- the exception thrown during transaction processing.Exception
- if an error occurs.beginTransaction(String, Message)
,
processTransaction(String, Message)
,
commitTransaction(String, Object)
public TransactionListener registerTransaction(String name, TransactionListener listener)
listener
for transactions identified by name
.
If a listener for name
was already registered, its definition
will be replaced by this new one. The processTransaction
method of this
listener
will be called whenever a transaction identified by
name
arrives from the NetServer.name
- the name of the transaction to register.listener
- the listener of transaction messages.name
, or
null
if it was not registered.NullPointerException
- if name
or listener
are null
or empty.TransactionListener.processTransaction(String, Message)
,
unregisterTransaction(String)
public TransactionListener unregisterTransaction(String name)
name
. If no
such listener exists, then nothing happens. If a transaction identified
by name
later arrives, it will be handled by the default processTransaction
method of this ServerChannel
.name
- the name of the transaction to unregister.name
was registered, or
null
if it was not registered.NullPointerException
- if name
is null
or empty.registerTransaction(String, TransactionListener)
public void processMulticast(String name, Message message) throws Exception
enableMulticast
method.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation executes the disableMulticast("*")
to disable the reception of all
multicast messages by this server.
processMulticast
in interface MulticastListener
name
- the name of the multicast message.message
- the data of the multicast message.Exception
- if an error occurs.enableMulticast(String)
,
disableMulticast(String)
public void processOneWay(String name, Message message) throws Exception
message
is received.
This method is meant to be overriden by classes that extend ServerChannel
. This default implementation simply ignores the
one-way message
.
processOneWay
in interface OneWayListener
name
- the name of the entity that sent the message.message
- the data of the one-way message.Exception
- if an error occurs.sendOneWay(String, Object)
public void processHalt() throws Exception
execute
method unblocks and returns to it's caller. This usually results
in the end of the execution of this server.
This method is meant to be overriden by classes that extend
ServerChannel
. This default implementation does nothing.
Exception
- if an error occurs.execute(String, String, String)
,
execute(String, String, LayoutManager)
public void sendAckReply(Object reply)
ACK
code, indicating successful completion. An invocation to this
method yields exactly the same result as sendReply(reply, Message.Reply.ACK)
.reply
- the reply message to a successful transaction execution.sendNakReply(Object)
,
sendReply(Object, int, boolean)
public void sendNakReply(Object reply)
NAK
code, indicating unsuccessful completion. An invocation to
this method yields exactly the same result as sendReply(reply, Message.Reply.NAK)
.reply
- the reply message to an unsuccessful transaction execution.sendAckReply(Object)
,
sendReply(Object, int, boolean)
public void sendReply(Object reply, int replyCode)
replyCode
. This reply code indicates the completion status of the
transaction, such as ACK
(for success) or
NAK
(in case of failure). An invocation to this
method yields exactly the same result as sendReply(reply, replyCode, false)
.reply
- the reply message.replyCode
- a reply code sush as ACK
or
NAK
.sendReply(Object, int, boolean)
public void sendReply(Object reply, int replyCode, boolean hold)
replyCode
and required server hold
state. The reply
data
is converted to a String
using the standard method toString
, hence any Java Object
can be used as
reply data. The replyCode
indicates the completion status of the
transaction, such as ACK
(for success) or
NAK
(in case of failure). If hold
is
true
, the server application will enter a hold state. This
hold state can later be released using the releaseHold
method.
This method can only be used within the context of a processTransaction
method. In other
words, you can only send a reply message to an active transaction
request. If there is no active transaction request, then this method does
nothing. If this method is used more than once within the context of the
same transaction request, only the first call will send a reply. The
other calls will be silently ignored. In other words, you can only send
one reply message to a transaction request.
reply
- the reply message.replyCode
- a reply code sush as ACK
or
NAK
.hold
- if true
the server will enter a hold state.processTransaction(String, Message)
,
releaseHold()
public Message sendTransaction(String service, Object request)
Sends an synchronous transaction request to the specified service
using the supplied request
data. See sendTransaction
for further
details. This is just a convenience method implemented by the following
statement:
sendTransaction(service, request, 0);
service
- name of the service host.server.transaction
.request
- the transaction request data for the service
.Message
.sendTransaction(String, Object, long)
public Message sendTransaction(String service, Object request, long timeout)
Sends an synchronous transaction request to the specified service
using the supplied request
data and timeout option. The
request
data is converted to a String
using the standard
method Object.toString()
, therefore any Java Object
can
be used as request data. The service
argument has one of the
following formats:
{HostName.}ServerName.TranName {HostName.}ServerName.[TranCode]
where optional items are shown within "{"
and
"}"
brackets, and the characters "."
, "["
and "]"
stand for themselves. If the optional HostName
is
not specified, then the NetServer Default Host name will be used.
TranName
is the name of the requested transaction, while TranCode
is and alternative one-character identification of the same
transaction. Either TranName
or TranCode
must be
specified. Some examples:
ECUSER.[!] ACASER.ACA-TIME HUB.IMSER.AddContact
The timeout
argument specifies the amount of milliseconds to
wait (more or less) for the reply message. If timeout
is zero,
however, the call simply waits forever for the reply message.
service
- name of the service host.server.transaction
.request
- the transaction request data for the service
.timeout
- the maximum time to wait for a reply (in milliseconds).Message
.NullPointerException
- if service
is null
or empty.IllegalArgumentException
- if service
or timeout
are invalid.TimeoutException
- if timeout
expired while waiting for the reply.public int sendRequest(String service, Object request)
service
with
supplied request
data. This method has exactly the same effect as
calling sendRequest(service, request, null)
.service
- name of the service host.server.transaction
.request
- the input request data sent to the service
.NullPointerException
- if service
is null
or empty.IllegalArgumentException
- if service
is invalid.sendRequest(String, Object, ReplyListener, Object)
public int sendRequest(String service, Object request, ReplyListener listener)
service
with
supplied request
data and listener
. This method has
exactly the same effect as calling sendRequest(service, request, listener, null)
.service
- name of the service host.server.transaction
.request
- the input request data sent to the service
.listener
- the listener for the reply message of this request.NullPointerException
- if service
is null
or empty.IllegalArgumentException
- if service
is invalid.sendRequest(String, Object, ReplyListener, Object)
public int sendRequest(String service, Object request, ReplyListener listener, Object context)
Sends an asynchronous transaction to the specified service
with supplied request
data, listener
and context
.
The request
data is converted to a String using the standard
toString
method, hence any Java object can be
used as request data. The reply message of this transaction request will
be dispatched by calling the processReply
method of the supplied listener
. The service
argument has one of the following formats:
{HostName.}ServerName.TranName {HostName.}ServerName.[TranCode]
where optional items are shown within "{"
and
"}"
brackets, and the characters "."
, "["
and "]"
stand for themselves. If the optional HostName
is
not specified, then the NetServer Default Host name will be used.
TranName
is the name of the requested transaction, while TranCode
is and alternative one-character identification of the same
transaction. Either TranName
or TranCode
must be
specified. Some examples:
ECUSER.[!] ACASER.ACA-TIME HUB.IMSER.AddContact
service
- name of the service host.server.transaction
.request
- the input request data sent to the service
.listener
- the listener for the reply message of this request.context
- user-defined context information for this request.NullPointerException
- if service
is null
or empty.IllegalArgumentException
- if service
is invalid.ReplyListener.processReply(int, Message, Object)
public int sendOneWay(String name, Object message)
Sends a one-way message to the named destination with encryption. If
encrypted
is true
the message will be sent encrypted. The
destination is identified by the supplied name
, which has the
following format:
{HostName:}EntityName{/ChannelName}
where optional items are shown within "{"
and
"}"
brackets, and the characters ":"
and "/"
stand for themselves. If the optional HostName
is not specified,
the NetServer Default Host name will be used. EntityName
is the name of the one-way destination, and the optional ChannelName
identifies a channel within EntityName
. Some
examples:
DEV-INET HUB:ACASER DAECLI/(40A0F16C)
name
- the name of the destination entity.message
- the message sent to the named destination.NullPointerException
- if name
is null
or empty.IllegalArgumentException
- if name
is invalid.processOneWay(String, Message)
public void enableMulticast(String name)
Enables the reception of multicast messages identified by the
specified name
. Multicast messages are generated by NetServers
when particular event occurs (e.g., the price of a stock has reached a
certain limit). When a multicast message arrives, the processMulticast
method of this ServerChannel
will be called. The name
argument has the following format:
{HostName.}MulticastName
with an optional HostName
. If no HostName
is
specified, the NetServer Local Host name value will be used. The
MulticastName
is requiered and has a maximum length of 10
chars.
name
- name of the multicast messages to enable.NetException
- if the operation fails.processMulticast(String, Message)
,
disableMulticast(String)
,
sendMulticast(String, Object, boolean)
public void enableMulticast(String name, MulticastListener listener)
Enables the reception of multicast messages identified by the
specified name
. Multicast messages are generated by NetServers
when particular event occurs (e.g., the price of a stock has reached a
certain limit). When a multicast message arrives, the processMulticast
method of supplied
listener
will be called. The name
argument has the
following format:
{HostName.}MulticastName
with an optional HostName
. If no HostName
is
specified, the NetServer Local Host name value will be used. The
MulticastName
is requiered and has a maximum length of 10
chars.
name
- name of the multicast messages to enable.listener
- the listener of multicast messages.NetException
- if the operation fails.MulticastListener.processMulticast(String, Message)
,
disableMulticast(String)
,
sendMulticast(String, Object, boolean)
public void disableMulticast(String name)
Disables the reception of multicast messages identified by the
specified name
. Multicast messages are generated by NetServers
when particular event occurs (e.g., the price of a stock has reached a
certain limit). The name
argument has the following format:
{HostName.}MulticastName
with an optional HostName
. If no HostName
is
specified, the NetServer Local Host name value will be used. The
MulticastName
is requiered and has a maximum length of 10 chars.
If the name
argument has the special value "*"
, then this
method disables the reception of all multicast messages that have been
enabled using the enableMulticast
method.
name
- name of the multicast messages to disable.NetException
- if the operation fails.enableMulticast(String)
,
sendMulticast(String, Object, boolean)
public void sendMulticast(String name, Object value)
Sends a multicast message to the NetServer. See sendMulticast
for further
details, because this is just a convenience method implemented by the
following statement:
sendMulticast(name, value, false);
name
- the name of the multicast message.value
- the multicast object message value.sendMulticast(String, Object, boolean)
public void sendMulticast(String name, Object value, boolean encrypted)
Sends an multicast message to the NetServer. Multicast messages are
generated by application servers when particular events occur (e.g., the
price of a stock has reached a certain limit). Upon reception of this
message, the NetServer will dispatch it to all client and/or server
applications that have enabled the reception of multicast messages with
name
. The name
argument has the following format:
{HostName.}MulticastName
with an optional HostName
. If no HostName
is
specified, the NetServer Local Host name will be used. The MulticastName
is requiered and has a maximum length of 10 chars.
name
- the name of the multicast message.value
- the multicast object message value.encrypted
- if true
the message is sent encrypted.enableMulticast(String)
,
disableMulticast(String)
public String getTimestamp()
Returns an NetServer timestamp. A NetServer timestamp is a string produced by a NetServer that identifies a unique point in time. Each time a NetServer returns a timestamp, it's value is guaranteed to be different (bigger) than the previous timestamp returned. A NetServer timestamp is a string that contains 26 characters with the following format:
yyyy-MM-dd:HH:mm:ss.cccccc
NetException
- if the operation fails.public void sendConsole(String command)
command
- the console command.public void sendOperator(String command)
command
- the operator command.public void releaseHold()
sendReply
method
call with the hold
(third) argument set to true
.sendError
method is used
to report an internal error to the NetServer.public void sendError(String name, String description)
name
and description
, which are used by the
NetServer to generate an event log, and to display a message in the
NetServer Console. After this method has been called, the server
application enter a hold state, which can later be released using
the releaseHold()
method if the error situation is resolved.
For example, the server application may need to communicate with a
Database server, but may not be able to open a connection due to some
temporal situation. In this case, the server application may use the
sendError
method to report the situation, and then
enter an active hold state trying to open the requiered connection
to the Database server. Once this is done, it releases the hold
state using the releaseHold
method.
name
- the name of the error. If null
, the name "ERROR"
is used.description
- the description of the error.releaseHold()
public static Properties loadProperties(String fileName)
fileName
. If fileName
does not specify a full path, then the current working
directory of the application will be used to resolve the locatation
of the property file.fileName
- the name of the property file.NullPointerException
- if fileName
is null
or empty.NetException
- if fileName
could not be found or read.Copyright © OBCOM INGENIERIA S.A. (Chile). All Rights Reserved.