Class ServerChannel
- All Implemented Interfaces:
JschServices, MailServices, SocketServices, SQLServices
A ServerChannel can establish a secure or a non-secure communication
channel. Secure channels use the Transport Layer Security (TLS)
protocol, which ensures privacy between communicating applications. When a
server and client communicate, TLS ensures that no third party may
eavesdrop or tamper with any message.
The following example uses ServerChannel to implement a server
application called "SAMPLESER". This server is very small: it just
implements a trivial "HELLO" service:
import cl.netswitch.lib.server.*;
public class SampleServer extends ServerChannel implements RequestListener
{
@Override
public void handleRequest(RequestEvent request) throws Exception
{
String name = request.getMessage().getText();
request.sendReply("HELLO to you too, %s", name);
}
public static void main(String[] args) throws Exception
{
SampleServer server = new SampleServer();
server.addRequestListener("HELLO", server);
server.execute("SAMPLESER", "tcp://localhost:20101");
}
}
| Property | Description | Type | Default |
|---|---|---|---|
netswitch.uri |
Protocol, address and port of the NetSwitch server | String |
NETSWITCH |
netswitch.password |
Password use to authenticate the server channel | String |
none |
«name».server.compression.threshold |
Minimum size that a message must have before it is compressed (bytes) | Integer |
0 (disabled) |
«name».server.keep.alive |
Enable or disable the socket SO_KEEPALIVE option | Boolean |
false |
«name».server.reader.buffer.free |
Free size of the reader buffer (bytes) | Integer |
4096 |
«name».server.reader.buffer.max |
Maximum size of the reader buffer (bytes) | Integer |
0 (unbounded) |
«name».server.reader.buffer.min |
Minimum size of the reader buffer (bytes) | Integer |
8192 |
«name».server.reader.buffer.warn |
Warning size of the reader buffer (bytes) | Integer |
8192 |
«name».server.reply.timeout |
Maximum time to wait for a NetSwitch reply (milliseconds) | Integer |
800 |
«name».server.tcp.nodelay |
Enable or disable the socket TCP_NODELAY option | Boolean |
true |
«name».server.trace |
Trace inbound and outbound messages (for debugging) | Boolean |
false |
«name».server.trust.store |
Path of the JKS trust store file used for SSL connections | String |
none |
«name».server.use.caller.name |
Use caller name to identify execute methods | Boolean |
false |
«name».server.user.name |
Username used to login the channel with the NetSwitch server | String |
none |
«name».server.user.password |
Password used to login the channel with the NetSwitch server | String |
none |
«name».server.writer.queue.size |
Maximum size of the writer queue (messages) | Integer |
64 |
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddRequestListener(String name, RequestListener listener) Registers alistenerfor request identified byname.final voidCancels the execution of thehandleTimermethod.final voidclose()Close this channel, relinquishing any underlying resources.decodePassword(String encoded, String username, String type) Decodes an encoded password using supplied arguments.final voiddisableMulticast(String name) Disables the reception of multicast messages identified byname.final voidenableMulticast(String name, MulticastListener listener) Enables the reception of multicast messages identified byname.final voidDeprecated.final voidexecute(String name, Properties properties, ServerContext context) Starts the execution of thisServerChannel.final <T> TexecuteJsch(JschExecutor<T> executor) Allocates a connected Jsch (Java Secure Channel) session from the default pool and then executes the supplied executor.final <T> TexecuteJsch(JschExecutor<T> executor, String execName) Allocates a connected Jsch (Java Secure Channel) session from the default pool and then executes the supplied executor.final <T> TexecuteJsch(String poolName, JschExecutor<T> executor) Allocates a connected Jsch (Java Secure Channel) session from the specified pool and then executes the supplied executor.final <T> TexecuteJsch(String poolName, JschExecutor<T> executor, String execName) Allocates a connected Jsch (Java Secure Channel) session from the specified pool and then executes the supplied executor.final <T> TexecuteSocket(SocketExecutor<T> executor) Allocates a socket from the default pool and executes the supplied socket executor.final <T> TexecuteSocket(SocketExecutor<T> executor, String execName) Allocates a socket from the default pool and executes the supplied socket executor.final <T> TexecuteSocket(String poolName, SocketExecutor<T> executor) Allocates a socket from the specified pool and then executes the supplied socket executor.final <T> TexecuteSocket(String poolName, SocketExecutor<T> executor, String execName) Allocates a socket from the specified pool and then executes the supplied socket executor.final <T> TexecuteSQL(SQLExecutor<T> executor) Allocates a connection from the default pool and executes the supplied SQL executor.final <T> TexecuteSQL(SQLExecutor<T> executor, String execName) Allocates a connection from the default pool and executes the supplied SQL executor.final <T> TexecuteSQL(String poolName, SQLExecutor<T> executor) Allocates a connection from the specified pool and then executes the supplied SQL executor.final <T> TexecuteSQL(String poolName, SQLExecutor<T> executor, String execName) Allocates a connection from the specified pool and then executes the supplied SQL executor.final <T> TexecuteTask(Callable<T> task) Executes supplied task mantaining statistics.final <T> TexecuteTask(Callable<T> task, String taskName) Executes supplied task mantaining statistics with optional taskName.final String[]Returns the command arguments supplied to the main() method of thisServerChannel.final intReturns the server's idle timeout.final StringgetName()Returns the name of thisServerChannel.final StringReturns the switch name of thisServerChannel.final URIReturns the connection URI of thisServerChannel.final StringReturns the switch version of thisServerChannel.Returns an unmodifiable map with all the properties of this ServerChannel.final StringgetProperty(String name) Returns the value of the property indexed by specified name.final StringgetProperty(String name, String defval) Returns the value of the property indexed by specified name.final SharedBooleangetSharedBoolean(String name, boolean inival) Returns the SharedBoolean indexed by specified name.final SharedIntegergetSharedInteger(String name, int inival) Returns the SharedInteger indexed by specified name.final SharedLonggetSharedLong(String name, long inival) Returns the SharedLong indexed by specified name.final SharedStringgetSharedString(String name, String inival) Returns the SharedString indexed by specified name.final intReturns the maximum time to wait for aRunStartreply.final StringReturns the unique name of thisServerChannel.final StringReturns the implementation version of thisServerChannel.protected voidCalled when a idle event occurs.protected voidhandleInbound(Message inbound) Handles an inbound message received by this connector.protected voidCalled just after this channel connects to the switch server.protected voidCalled just after a consoleREINITcommand is executed.protected voidhandleStop(String reason) Called when a stop message is received.protected voidCalled when a timer event occurs.final booleanReturnstrueif thisServerChannelis executing.final booleanReturnstrueif running on theServerChannelThread.protected voidlogRequestError(RequestEvent request, Throwable thrown) Logs the error that was thrown while processing a request message.final voidremoveRequestListener(String name) Unregisters the request listener identified byname.protected voidreplyCompleted(ReplyEvent reply) Called after an asynchronous reply message has been successfully processed by ahandleReplymethod.protected voidreplyError(ReplyEvent reply, Throwable thrown) Called after an exception is thrown while processing an asynchronous reply message.protected voidreplyReceived(ReplyEvent reply) Called after an asynchronous reply message has been received and before it is processed by ahandleReplymethod.protected voidrequestCompleted(RequestEvent request) Called after a request message has been successfully processed by ahandleRequestmethod.protected voidrequestError(RequestEvent request, Throwable thrown) Called after an exception is thrown while processing a request message.protected voidrequestReceived(RequestEvent request) Called after a request message has been received and before it is processed by ahandleRequestmethod.final <T> voidrunAsyncTask(Callable<T> task, TaskResultListener<T> listener) Executes the suppliedtaskin a separate thread.final voidRun supplied runnable on the server's thread at some time in the future.voidSends a mail message using the "default" SMTP mail session.voidSends a mail message using the specified SMTP mail session.final voidsendMessage(Message message) Sends the supplied message to the output stream of a channel.final voidsendMessage(String destination, Serializable data) Sends a message to the specifieddestination.final voidsendMulticast(String name, Serializable data) Sends an multicast message built using the suppliednameanddata.final MessagesendRequest(String destination, Serializable data) Sends a request message to adestinationand then blocks forever waiting for the reply.final MessagesendRequest(String destination, Serializable data, int timeout) Sends a request message to adestinationand then blocks waiting for the reply untiltimeout.final voidsendRequest(String destination, Serializable data, ReplyListener listener) Sends a request message to adestinationand then callslistenerwhen the asynchronous reply is received.final voidsendRequest(String destination, Serializable data, ReplyListener listener, int timeout) Sends a request message to adestinationand then callslistenerwhen the asynchronous reply is received.final voidsendRequest(String destination, Serializable data, ReplyListener listener, int timeout, String replyKey) Sends a request message to adestinationand then callslistenerwhen the asynchronous reply is received.final voidsetIdleTimeout(int timeout) Changes the server's idle timeout.final voidsetSwitchReplyTimeout(int timeout) Changes the maximum time to wait for aRunStartreply.final voidstartTimer(int period) Schedules the execution of thehandleTimermethod at regular intervals.final voidstop()Stops the execution of thisServerChannel.final voidStops the execution of thisServerChannelwith a reason.Methods inherited from class ChannelBase
connect, fine, getCompressionThreshold, getLocalAddress, getLogger, getLoggerHeader, getReaderBufferFreeSize, getReaderBufferMaxSize, getReaderBufferMinSize, getReaderBufferWarnSize, getReaderBytes, getReaderMessages, getRemoteAddress, getSoKeepAlive, getSslHandshakeTimeout, getTag, getTcpNoDelay, getTrustStoreFile, getWriterBytes, getWriterMessages, getWriterQueueSize, info, isClosed, isConnected, isLoggable, isSecure, isTracing, setCompressionThreshold, setLogger, setLoggerHeader, setReaderBufferFreeSize, setReaderBufferMaxSize, setReaderBufferMinSize, setReaderBufferWarnSize, setSoKeepAlive, setSslHandshakeTimeout, setTcpNoDelay, setTracing, setTrustStoreFile, setWriterQueueSize, severe, severe, warning, writeMessage, writeMessage
-
Constructor Details
-
ServerChannel
public ServerChannel()Constructs a newServerChannelinstance.
-
-
Method Details
-
getArguments
Returns the command arguments supplied to the main() method of thisServerChannel. Returnsnullif thisServerChannelis not executing, or if it was executed with no command arguments.- Returns:
- the command arguments or
nullif none available.
-
getName
Returns the name of thisServerChannel. Returnsnullif thisServerChannelis not executing.- Returns:
- the name or
nullif not executing.
-
getNetSwitchURI
Returns the connection URI of thisServerChannel. Returnsnullif thisServerChannelis not executing.- Returns:
- the connection URI or
nullif not executing.
-
getNetSwitchName
Returns the switch name of thisServerChannel. This value is assigned to this server by the switch server. Returnsnullif thisServerChannelis not executing.- Returns:
- the name or
nullif not executing.
-
getNetSwitchVersion
Returns the switch version of thisServerChannel. This value is assigned to this server by the switch server. Returnsnullif thisServerChannelis not executing.- Returns:
- the version or
nullif not executing.
-
getUniqueName
Returns the unique name of thisServerChannel. This value is assigned to this server by the switch server. Returnsnullif thisServerChannelis not executing.- Returns:
- the name or
nullif not executing.
-
isExecuting
public final boolean isExecuting()Returnstrueif thisServerChannelis executing.- Returns:
trueif thisServerChannelis executing.
-
isServerThread
public final boolean isServerThread()Returnstrueif running on theServerChannelThread.- Returns:
trueif running on theServerChannelThread.
-
getVersion
Returns the implementation version of thisServerChannel.- Returns:
- the implementation version of this
ServerChannel.
-
handleInbound
Handles an inbound message received by this connector.- Specified by:
handleInboundin classChannelBase- Parameters:
inbound- the inbound message to be handled.- Throws:
NullPointerException- ifinboundisnull.Exception- if another error occurs.
-
decodePassword
Decodes an encoded password using supplied arguments.- Parameters:
encoded- the password to be decoded.username- the username used to encoded the password.type- the type used to encoded the password.- Returns:
- the password decoded using supplied arguments.
- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
getProperty
Returns the value of the property indexed by specified name. If the property is not defined, it returns the supplied default value.- Parameters:
name- the name of the required property.defval- default value returned if the property is not defined.- Returns:
- the value of the property or default value
defval. - Throws:
NullPointerException- ifnameisnull.
-
getProperty
Returns the value of the property indexed by specified name. If the property is not defined, it returnsnull.- Parameters:
name- the name of the required property.- Returns:
- the value of the property or
nullif not defined. - Throws:
NullPointerException- ifnameisnull.
-
getProperties
-
runAsyncTask
Executes the suppliedtaskin a separate thread. It calls thelistenerwhen the task returns the computed value, or when the task throws an exception.- Type Parameters:
T- the type of the value returned by thetask.- Parameters:
task- the task to be executed in a separate thread.listener- called when the task returns a value or throws an exception.- Throws:
NullPointerException- if an argument isnull.IllegalStateException- if the server channel is not executing.
-
executeSQL
Allocates a connection from the default pool and executes the supplied SQL executor.This convenience method produces the same result as the following invocation:
executeSQL("default", executor, null);- Specified by:
executeSQLin interfaceSQLServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
executor- an SQL statement executor.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- ifexecutorisnull.SQLException- if an SQL error occurs.Exception- if another error occurs.
-
executeSQL
public final <T> T executeSQL(SQLExecutor<T> executor, String execName) throws SQLException, Exception Allocates a connection from the default pool and executes the supplied SQL executor.This convenience method produces the same result as the following invocation:
executeSQL("default", executor, tag);- Specified by:
executeSQLin interfaceSQLServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
executor- an SQL statement executor.execName- the name of theexecutor(can be null).- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- ifexecutorisnull.SQLException- if an SQL error occurs.Exception- if another error occurs.
-
executeSQL
public final <T> T executeSQL(String poolName, SQLExecutor<T> executor) throws SQLException, Exception Allocates a connection from the specified pool and then executes the supplied SQL executor.This convenience method produces the same result as the following invocation:
executeSQL(poolName, executor, null);- Specified by:
executeSQLin interfaceSQLServices- Type Parameters:
T- the type of the execution result.- Parameters:
poolName- the name of the connection pool.executor- an SQL statement executor.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.SQLException- if an SQL error occurs.Exception- if another error occurs.
-
executeSQL
public final <T> T executeSQL(String poolName, SQLExecutor<T> executor, String execName) throws SQLException, Exception Allocates a connection from the specified pool and then executes the supplied SQL executor. If the SQL executor returns normally, the connection is committed. If the SQL executor throws an exception, the connection is rollback. In any event, the connection is returned to the pool.- Specified by:
executeSQLin interfaceSQLServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
poolName- the name of the connection pool.executor- an SQL statement executor.execName- the name of theexecutor(can be null).- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.SQLException- if an SQL error occurs.Exception- if another error occurs.
-
executeJsch
Allocates a connected Jsch (Java Secure Channel) session from the default pool and then executes the supplied executor.This convenience method produces the same result as the following invocation:
executeJsch("default", executor, null);- Specified by:
executeJschin interfaceJschServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
executor- the Jsch executor to be executed.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- ifexecutorisnull.Exception- if another error occurs.
-
executeJsch
Allocates a connected Jsch (Java Secure Channel) session from the default pool and then executes the supplied executor.This convenience method produces the same result as the following invocation:
executeJsch("default", executor, tag);- Specified by:
executeJschin interfaceJschServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
executor- the Jsch executor to be executed.execName- the name of theexecutor(can be null).- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- ifexecutorisnull.Exception- if another error occurs.
-
executeJsch
Allocates a connected Jsch (Java Secure Channel) session from the specified pool and then executes the supplied executor.This convenience method produces the same result as the following invocation:
executeJsch(poolName, executor, null);- Specified by:
executeJschin interfaceJschServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
poolName- the name of the Jsch (Java Secure Channel) pool.executor- the Jsch executor to be executed.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
executeJsch
public final <T> T executeJsch(String poolName, JschExecutor<T> executor, String execName) throws Exception Allocates a connected Jsch (Java Secure Channel) session from the specified pool and then executes the supplied executor. If the Jsch executor throws an exception, the Jsch session is closed and not returned to the pool.- Specified by:
executeJschin interfaceJschServices- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
poolName- the name of the Jsch (Java Secure Channel) pool.executor- the Jsch executor to be executed.execName- the name of theexecutor(can be null).- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
executeSocket
Allocates a socket from the default pool and executes the supplied socket executor.This convenience method produces the same result as the following invocation:
executeSocket("default", executor, null);- Specified by:
executeSocketin interfaceSocketServices- Type Parameters:
T- the type of the execution result.- Parameters:
executor- the socket executor to be executed.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- ifexecutorisnull.IOException- if an I/O error occurs.Exception- if another error occurs.
-
executeSocket
public final <T> T executeSocket(SocketExecutor<T> executor, String execName) throws IOException, Exception Allocates a socket from the default pool and executes the supplied socket executor.This convenience method produces the same result as the following invocation:
executeSocket("default", executor, tag);- Specified by:
executeSocketin interfaceSocketServices- Type Parameters:
T- the type of the execution result.- Parameters:
executor- the socket executor to be executed.execName- the name of theexecutor(can be null).- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- ifexecutorisnull.IOException- if an I/O error occurs.Exception- if another error occurs.
-
executeSocket
public final <T> T executeSocket(String poolName, SocketExecutor<T> executor) throws IOException, Exception Allocates a socket from the specified pool and then executes the supplied socket executor.This convenience method produces the same result as the following invocation:
executeSocket(poolName, executor, null);- Specified by:
executeSocketin interfaceSocketServices- Type Parameters:
T- the type of the execution result.- Parameters:
poolName- the name of the socket pool.executor- the socket executor to be executed.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.IOException- if an I/O error occurs.Exception- if another error occurs.
-
executeSocket
public final <T> T executeSocket(String poolName, SocketExecutor<T> executor, String execName) throws IOException, Exception Allocates a socket from the specified pool and then executes the supplied socket executor. If the socket executor throws anIOException, the socket is closed and not returned to the pool. If the socket executor terminates successfully, or if it throws any other exception, the socket is returned to the pool.- Specified by:
executeSocketin interfaceSocketServices- Type Parameters:
T- the type of the execution result.- Parameters:
poolName- the name of the socket pool.executor- the socket executor to be executed.execName- the name of theexecutor(can be null).- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.IOException- if an I/O error occurs.Exception- if another error occurs.
-
executeTask
Executes supplied task mantaining statistics.This convenience method produces the same result as the following invocation:
executeTask(task, null);- Type Parameters:
T- the type of the value returned by thetask.- Parameters:
task- the task callable to be executed.- Returns:
- the value returned by the
task. - Throws:
NullPointerException- iftaskisnull.Exception- if an error occurs executingtask.
-
executeTask
Executes supplied task mantaining statistics with optional taskName.- Type Parameters:
T- the type of the value returned by thetask.- Parameters:
task- the task callable to be executed.taskName- the name of thetask(can be null).- Returns:
- the value returned by the
task. - Throws:
NullPointerException- iftaskisnull.Exception- if an error occurs executingtask.
-
sendMail
Sends a mail message using the "default" SMTP mail session.This convenience method produces the same result as the following invocation:
sendMail("default", subject, text);- Specified by:
sendMailin interfaceMailServices- Parameters:
subject- the subject of the mail message.text- the text of the mail message.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
sendMail
Sends a mail message using the specified SMTP mail session.- Specified by:
sendMailin interfaceMailServices- Parameters:
sessionName- the name of the mail session.subject- the subject of the mail message.text- the text of the mail message.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
enableMulticast
Enables the reception of multicast messages identified byname. When a multicast message arrives, it will be dispatched calling thelistener.handleMulticastmethod.- Parameters:
name- name of the multicast messages.listener- the listener of multicast messages.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
disableMulticast
Disables the reception of multicast messages identified byname. Ifnamehas the special value"*", then this method disables the reception of all multicast messages that have been enabled using theenableMulticastmethod.- Parameters:
name- name of the multicast messages or"*".- Throws:
NullPointerException- ifnameisnull.Exception- if another error occurs.
-
sendMulticast
Sends an multicast message built using the suppliednameanddata. The message will be dispatched to all client and/or server applications that have enabled the reception of multicast messages with the specifiedname.- Parameters:
name- the name of the multicast message.data- data to include in the multicast message (can be null).- Throws:
NullPointerException- ifnameisnull.Exception- if another error occurs.
-
sendRequest
public final void sendRequest(String destination, Serializable data, ReplyListener listener) throws Exception Sends a request message to adestinationand then callslistenerwhen the asynchronous reply is received. This method waits forever for the reply.This convenience method produces the same result as the following invocation:
sendRequest(destination, data, listener, 0);- Parameters:
destination- the destination of the request message.data- the data to include in the request message (can be null).listener- listener called with the asynchronous reply message.- Throws:
NullPointerException- if a required argument isnull.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
sendRequest
public final void sendRequest(String destination, Serializable data, ReplyListener listener, int timeout) throws Exception Sends a request message to adestinationand then callslistenerwhen the asynchronous reply is received. Argumenttimeoutspecifies the amount of time to wait for the asynchronous reply message.This convenience method produces the same result as the following invocation:
sendRequest(destination, data, listener, timeout, null);- Parameters:
destination- the destination of the request message.data- the data to include in the request message (can be null).listener- listener called with the asynchronous reply message.timeout- the maximum time to wait for the reply (milliseconds).- Throws:
NullPointerException- if a required argument isnull.IllegalArgumentException- iftimeoutis negative.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
sendRequest
public final void sendRequest(String destination, Serializable data, ReplyListener listener, int timeout, String replyKey) throws Exception Sends a request message to adestinationand then callslistenerwhen the asynchronous reply is received.Argument
destinationmust have the following format:[SwitchName:]ServerName[.ServiceName]
where optional items are shown within"["and"]"brackets, and the characters":"and"."stand for themselves. If the optionalSwitchNameis not specified, the message is sent to the connected switch.ServerNameis the name of a server, a listener or a connector. The optionalServiceNameis the name of a service provided by the server, or the name of a channel of a listener. The following are examples of valid destinations:POS_DEVICE SWITCH.LOG_ERROR HUB:IMSER.ADD_CONTACT
Argumenttimeoutspecifies the amount of time to wait for the asynchronous reply message. Iftimeoutexpires while waiting for the reply, thelisteneris called with anullmessage, indicating a timeout event. Iftimeoutis zero (0), the listener may never get called.Optional argument
replyKeyprovides a globally unique identifier of the reply. When the reply is later received by some other channel, thisreplyKeymust be provided todispatchReplyto dispatch the reply to thelistener.- Parameters:
destination- the destination of the request message.data- the data to include in the request message (can be null).listener- listener called with the asynchronous reply message.timeout- the maximum time to wait for the reply (milliseconds).replyKey- a globally unique ID of the reply (can be null).- Throws:
NullPointerException- if a required argument isnull.IllegalArgumentException- iftimeoutis negative.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
sendRequest
Sends a request message to adestinationand then blocks forever waiting for the reply.This convenience method produces the same result as the following invocation:
sendRequest(destination, data, 0);- Parameters:
destination- the destination of the request message.data- the data to include in the request message (can be null).- Returns:
- the reply message returned from
destination. - Throws:
NullPointerException- ifdestinationisnull.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
sendRequest
public final Message sendRequest(String destination, Serializable data, int timeout) throws SocketTimeoutException, Exception Sends a request message to adestinationand then blocks waiting for the reply untiltimeout. The value ofdestinationmust have the following format:[SwitchName:]ServerName[.ServiceName]
where optional items are shown within"["and"]"brackets, and the characters":"and"."stand for themselves. If the optionalSwitchNameis not specified, the message is sent to the connected switch.ServerNameis the name of a server, a listener or a connector. The optionalServiceNameis the name of a service provided by the server, or the name of a channel of a listener. The following are examples of valid destinations:POS_DEVICE SWITCH.LOG_ERROR HUB:IMSER.ADD_CONTACT
Argumenttimeoutspecifies the amount of time to wait for the reply message. ASocketTimeoutExceptionis thrown iftimeoutexpires while waiting for the reply. Iftimeoutis zero (0), the call blocks forever.- Parameters:
destination- the destination of the request message.data- the data to include in the request message (can be null).timeout- the maximum time to wait for a reply (in milliseconds).- Returns:
- the reply message returned from
destination. - Throws:
NullPointerException- ifdestinationisnull.IllegalArgumentException- iftimeoutis negative.SocketTimeoutException- iftimeoutexpired while waiting for reply.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
sendMessage
Sends a message to the specifieddestination. The value ofdestinationmust have the following format:[SwitchName:]ServerName[.ServiceName]
where optional items are shown within"["and"]"brackets, and the characters":"and"."stand for themselves. If the optionalSwitchNameis not specified, the message is sent to the connected switch.ServerNameis the name of a server, a listener or a connector. The optionalServiceNameis the name of a service provided by the server, or the name of a channel of a listener. The following are examples of valid destinations:POS_DEVICE SWITCH.LOG_ERROR HUB:IMSER.ADD_CONTACT
- Parameters:
destination- the destination of the request message.data- the data to include in the message (can be null).- Throws:
NullPointerException- ifdestinationisnull.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
sendMessage
Sends the supplied message to the output stream of a channel.- Parameters:
message- the message to be written to the stream.- Throws:
NullPointerException- ifmessageisnull.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
addRequestListener
Registers alistenerfor request identified byname. If a listener fornamewas already registered, its definition will be replaced by this new one. ThehandleRequestmethod of thislistenerwill be called whenever a request identified bynamearrives.- Parameters:
name- the name of the request to register.listener- the listener of request messages.- Throws:
NullPointerException- if an argument isnull.
-
removeRequestListener
Unregisters the request listener identified byname. If no such listener exists, then nothing happens. If a request identified bynamelater arrives, an error reply will be sent to the service caller.- Parameters:
name- the name of the request to unregister.- Throws:
NullPointerException- ifnameisnull.
-
handleInitialize
Called just after this channel connects to the switch server. This event occurs only once in the life cycle of a server channel.This method is meant to be overridden by classes that extend
ServerChannel. This default implementation does nothing.- Throws:
Exception- if an error occurs.
-
handleReinitialize
Called just after a consoleREINITcommand is executed. This event may occur several times in the life cycle of a server channel.Before this method is called, the properties of this server channel are cleared and then reloaded from the properties file, if that file still exists and is readable.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation does nothing.- Throws:
Exception- if an error occurs.
-
requestReceived
Called after a request message has been received and before it is processed by ahandleRequestmethod.This method should execute initialization logic common to all requests, such as starting a database transaction.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation does nothing.- Parameters:
request- describes the request event.- Throws:
NullPointerException- ifrequestisnull.Exception- if another error occurs.- See Also:
-
requestCompleted
Called after a request message has been successfully processed by ahandleRequestmethod.This method should execute termination logic common to all successful requests, such performing a database commit.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation does nothing.- Parameters:
request- describes the request event.- Throws:
NullPointerException- ifrequestisnull.Exception- if another error occurs.- See Also:
-
requestError
Called after an exception is thrown while processing a request message. The exception could have been be thrown by eitherrequestReceived,handleRequestorrequestCompleted.This method should execute termination logic common to all failed requests, such as performing a database rollback.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation uses thesendErrormethod to send a reply message containing the message of the throwable.- Parameters:
request- describes the request event.thrown- the error thrown during request processing.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.- See Also:
-
logRequestError
Logs the error that was thrown while processing a request message. The exception could have been be thrown by eitherrequestReceived,handleRequestorrequestCompleted.This method should log the information of the supplied throwable. The log record usually includes the message and stack trace of the throwable, but the server is free to choose the format and/or contents to be logged.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation logs the message and stack trace of the supplied throwable, unless the throwable is an instance ofServerException, in which case it uses a compact format that includes only the message but not the stack trace.- Parameters:
request- describes the request event.thrown- the error thrown during request processing.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.- See Also:
-
replyReceived
Called after an asynchronous reply message has been received and before it is processed by ahandleReplymethod.This method should execute initialization logic common to all replies, such as starting a database transaction.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation does nothing.- Parameters:
reply- describes the reply event.- Throws:
NullPointerException- ifreplyisnull.Exception- if another error occurs.- See Also:
-
replyCompleted
Called after an asynchronous reply message has been successfully processed by ahandleReplymethod.This method should execute termination logic common to all successful replies, such performing a database commit.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation does nothing.- Parameters:
reply- describes the reply event.- Throws:
NullPointerException- ifreplyisnull.Exception- if another error occurs.- See Also:
-
replyError
Called after an exception is thrown while processing an asynchronous reply message. The exception could have been be thrown by eitherreplyReceived,handleReplyorreplyCompleted.This method should execute termination logic common to all failed replies, such as performing a database rollback.
This method is meant to be overridden by classes that extend
ServerChannel. This default implementation calls therequestErrormethod with therequestof the reply event and the supplied throwable.- Parameters:
reply- describes the reply event.thrown- the error thrown during reply processing.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.- See Also:
-
runLater
Run supplied runnable on the server's thread at some time in the future. If this method is called from the server's thread, the runnable will still be queued for execution after all pending server events have been processed.- Parameters:
runnable- a runnable to be run later on the server's thread.- Throws:
NullPointerException- ifrunnableisnull.
-
startTimer
public final void startTimer(int period) Schedules the execution of thehandleTimermethod at regular intervals. If the suppliedperiodis zero (0), the current timer (if any) is cancelled.- Parameters:
period- time between successive executions of thehandleTimermethod (milliseconds).- Throws:
IllegalArgumentException- ifperiodis negative.IllegalStateException- if the server channel is not executing.
-
cancelTimer
public final void cancelTimer()Cancels the execution of thehandleTimermethod. If the method is running when this call occurs, the method will run to completion, but will never run again until a call to thestartTimeris executed. -
handleTimer
Called when a timer event occurs. A timer event occurs when the sever's timer interval period expires. This interval period is defined using thestartTimermethod.This method is meant to be overridden by classes that extend
ServerChannel. This default implementation callscancelTimerto stop the generation of timer events.- Throws:
Exception- if an error occurs.
-
getIdleTimeout
public final int getIdleTimeout()Returns the server's idle timeout. If the value returned is zero (0), the server blocks forever waiting for events. If the value returned is positive, the server will call the methodhandleIdleeverytime the idle timeout expires while waiting for an event.- Returns:
- the server's idle timeout (milliseconds).
-
setIdleTimeout
public final void setIdleTimeout(int timeout) Changes the server's idle timeout. If the value oftimeoutis zero (0), the server will block forever waiting for the next event. If the value oftimeoutis positive, the server will call the methodhandleIdleeverytime the timeout expires while waiting for an event.- Parameters:
timeout- maximum time to wait for an event (milliseconds).- Throws:
IllegalArgumentException- iftimeoutis negative.
-
handleIdle
Called when a idle event occurs. An idle event occurs when the sever's timeout expires. The server's timeout is defined using thesetIdleTimeoutmethod.This method is meant to be overridden by classes that extend
ServerChannel. This default implementation callssetIdleTimeout(0)to stop the generation of idle events.- Throws:
Exception- if an error occurs.
-
stop
public final void stop()Stops the execution of thisServerChannel. The communication channel is closed, and all resources are released. If thisServerChannelis not executing, this method does nothing.This convenience method produces the same result as the following invocation:
stop("Method stop called"); -
stop
Stops the execution of thisServerChannelwith a reason. The communication channel is closed, and all resources are released. If thisServerChannelis not executing, this method does nothing.- Parameters:
reason- the reason why the server channel is stopping (can be null).
-
handleStop
Called when a stop message is received. A stop message is sent just before the communication channel is closed. After processing this message, theexecutemethod 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 overridden by classes that extend
ServerChannel. This default implementation does nothing.- Parameters:
reason- describes the reason why the server is being stopped.- Throws:
NullPointerException- ifreasonisnull.Exception- if another error occurs.
-
getSwitchReplyTimeout
public final int getSwitchReplyTimeout()Returns the maximum time to wait for aRunStartreply. If the value returned is zero (0), this server blocks forever waiting for the reply.- Returns:
- the RunStart reply timeout (milliseconds).
-
setSwitchReplyTimeout
public final void setSwitchReplyTimeout(int timeout) Changes the maximum time to wait for aRunStartreply. If the value oftimeoutis zero (0), this server will block forever waiting for the reply.- Parameters:
timeout- maximum time to wait for a RunStart reply (milliseconds).- Throws:
IllegalArgumentException- iftimeoutis negative.
-
execute
public final void execute(String name, Properties properties, ServerContext context) throws Exception Starts the execution of thisServerChannel. The specified channelnamemust be registered with the switch. Argumentpropertiesprovides the connection and configuration parameters of the server channel.After validating the arguments, this method connects to the switch server and sends a registration message with the name and credentials of this server. It then waits for messages to arrive and dispatches them to the corresponding "
handleEvent" methods.This method returns to its caller when the
ServerChannelhas been stopped, or when thestopmethod is called, or when an unrecoverable error occurs. To remotely stop this server, an administrator needs to issue the "stop" command using the Console.- Parameters:
name- the name of this server channel.properties- the properties of this server channel.context- the server context of this server channel.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
execute
Deprecated.Use methodexecute(String, Properties, ServerContext).Starts the execution of thisServerChannel. Argumentargsis an array with command line arguments. ArgumentdefaultNameprovides the default name of the server.IMPORTANT: This method is no longer implemented, and throws an exception if invoked. It's kept because some servers still reference it, but never invoke it.
- Parameters:
args- array with command line arguments.defaultName- the default name of the server.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
close
public final void close()Close this channel, relinquishing any underlying resources.- Overrides:
closein classChannelBase
-
execute(String, Properties, ServerContext).