Class RequestEvent
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
Fields inherited from class EventObject
source -
Constructor Summary
ConstructorsConstructorDescriptionRequestEvent(ServerChannel channel, Message message) Constructs a newRequestEventinstance. -
Method Summary
Modifier and TypeMethodDescriptionbooleandispatchReply(String replyKey, Serializable data) Dispatches supplied reply data to the pending reply listener indexed by given key.voidLogs 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.intReturns the timeout of this RequestEvent.booleanReturnstrueif a reply has already been sent.voidLogs an information message with supplied format and arguments.booleanisLoggable(Level level) Returnstrueif the given message level is being logged.booleanisUserInRole(String roleName) Returnstrueif the authenticated user is included in a role.<T> voidrunAsyncTask(Callable<T> task, TaskResultListener<T> listener) Executes the suppliedtaskin a separate thread.voidsendErrorReply(Serializable data) Sends aERRORreply message built using the supplieddata.voidsendErrorReply(String text, Object... args) Sends anERRORreply message built using the suppliedtextformat and optional arguments.voidsendErrorReply(Throwable thrown) voidMarks the request as having sent a reply, and therefore will not fail with a "Reply Not Sent" expection.voidsendReply(Serializable data) Sends aSUCCESSreply message built using the supplieddata.voidsendReply(Serializable data, int status) Sends a reply message built using the supplieddataand completionstatus.voidSends aSUCCESSreply message built using the suppliedtextformat and optional arguments.sendSubRequest(String destination, Serializable data) Sends a subrequest message to adestinationand then blocks forever waiting for the reply.sendSubRequest(String destination, Serializable data, int timeout) Sends a subrequest message to adestinationand then blocks waiting for the reply untiltimeout.voidsendSubRequest(String destination, Serializable data, ReplyListener listener) Sends a subrequest message to adestinationand then callslistenerwhen the asynchronous reply message is received.voidsendSubRequest(String destination, Serializable data, ReplyListener listener, int timeout) Sends a subrequest message to adestinationand then callslistenerwhen the asynchronous reply message is received.voidsendSubRequest(String destination, Serializable data, ReplyListener listener, int timeout, String replyKey) Sends a subrequest message to adestinationand then callslistenerwhen the asynchronous reply is received.voidsetErrorListener(RequestErrorListener listener) Changes the request error listener of this RequestEvent.voidLogs a severe message with supplied format and arguments.voidLogs a severe message with supplied throwable, format and arguments.voidLogs a warning message with supplied format and arguments.Methods inherited from class EventObject
getSource, toString
-
Constructor Details
-
RequestEvent
Constructs a newRequestEventinstance.- 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
nullif none defined.
-
getRequestId
Returns the request ID of this RequestEvent.- Returns:
- the request ID or
nullif 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
nullif not authenticated.
-
getAuthUser
Returns the name of the authenticated user ornull.- Returns:
- the user name or
nullif not authenticated.
-
isUserInRole
Returnstrueif the authenticated user is included in a role.- Parameters:
roleName- the name of the role to be checked.- Returns:
trueif user included in role; otherwisefalse.- Throws:
NullPointerException- ifroleNameisnull.
-
hasSentReply
public boolean hasSentReply()Returnstrueif a reply has already been sent.- Returns:
trueif a reply has already been sent.
-
getErrorListener
Returns the request error listener of this RequestEvent.- Returns:
- the listener or
nullif none defined.
-
setErrorListener
Changes the request error listener of this RequestEvent.- Parameters:
listener- the new request error listener (can be null).
-
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 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
nullif not defined. - Throws:
NullPointerException- iftypeisnull.ClassCastException- if object is not an instance oftype.Exception- if the required object cannot be unmarshalled.
-
sendErrorReply
Sends anERRORreply message built using the suppliedtextformat 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- iftextisnull.IllegalFormatException- iftextformat is invalid.Exception- if an unexpected error occurs.
-
sendErrorReply
Sends anERRORreply message built using themessageof the supplied throwable. If a reply message has already been sent, this method does nothing.If the
messageof the throwable isnullor empty, the string returned by thetoStringmethod will be used to build the error message.If
thrownis an instance ofServiceException, the error message will include theuser messageand theerror codeprovided bythrown.- Parameters:
thrown- the throwable describing the error.- Throws:
NullPointerException- ifthrownisnull.Exception- if an unexpected error occurs.
-
sendErrorReply
Sends aERRORreply 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 aSUCCESSreply message built using the suppliedtextformat 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- iftextisnull.IllegalFormatException- iftextformat is invalid.Exception- if an unexpected error occurs.
-
sendReply
Sends aSUCCESSreply 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 supplieddataand completionstatus. If a reply message has already been sent, this method does nothing.The completion
statusindicates 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 adestinationand then callslistenerwhen 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 adestinationand then callslistenerwhen the asynchronous reply message 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:
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- iftimeoutis 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 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 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- iftimeoutis 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:
trueif the reply listener was called (not timeout).- Throws:
NullPointerException- ifreplyKeyisnull.Exception- if an error occurs calling the reply listener.
-
sendSubRequest
Sends a subrequest message to adestinationand 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- ifdestinationisnull.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 adestinationand then blocks waiting for the reply untiltimeout.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 reply message. ASocketTimeoutExceptionis thrown iftimeoutexpires while waiting for the reply. Iftimeoutis 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- iftimeoutis negative.SocketTimeoutException- iftimeoutexpired while waiting for reply.IllegalStateException- if the server channel is not executing.Exception- if another error occurs.
-
isLoggable
Returnstrueif the given message level is being logged.- Parameters:
level- a message logging level.- Returns:
trueif the given message level is being logged.- Throws:
NullPointerException- iflevelisnull.
-
fine
-
info
-
warning
-
severe
-
severe
-