Class AbstractServerHandler<CallMessage,V,CastMessage>
- java.lang.Object
-
- co.paralleluniverse.actors.behaviors.AbstractServerHandler<CallMessage,V,CastMessage>
-
- All Implemented Interfaces:
Initializer
,ServerHandler<CallMessage,V,CastMessage>
public class AbstractServerHandler<CallMessage,V,CastMessage> extends java.lang.Object implements ServerHandler<CallMessage,V,CastMessage>
A convenience class implementing theServerHandler
interface. All methods do nothing, except forhandleCall
which throws anUnsupportedOperationException
.
-
-
Constructor Summary
Constructors Constructor Description AbstractServerHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description V
handleCall(ActorRef<?> from, java.lang.Object id, CallMessage m)
Called to handle a synchronous request (one waiting for a response).void
handleCast(ActorRef<?> from, java.lang.Object id, CastMessage m)
Called to handle an asynchronous request (one that does not for a response).void
handleInfo(java.lang.Object m)
void
handleTimeout()
Called whenever the timeout set withsetTimeout
or supplied at construction expires without any message received.void
init()
void
terminate(java.lang.Throwable cause)
-
-
-
Method Detail
-
init
public void init() throws SuspendExecution
This implementation does nothing
- Specified by:
init
in interfaceInitializer
- Throws:
SuspendExecution
-
handleCall
public V handleCall(ActorRef<?> from, java.lang.Object id, CallMessage m) throws SuspendExecution
Called to handle a synchronous request (one waiting for a response).- If this method returns a non-null value, it will be sent back to the sender of the request wrapped by an
ErrorResponseMessage
; if the request was sent viaServer.call
(which is how it's usually done), this value will be returned by thecall
method. - If this method throws an exception, it will be sent back to the sender of the request wrapped by an
ErrorResponseMessage
; if the request was sent viaServer.call
, the exception will be thrown by thecall
method, possibly wrapped in aRuntimeException
. - If this method returns
null
, then a reply is not immediately sent, and thecall
method will remain blocked until a reply is sent manually withreply
orreplyError
.
This implementation throws an
UnsupportedOperationException
.- Specified by:
handleCall
in interfaceServerHandler<CallMessage,V,CastMessage>
- Parameters:
from
- the sender of the requestid
- the request's unique idm
- the request- Returns:
- a value that will be sent as a response to the sender of the request.
- Throws:
SuspendExecution
- If this method returns a non-null value, it will be sent back to the sender of the request wrapped by an
-
handleCast
public void handleCast(ActorRef<?> from, java.lang.Object id, CastMessage m) throws SuspendExecution
Called to handle an asynchronous request (one that does not for a response).This implementation does nothing
- Specified by:
handleCast
in interfaceServerHandler<CallMessage,V,CastMessage>
- Parameters:
from
- the sender of the requestid
- the request's unique idm
- the request- Throws:
SuspendExecution
-
handleInfo
public void handleInfo(java.lang.Object m) throws SuspendExecution
Called to handle any message sent to this actor that is neither acall
nor acast
.This implementation does nothing
- Specified by:
handleInfo
in interfaceServerHandler<CallMessage,V,CastMessage>
- Parameters:
m
- the message- Throws:
SuspendExecution
-
handleTimeout
public void handleTimeout() throws SuspendExecution
Called whenever the timeout set withsetTimeout
or supplied at construction expires without any message received. The countdown is reset after every received message. This method will be triggered multiple times if a message is not received for a period of time longer than multiple timeout durations.This implementation does nothing
- Specified by:
handleTimeout
in interfaceServerHandler<CallMessage,V,CastMessage>
- Throws:
SuspendExecution
-
terminate
public void terminate(java.lang.Throwable cause) throws SuspendExecution
This implementation does nothing
- Specified by:
terminate
in interfaceInitializer
- Throws:
SuspendExecution
-
-