Class Server<CallMessage,V,CastMessage>
- java.lang.Object
-
- co.paralleluniverse.actors.ActorRef<Message>
-
- co.paralleluniverse.actors.ActorRefDelegate<java.lang.Object>
-
- co.paralleluniverse.actors.behaviors.Behavior
-
- co.paralleluniverse.actors.behaviors.Server<CallMessage,V,CastMessage>
-
- All Implemented Interfaces:
Port<java.lang.Object>
,PortAutoCloseable
,SendPort<java.lang.Object>
,java.io.Serializable
,java.lang.AutoCloseable
public class Server<CallMessage,V,CastMessage> extends Behavior
An interface to aServerActor
.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description V
call(CallMessage m)
Sends a synchronous request to the actor, and awaits a response.V
call(CallMessage m, long timeout, java.util.concurrent.TimeUnit unit)
Sends a synchronous request to the actor, and awaits a response, but no longer than the given timeout.V
call(CallMessage m, Timeout timeout)
Sends a synchronous request to the actor, and awaits a response, but no longer than the given timeout.void
cast(CastMessage m)
Sends an asynchronous request to the actor and returns immediately (may block until there's room available in the actor's mailbox).void
setDefaultTimeout(long timeout, java.util.concurrent.TimeUnit unit)
Sets a default timeout for non-timedcall
s on this server reference.java.lang.String
toString()
-
Methods inherited from class co.paralleluniverse.actors.ActorRefDelegate
getImpl, isInActor
-
Methods inherited from class co.paralleluniverse.actors.ActorRef
close, close, equals, getName, hashCode, interrupt, send, send, send, sendSync, trySend
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface co.paralleluniverse.strands.channels.PortAutoCloseable
isClosed
-
-
-
-
Constructor Detail
-
Server
public Server(ActorRef<java.lang.Object> actor)
Ifactor
is known to be aServerActor
, creates a newServer
interface to it. Normally, you don't use this constructor, but theServer
instance returned byServerActor.spawn()
.- Parameters:
actor
- aServerActor
-
-
Method Detail
-
setDefaultTimeout
public void setDefaultTimeout(long timeout, java.util.concurrent.TimeUnit unit)
Sets a default timeout for non-timedcall
s on this server reference. Non-timed calls that take longer than the default timeout, will throw aTimeoutException
wrapped in aRuntimeException
. Timed calls (those that take a timeout parameter) will not be affected.This method only affects calls made through this particular server actor reference and not calls to the same server actor through other references.
This method has nothing to do with
ServerActor.setTimeout
- Parameters:
timeout
- the timeout durationunit
- the time unit of the timeout, ornull
to unset.
-
call
public final V call(CallMessage m) throws java.lang.InterruptedException, SuspendExecution
Sends a synchronous request to the actor, and awaits a response. This method will wait indefinitely for the actor to respond unless a default timeout has been set for this server reference withsetDefaultTimeout
.This method may be safely called by actors and non-actor strands alike.
- Parameters:
m
- the request- Returns:
- the value sent as a response from the actor
- Throws:
java.lang.RuntimeException
- if the actor encountered an error while processing the requestjava.lang.InterruptedException
SuspendExecution
-
call
public final V call(CallMessage m, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException, SuspendExecution
Sends a synchronous request to the actor, and awaits a response, but no longer than the given timeout.This method may be safely called by actors and non-actor strands alike.
- Parameters:
m
- the requesttimeout
- the maximum duration to wait for a response.unit
- the time unit of the timeout- Returns:
- the value sent as a response from the actor
- Throws:
java.lang.RuntimeException
- if the actor encountered an error while processing the requestjava.util.concurrent.TimeoutException
- if the timeout expires before a response has been received.java.lang.InterruptedException
SuspendExecution
-
call
public final V call(CallMessage m, Timeout timeout) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException, SuspendExecution
Sends a synchronous request to the actor, and awaits a response, but no longer than the given timeout.This method may be safely called by actors and non-actor strands alike.
- Parameters:
m
- the requesttimeout
- the method will not block for longer than the amount remaining in theTimeout
- Returns:
- the value sent as a response from the actor
- Throws:
java.lang.RuntimeException
- if the actor encountered an error while processing the requestjava.util.concurrent.TimeoutException
- if the timeout expires before a response has been received.java.lang.InterruptedException
SuspendExecution
-
cast
public final void cast(CastMessage m) throws SuspendExecution
Sends an asynchronous request to the actor and returns immediately (may block until there's room available in the actor's mailbox).- Parameters:
m
- the request- Throws:
SuspendExecution
-
-