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 aServerActorthat 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 musttargetargument.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classProxyServerActor.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 protectedProxyServerActor(boolean callOnVoidMethods)This constructor is for use by subclasses that are intended to serve as the target.protectedProxyServerActor(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 newProxyServerActorwith 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 newProxyServerActorwith the default mailbox settings.protectedProxyServerActor(MailboxConfig mailboxConfig, boolean callOnVoidMethods)This constructor is for use by subclasses that are intended to serve as the target.protectedProxyServerActor(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 newProxyServerActorprotectedProxyServerActor(java.lang.String name, boolean callOnVoidMethods)This constructor is for use by subclasses that are intended to serve as the target.protectedProxyServerActor(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 newProxyServerActorwith 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 newProxyServerActorwith the default mailbox settings.protectedProxyServerActor(java.lang.String name, MailboxConfig mailboxConfig, boolean callOnVoidMethods)This constructor is for use by subclasses that are intended to serve as the target.protectedProxyServerActor(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 newProxyServerActorProxyServerActor(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 voidcheckCodeSwap()Tests whether this actor has been upgraded via hot code-swapping.protected java.lang.ObjecthandleCall(ActorRef<?> from, java.lang.Object id, ProxyServerActor.Invocation m)Called to handle a synchronous request (one waiting for a response).protected voidhandleCast(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'sActorRefwill implement;targetmust 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'sActorRefwill implement;targetmust implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(java.lang.String name, boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)Creates a newProxyServerActorwith 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'sActorRefwill implement;targetmust 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'sActorRefwill implement;targetmust implement all these interfaces.
-
ProxyServerActor
public ProxyServerActor(boolean callOnVoidMethods, java.lang.Object target, java.lang.Class<?>... interfaces)Creates a newProxyServerActorwith 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'sActorRefwill implement;targetmust 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 newProxyServerActorwith 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 newProxyServerActorwith 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'sActorRefwill 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'sActorRefwill 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'sActorRefwill 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'sActorRefwill 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:
makeRefin classServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>
-
checkCodeSwap
protected void checkCodeSwap() throws SuspendExecutionDescription copied from class:ActorTests whether this actor has been upgraded via hot code-swapping. If a new version of this actor is found, this method never returns (a specialErroris thrown which causes the actor to restart).- Overrides:
checkCodeSwapin 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:ServerActorCalled to handle a synchronous request (one waiting for a response).By default, this method calls
server.handleCallif 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 thecallmethod. - 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 thecallmethod, possibly wrapped in aRuntimeException. - If this method returns
null, then a reply is not immediately sent, and thecallmethod will remain blocked until a reply is sent manually withreplyorreplyError.
- Overrides:
handleCallin 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:ServerActorCalled to handle an asynchronous request (one that does not for a response).By default, this method calls
server.handleCastif a server object was supplied at construction time. Otherwise, it throws anUnsupportedOperationException, which will result in this actor's death, unless caught.- Overrides:
handleCastin classServerActor<ProxyServerActor.Invocation,java.lang.Object,ProxyServerActor.Invocation>- Parameters:
from- the sender of the requestid- the request's unique idm- the request- Throws:
SuspendExecution
-
-