Class ProxyServerActor
- java.lang.Object
-
- co.paralleluniverse.actors.ActorImpl<Message>
-
- co.paralleluniverse.actors.Actor<java.lang.Object,java.lang.Void>
-
- co.paralleluniverse.actors.behaviors.BehaviorActor
-
- co.paralleluniverse.actors.behaviors.ServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
-
- co.paralleluniverse.actors.behaviors.ProxyServerActor
-
- All Implemented Interfaces:
ActorBuilder<java.lang.Object,java.lang.Void>
,Joinable<java.lang.Void>
,Port<java.lang.Object>
,PortAutoCloseable
,ReceivePort<java.lang.Object>
,Stranded
,SuspendableCallable<java.lang.Void>
,java.io.Serializable
,java.lang.AutoCloseable
public class ProxyServerActor extends ServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
Wraps a Java object in aServerActor
that exposes the object's methods as an interface and processes them in an actor (on a dedicated strand).You can either supply a target object to any of the public constructors, or extend this class and use the subclass itself as the target, in which case use the protected constructors that don't take a
The interface(s) exposed musttarget
argument.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ProxyServerActor.Invocation
-
Nested classes/interfaces inherited from class co.paralleluniverse.actors.ActorImpl
ActorImpl.ActorLifecycleListener
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Field Summary
-
Fields inherited from class co.paralleluniverse.actors.behaviors.ServerActor
NULL_RETURN_VALUE
-
Fields inherited from class co.paralleluniverse.actors.ActorImpl
flightRecorder, ref
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ProxyServerActor(boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target.protected
ProxyServerActor(boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target.ProxyServerActor(boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
with the default mailbox settings, which exposes all interfaces implemented by the giventarget
.ProxyServerActor(boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
with the default mailbox settings.protected
ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target.protected
ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target.ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
, which exposes all interfaces implemented by the giventarget
.ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
protected
ProxyServerActor(java.lang.String name, boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target.protected
ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target.ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
with the default mailbox settings, which exposes all interfaces implemented by the giventarget
.ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
with the default mailbox settings.protected
ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target.protected
ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target.ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
, which exposes all interfaces implemented by the giventarget
.ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
ProxyServerActor(java.lang.String name, Strand strand, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>[] interfaces)
Creates a newProxyServerActor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkCodeSwap()
Tests whether this actor has been upgraded via hot code-swapping.protected java.lang.Object
handleCall(ActorRef<?> from, java.lang.Object id, ProxyServerActor.Invocation m)
Called to handle a synchronous request (one waiting for a response).protected void
handleCast(ActorRef<?> from, java.lang.Object id, ProxyServerActor.Invocation m)
Called to handle an asynchronous request (one that does not for a response).protected Server<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
makeRef(ActorRef<java.lang.Object> ref)
-
Methods inherited from class co.paralleluniverse.actors.behaviors.ServerActor
behavior, currentServerActor, handleInfo, handleMessage, handleTimeout, log, ref, reply, replyError, self, server, setTimeout, shutdown, spawn, spawn, spawn, spawnThread
-
Methods inherited from class co.paralleluniverse.actors.behaviors.BehaviorActor
doRun, getInitializer, handleLifecycleMessage, init, isRunning, onStart, onTerminate, terminate
-
Methods inherited from class co.paralleluniverse.actors.Actor
addLifecycleListener, build, checkThrownIn, close, currentActor, filterMessage, get, get, getActor, getDeathCause, getMonitor, getName, getQueueLength, getStrand, hire, hire, internalSend, internalSendNonSuspendable, interrupt, isClosed, isDone, isInActor, isRegistered, isStarted, join, join, link, linked, mailbox, migrate, migrateAndRestart, monitor, monitorAddDeath, monitorAddMessage, monitorResetSkippedMessages, monitorSkippedMessage, newActor, newActor, onCodeChange, readResolve, receive, receive, receive, register, register, reinstantiate, removeLifecycleListener, removeObserverListeners, run, sendSync, setForwardWatch, setMonitor, setName, setStrand, start, stopMonitor, throwIn, toString, tryReceive, trySend, unlink, unlinked, unregister, unwatch, verifyInActor, verifyOnActorStrand, watch, writeReplace
-
Methods inherited from class co.paralleluniverse.actors.ActorImpl
close, getLifecycleListener, getMailbox, isRecordingLevel, record, record, record, record, record, record, record, sendOrInterrupt
-
-
-
-
Constructor Detail
-
ProxyServerActor
public ProxyServerActor(java.lang.String name, Strand strand, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>[] interfaces)
Creates a newProxyServerActor
- Parameters:
name
- the actor's name (may be null)strand
- the actor's strand (may be null)mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.interfaces
- the interfaces this actor'sActorRef
will implement;target
must implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
- Parameters:
name
- the actor's name (may be null)mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.interfaces
- the interfaces this actor'sActorRef
will implement;target
must implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
with the default mailbox settings.- Parameters:
name
- the actor's name (may be null)callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.interfaces
- the interfaces this actor'sActorRef
will implement;target
must implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
- Parameters:
mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.interfaces
- the interfaces this actor'sActorRef
will implement;target
must implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)
Creates a newProxyServerActor
with the default mailbox settings.- Parameters:
callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.interfaces
- the interfaces this actor'sActorRef
will implement;target
must implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
, which exposes all interfaces implemented by the giventarget
.- Parameters:
name
- the actor's name (may be null)mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.
-
ProxyServerActor
public ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
with the default mailbox settings, which exposes all interfaces implemented by the giventarget
.- Parameters:
name
- the actor's name (may be null)callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.
-
ProxyServerActor
public ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
, which exposes all interfaces implemented by the giventarget
.- Parameters:
mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.
-
ProxyServerActor
public ProxyServerActor(boolean callOnVoidMethods, java.lang.Object target)
Creates a newProxyServerActor
with the default mailbox settings, which exposes all interfaces implemented by the giventarget
.- Parameters:
callOnVoidMethods
- whether calling void methods will block until they have completed executiontarget
- the object implementing the actor's behaviors, on which the exposed interface methods will be called.
-
ProxyServerActor
protected ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls.- Parameters:
name
- the actor's name (may be null)mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed executioninterfaces
- the interfaces this actor'sActorRef
will implement; this class must implement all these interfaces.
-
ProxyServerActor
protected ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls. The default mailbox settings will be used.- Parameters:
name
- the actor's name (may be null)callOnVoidMethods
- whether calling void methods will block until they have completed executioninterfaces
- the interfaces this actor'sActorRef
will implement; this class must implement all these interfaces.
-
ProxyServerActor
protected ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls. The default mailbox settings will be used.- Parameters:
callOnVoidMethods
- whether calling void methods will block until they have completed executioninterfaces
- the interfaces this actor'sActorRef
will implement; this class must implement all these interfaces.
-
ProxyServerActor
protected ProxyServerActor(boolean callOnVoidMethods, java.lang.Class<?>... interfaces)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls. The default mailbox settings will be used.- Parameters:
callOnVoidMethods
- whether calling void methods will block until they have completed executioninterfaces
- the interfaces this actor'sActorRef
will implement; this class must implement all these interfaces.
-
ProxyServerActor
protected ProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls, and all of the interfaces implemented by the subclass will be exposed by theActorRef
.- Parameters:
name
- the actor's name (may be null)mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed execution
-
ProxyServerActor
protected ProxyServerActor(java.lang.String name, boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls, and all of the interfaces implemented by the subclass will be exposed by theActorRef
. The default mailbox settings will be used.- Parameters:
name
- the actor's name (may be null)callOnVoidMethods
- whether calling void methods will block until they have completed execution
-
ProxyServerActor
protected ProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls, and all of the interfaces implemented by the subclass will be exposed by theActorRef
.- Parameters:
mailboxConfig
- this actor's mailbox settings.callOnVoidMethods
- whether calling void methods will block until they have completed execution
-
ProxyServerActor
protected ProxyServerActor(boolean callOnVoidMethods)
This constructor is for use by subclasses that are intended to serve as the target. This object will serve as the target for the method calls, and all of the interfaces implemented by the subclass will be exposed by theActorRef
. The default mailbox settings will be used.- Parameters:
callOnVoidMethods
- whether calling void methods will block until they have completed execution
-
-
Method Detail
-
makeRef
protected final Server<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation> makeRef(ActorRef<java.lang.Object> ref)
- Overrides:
makeRef
in classServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
-
checkCodeSwap
protected void checkCodeSwap() throws SuspendExecution
Description copied from class:Actor
Tests whether this actor has been upgraded via hot code-swapping. If a new version of this actor is found, this method never returns (a specialError
is thrown which causes the actor to restart).- Overrides:
checkCodeSwap
in classBehaviorActor
- Throws:
SuspendExecution
-
handleCall
protected java.lang.Object handleCall(ActorRef<?> from, java.lang.Object id, ProxyServerActor.Invocation m) throws java.lang.Exception, SuspendExecution
Description copied from class:ServerActor
Called to handle a synchronous request (one waiting for a response).By default, this method calls
server
.handleCall
if a server object was supplied at construction time. Otherwise, it throws anUnsupportedOperationException
, which will be sent back to the requester.- 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
.
- Overrides:
handleCall
in classServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
- 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:
java.lang.Exception
- if thrown, it will be sent back to the sender of the request.SuspendExecution
- If this method returns a non-null value, it will be sent back to the sender of the request wrapped by an
-
handleCast
protected void handleCast(ActorRef<?> from, java.lang.Object id, ProxyServerActor.Invocation m) throws SuspendExecution
Description copied from class:ServerActor
Called to handle an asynchronous request (one that does not for a response).By default, this method calls
server
.handleCast
if a server object was supplied at construction time. Otherwise, it throws anUnsupportedOperationException
, which will result in this actor's death, unless caught.- Overrides:
handleCast
in classServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
- Parameters:
from
- the sender of the requestid
- the request's unique idm
- the request- Throws:
SuspendExecution
-
-