- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
Fields inherited from class java.util.EventObject
source
-
Constructor Summary
ConstructorDescriptionRequestEvent
(ServerChannel channel, Message message) Constructs a newRequestEvent
instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
dispatchReply
(String replyKey, Serializable data) Dispatches supplied reply data to the pending reply listener indexed by given key.void
Logs a fine message with supplied format and arguments.Returns the authentication type (BASIC,DIGEST) ornull
.Returns the name of the authenticated user ornull
.Returns the destination of this RequestEvent.Returns the request error listener of this RequestEvent.Returns the request message of this RequestEvent.<T extends Serializable>
TReturns the object contained in the message of this RequestEvent.Returns the reply path of this RequestEvent.Returns the request ID of this RequestEvent.Returns the server channel of this RequestEvent.Returns the service name of this RequestEvent.int
Returns the timeout of this RequestEvent.boolean
Returnstrue
if a reply has already been sent.void
Logs an information message with supplied format and arguments.boolean
isLoggable
(Level level) Returnstrue
if the given message level is being logged.boolean
isUserInRole
(String roleName) Returnstrue
if the authenticated user is included in a role.<T> void
runAsyncTask
(Callable<T> task, TaskResultListener<T> listener) Executes the suppliedtask
in a separate thread.void
sendErrorReply
(Serializable data) Sends aERROR
reply message built using the supplieddata
.void
sendErrorReply
(String text, Object... args) Sends anERROR
reply message built using the suppliedtext
format and optional arguments.void
sendErrorReply
(Throwable thrown) void
Marks the request as having sent a reply, and therefore will not fail with a "Reply Not Sent" expection.void
sendReply
(Serializable data) Sends aSUCCESS
reply message built using the supplieddata
.void
sendReply
(Serializable data, int status) Sends a reply message built using the supplieddata
and completionstatus
.void
Sends aSUCCESS
reply message built using the suppliedtext
format and optional arguments.sendSubRequest
(String destination, Serializable data) Sends a subrequest message to adestination
and then blocks forever waiting for the reply.sendSubRequest
(String destination, Serializable data, int timeout) Sends a subrequest message to adestination
and then blocks waiting for the reply untiltimeout
.void
sendSubRequest
(String destination, Serializable data, ReplyListener listener) Sends a subrequest message to adestination
and then callslistener
when the asynchronous reply message is received.void
sendSubRequest
(String destination, Serializable data, ReplyListener listener, int timeout) Sends a subrequest message to adestination
and then callslistener
when the asynchronous reply message is received.void
sendSubRequest
(String destination, Serializable data, ReplyListener listener, int timeout, String replyKey) Sends a subrequest message to adestination
and then callslistener
when the asynchronous reply is received.void
setErrorListener
(RequestErrorListener listener) Changes the request error listener of this RequestEvent.void
Logs a severe message with supplied format and arguments.void
Logs a severe message with supplied throwable, format and arguments.void
Logs a warning message with supplied format and arguments.Methods inherited from class java.util.EventObject
getSource, toString
-
Constructor Details
-
RequestEvent
Constructs a newRequestEvent
instance.- Parameters:
channel
- the object on which the event occurred.message
- the request message received by the channel.- Throws:
NullPointerException
- if an argument isnull
.
-
-
Method Details
-
getServerChannel
Returns the server channel of this RequestEvent.- Returns:
- the server channel of this RequestEvent.
-
getDestination
Returns the destination of this RequestEvent.- Returns:
- the destination of this RequestEvent.
-
getServiceName
Returns the service name of this RequestEvent.- Returns:
- the service name of this RequestEvent.
-
getMessage
Returns the request message of this RequestEvent.- Returns:
- the request message of this RequestEvent.
-
getReplyPath
Returns the reply path of this RequestEvent.- Returns:
- the reply path or
null
if none defined.
-
getRequestId
Returns the request ID of this RequestEvent.- Returns:
- the request ID or
null
if none defined.
-
getTimeout
public int getTimeout()Returns the timeout of this RequestEvent. The returned value is a non-negative value indicating the maximum number of milliseconds the sender of this request will wait for the reply. If the returned value is zero (0), the sender will wait forever.- Returns:
- the timeout of this RequestEvent (milliseconds).
-
getAuthType
Returns the authentication type (BASIC,DIGEST) ornull
.- Returns:
- the authentication type or
null
if not authenticated.
-
getAuthUser
Returns the name of the authenticated user ornull
.- Returns:
- the user name or
null
if not authenticated.
-
isUserInRole
Returnstrue
if the authenticated user is included in a role.- Parameters:
roleName
- the name of the role to be checked.- Returns:
true
if user included in role; otherwisefalse
.- Throws:
NullPointerException
- ifroleName
isnull
.
-
hasSentReply
public boolean hasSentReply()Returnstrue
if a reply has already been sent.- Returns:
true
if a reply has already been sent.
-
getErrorListener
Returns the request error listener of this RequestEvent.- Returns:
- the listener or
null
if none defined.
-
setErrorListener
Changes the request error listener of this RequestEvent.- Parameters:
listener
- the new request error listener (can be null).
-
runAsyncTask
Executes the suppliedtask
in a separate thread. It calls thelistener
when 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 the value or throws an exception.- Throws:
NullPointerException
- if an argument isnull
.
-
getObject
Returns the object contained in the message of this RequestEvent.Warning: to reduce memory consumption, this method returns a reference to (not a copy of) the mutable object stored in the request message. If the returned object is later modified, the request message object will be modified.
- Type Parameters:
T
- the type of the returned object.- Parameters:
type
- the class of the returned object.- Returns:
- a typed object or
null
if not defined. - Throws:
NullPointerException
- iftype
isnull
.ClassCastException
- if object is not an instance oftype
.Exception
- if the required object cannot be unmarshalled.
-
sendErrorReply
Sends anERROR
reply message built using the suppliedtext
format and optional arguments. If a reply message has already been sent, this method does nothing.- Parameters:
text
- the text format used to build the reply message.args
- an array with optional format arguments.- Throws:
NullPointerException
- iftext
isnull
.IllegalFormatException
- iftext
format is invalid.Exception
- if an unexpected error occurs.
-
sendErrorReply
Sends anERROR
reply message built using themessage
of the supplied throwable. If a reply message has already been sent, this method does nothing.If the
message
of the throwable isnull
or empty, the string returned by thetoString
method will be used to build the error message.If
thrown
is an instance ofServiceException
, the error message will include theuser message
and theerror code
provided bythrown
.- Parameters:
thrown
- the throwable describing the error.- Throws:
NullPointerException
- ifthrown
isnull
.Exception
- if an unexpected error occurs.
-
sendErrorReply
Sends aERROR
reply message built using the supplieddata
. If a reply message has already been sent, this method does nothing.This convenience method produces the same result as the following invocation:
sendReply(data, Message.ERROR);
- Parameters:
data
- the data to include in the reply message (can be null).- Throws:
Exception
- if an unexpected error occurs.
-
sendReply
Sends aSUCCESS
reply message built using the suppliedtext
format and optional arguments. If a reply message has already been sent, this method does nothing.- Parameters:
text
- the text format used to build the reply message.args
- an array with optional format arguments.- Throws:
NullPointerException
- iftext
isnull
.IllegalFormatException
- iftext
format is invalid.Exception
- if an unexpected error occurs.
-
sendReply
Sends aSUCCESS
reply message built using the supplieddata
. If a reply message has already been sent, this method does nothing.This convenience method produces the same result as the following invocation:
sendReply(data, Message.SUCCESS);
- Parameters:
data
- the data to include in the reply message (can be null).- Throws:
Exception
- if an unexpected error occurs.
-
sendReply
Sends a reply message built using the supplieddata
and completionstatus
. If a reply message has already been sent, this method does nothing.The completion
status
indicates whether the request terminated successfully (zero or positive status) or with error (negative status).- Parameters:
data
- the data to include in the reply message (can be null).status
- the reply completion status.- Throws:
Exception
- if an unexpected error occurs.
-
sendNullReply
Marks the request as having sent a reply, and therefore will not fail with a "Reply Not Sent" expection. If a reply message has already been sent, this method does nothing.This method is used when a request sender is not expecting a reply message, or when the reply message will be sent later by another instance of the server.
- Throws:
Exception
- if an unexpected error occurs.
-
sendSubRequest
public void sendSubRequest(String destination, Serializable data, ReplyListener listener) throws Exception Sends a subrequest message to adestination
and then callslistener
when the asynchronous reply message is received. This method waits forever for the reply.This convenience method produces the same result as the following invocation:
sendSubRequest(destination, data, listener, 0);
- Parameters:
destination
- the destination of the subrequest message.data
- the data to include in the subrequest message (can be null).listener
- listener called with the asynchronous reply message.- Throws:
NullPointerException
- if an argument isnull
.IllegalStateException
- if the server channel is not executing.Exception
- if another error occurs.
-
sendSubRequest
public void sendSubRequest(String destination, Serializable data, ReplyListener listener, int timeout) throws Exception Sends a subrequest message to adestination
and then callslistener
when the asynchronous reply message is received. Argumenttimeout
specifies the amount of time to wait for the asynchronous reply message.This convenience method produces the same result as the following invocation:
sendSubRequest(destination, data, listener, timeout, null);
- Parameters:
destination
- the destination of the subrequest message.data
- the data to include in the subrequest 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 an argument isnull
.IllegalArgumentException
- iftimeout
is negative.IllegalStateException
- if the server channel is not executing.Exception
- if another error occurs.
-
sendSubRequest
public void sendSubRequest(String destination, Serializable data, ReplyListener listener, int timeout, String replyKey) throws Exception Sends a subrequest message to adestination
and then callslistener
when the asynchronous reply is received.Argument
destination
must have the following format:[SwitchName:]ServerName[.ServiceName]
where optional items are shown within"["
and"]"
brackets, and the characters":"
and"."
stand for themselves. If the optionalSwitchName
is not specified, the message is sent to the connected switch.ServerName
is the name of a server, a listener or a connector. The optionalServiceName
is 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
Argumenttimeout
specifies the amount of time to wait for the asynchronous reply message. Iftimeout
expires while waiting for the reply, thelistener
is called with anull
message, indicating a timeout event. Iftimeout
is zero (0), the listener may never get called.Optional argument
replyKey
provides a globally unique identifier of the reply. When the reply is later received by some other channel, thisreplyKey
must be provided todispatchReply
to dispatch the reply to thelistener
.- Parameters:
destination
- the destination of the subrequest message.data
- the data to include in the subrequest 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 an argument isnull
.IllegalArgumentException
- iftimeout
is negative.IllegalStateException
- if the server channel is not executing.Exception
- if another error occurs.
-
dispatchReply
Dispatches supplied reply data to the pending reply listener indexed by given key.- Parameters:
replyKey
- the globally unique identifier of the reply message.data
- the data to include in the reply message (can be null).- Returns:
true
if the reply listener was called (not timeout).- Throws:
NullPointerException
- ifreplyKey
isnull
.Exception
- if an error occurs calling the reply listener.
-
sendSubRequest
Sends a subrequest message to adestination
and then blocks forever waiting for the reply.This convenience method produces the same result as the following invocation:
sendSubRequest(destination, data, 0);
- Parameters:
destination
- the destination of the subrequest message.data
- the data to include in the subrequest message (can be null).- Returns:
- the reply message returned from
destination
. - Throws:
NullPointerException
- ifdestination
isnull
.IllegalStateException
- if the server channel is not executing.Exception
- if another error occurs.
-
sendSubRequest
public Message sendSubRequest(String destination, Serializable data, int timeout) throws SocketTimeoutException, Exception Sends a subrequest message to adestination
and then blocks waiting for the reply untiltimeout
.Argument
destination
must have the following format:[SwitchName:]ServerName[.ServiceName]
where optional items are shown within"["
and"]"
brackets, and the characters":"
and"."
stand for themselves. If the optionalSwitchName
is not specified, the message is sent to the connected switch.ServerName
is the name of a server, a listener or a connector. The optionalServiceName
is 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
Argumenttimeout
specifies the amount of time to wait for the reply message. ASocketTimeoutException
is thrown iftimeout
expires while waiting for the reply. Iftimeout
is zero (0), the call blocks forever.- Parameters:
destination
- the destination of the subrequest message.data
- the data to include in the subrequest message (can be null).timeout
- the maximum time to wait for a reply (in milliseconds).- Returns:
- the reply message returned from
destination
. - Throws:
NullPointerException
- if an argument isnull
.IllegalArgumentException
- iftimeout
is negative.SocketTimeoutException
- iftimeout
expired while waiting for reply.IllegalStateException
- if the server channel is not executing.Exception
- if another error occurs.
-
isLoggable
Returnstrue
if the given message level is being logged.- Parameters:
level
- a message logging level.- Returns:
true
if the given message level is being logged.- Throws:
NullPointerException
- iflevel
isnull
.
-
fine
Logs a fine message with supplied format and arguments.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
info
Logs an information message with supplied format and arguments.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
warning
Logs a warning message with supplied format and arguments.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
severe
Logs a severe message with supplied format and arguments.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
severe
Logs a severe message with supplied throwable, format and arguments.- Parameters:
thrown
- the associatted throwable instance.message
- the text of the message or format.args
- an array of optional format arguments.
-