Package org.refcodes.remoting
Class RemoteServerImpl
- java.lang.Object
-
- org.refcodes.component.AbstractConnectableAutomaton
-
- org.refcodes.remoting.RemoteServerImpl
-
- All Implemented Interfaces:
org.refcodes.component.Closable
,org.refcodes.component.Closable.CloseAutomaton
,org.refcodes.component.ClosedAccessor
,org.refcodes.component.Component
,org.refcodes.component.ConnectableComponent
,org.refcodes.component.ConnectableComponent.ConnectableAutomaton
,org.refcodes.component.ConnectionComponent<org.refcodes.io.DatagramTransceiver<java.io.Serializable>>
,org.refcodes.component.ConnectionComponent.ConnectionAutomaton<org.refcodes.io.DatagramTransceiver<java.io.Serializable>>
,org.refcodes.component.ConnectionOpenable<org.refcodes.io.DatagramTransceiver<java.io.Serializable>>
,org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<org.refcodes.io.DatagramTransceiver<java.io.Serializable>>
,org.refcodes.component.ConnectionStatusAccessor
,org.refcodes.component.Destroyable
,org.refcodes.component.OpenedAccessor
,org.refcodes.mixin.BusyAccessor
,Remote
,RemoteServer
,org.refcodes.structure.Clearable
,org.refcodes.structure.Containable
public class RemoteServerImpl extends org.refcodes.component.AbstractConnectableAutomaton implements RemoteServer
Abstract implementation of theRemoteServer
's base functionality.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.BusyAccessor
org.refcodes.mixin.BusyAccessor.BusyMutator, org.refcodes.mixin.BusyAccessor.BusyProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.Closable
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ClosedAccessor
org.refcodes.component.ClosedAccessor.ClosedMutator, org.refcodes.component.ClosedAccessor.ClosedProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectableComponent
org.refcodes.component.ConnectableComponent.ConnectableAutomaton
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionComponent
org.refcodes.component.ConnectionComponent.ConnectionAutomaton<CON extends java.lang.Object>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON extends java.lang.Object,B extends org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON,B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionOpenable
org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<CON extends java.lang.Object>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON extends java.lang.Object,B extends org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON,B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionStatusAccessor
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
-
-
Constructor Summary
Constructors Constructor Description RemoteServerImpl()
Instantiates a new remote server impl.RemoteServerImpl(java.util.concurrent.ExecutorService aExecutorService)
Instantiates a new remote server impl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
void
close()
protected void
close(CloseConnectionMessage aJob)
Closes theRemote
upon a receivedCloseConnectionMessage
.void
destroy()
void
digest(Message aJob)
Thedigest(Message)
method is invoked in order to trigger processing of the providedMessage
, e.g. start execution depending on theMessage
instance being provided from the outside.protected void
doSendJob(Message aJob)
For testing purposes, any job can be manually pushed into the job process to the receiver.protected void
fromSender(Message aJob)
Provides anMessage
from another sender to this receiver.protected java.util.concurrent.ExecutorService
getExecutorService()
Hook method for retrieving theExecutorService
.boolean
hasSubject(java.lang.Object obj)
Returns true if the provided subject is contained inside thisRemoteServer
.boolean
isBusy()
protected boolean
isDestroyed()
Hook to support theDestroyable
interface, determines the destroyed status property; set to true whendestroy()
is called.boolean
isEmpty()
boolean
isOpenable(org.refcodes.io.DatagramTransceiver<java.io.Serializable> aConnection)
protected void
onClosed()
Hook when the connection has been closed.protected void
onOpened()
Hook when the connection has been opened.protected void
onSubjectPublished(java.lang.Object aSubject)
Hook when a subject has been published.protected void
onSubjectSignedOff(java.lang.Object aSubject)
Hook when a subject has been signed-off.void
open(org.refcodes.io.DatagramTransceiver<java.io.Serializable> aTransceiver)
boolean
publishSubject(java.lang.Object aSubject)
Publishes an object to anyRemoteClient
connected to theRemoteServer
.boolean
signOffSubject(java.lang.Object aSubject)
Tries to sign off the (previously published) subject, this can be vetoed in case the subject is still in use by aRemoteClient
.boolean
signOffSubject(java.lang.Object aSubject, int aTimeoutInMs)
Signs off the (previously published) subject, this be vetoed even in case the subject is still in use by aRemoteClient
, but the veto will only delay the sign off by the given timeout.int
size()
java.util.Iterator<java.lang.Object>
subjects()
Returns an (immutable) iterator containing all the proxy objects previously being published.protected void
toReceiver(Message aJob)
Forwards anMessage
from this sender to another receiver.-
Methods inherited from class org.refcodes.component.AbstractConnectableAutomaton
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus
-
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
-
Methods inherited from interface org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton
isOpenable
-
Methods inherited from interface org.refcodes.component.ConnectionStatusAccessor
getConnectionStatus, isConnectionOpened
-
-
-
-
Method Detail
-
clear
public void clear()
- Specified by:
clear
in interfaceorg.refcodes.structure.Clearable
-
close
public void close()
- Specified by:
close
in interfaceorg.refcodes.component.Closable
-
isBusy
public boolean isBusy()
- Specified by:
isBusy
in interfaceorg.refcodes.mixin.BusyAccessor
-
hasSubject
public boolean hasSubject(java.lang.Object obj)
Returns true if the provided subject is contained inside thisRemoteServer
.- Specified by:
hasSubject
in interfaceRemoteServer
- Parameters:
obj
- The subject to be tested if it is contained inside theRemoteServer
.- Returns:
- True if the given subject is contained inside the
RemoteServer
.
-
subjects
public java.util.Iterator<java.lang.Object> subjects()
Returns an (immutable) iterator containing all the proxy objects previously being published. Use theRemoteServer.signOffSubject(Object)
method in order to remove a published subject.- Specified by:
subjects
in interfaceRemoteServer
- Returns:
- An iterator containing the published proxy objects.
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceorg.refcodes.structure.Containable
-
publishSubject
public boolean publishSubject(java.lang.Object aSubject) throws org.refcodes.component.OpenException
Publishes an object to anyRemoteClient
connected to theRemoteServer
.- Specified by:
publishSubject
in interfaceRemoteServer
- Parameters:
aSubject
- A subject being published for inter-process communication such as remote procedure calls or remote method invocations.- Returns:
- True is returned if the subject could be published, else false is returned
- Throws:
org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
signOffSubject
public boolean signOffSubject(java.lang.Object aSubject) throws org.refcodes.component.OpenException, org.refcodes.exception.VetoException
Tries to sign off the (previously published) subject, this can be vetoed in case the subject is still in use by aRemoteClient
.- Specified by:
signOffSubject
in interfaceRemoteServer
- Parameters:
aSubject
- Description is currently not available!- Returns:
- True if the removal of the subject has been successful. If the
subject has not been found then false is returned. If a
RemoteClient
threw aVetoException
then the sign-off is aborted. - Throws:
org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.org.refcodes.exception.VetoException
- the veto exception
-
signOffSubject
public boolean signOffSubject(java.lang.Object aSubject, int aTimeoutInMs) throws org.refcodes.component.OpenException
Signs off the (previously published) subject, this be vetoed even in case the subject is still in use by aRemoteClient
, but the veto will only delay the sign off by the given timeout.- Specified by:
signOffSubject
in interfaceRemoteServer
- Parameters:
aSubject
- The subject to be signed off.aTimeoutInMs
- The timeout to be granted in case the sign-off has been vetoed, nevertheless the subject will be signed off after the timeout elapsed.- Returns:
- True if the removal of the subject has been successful. If the
subject has not been found then false is returned. If a
RemoteClient
threw aVetoException
then the sign-off is aborted. - Throws:
org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
size
public int size()
- Specified by:
size
in interfaceorg.refcodes.structure.Containable
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceorg.refcodes.component.Destroyable
-
doSendJob
protected void doSendJob(Message aJob) throws org.refcodes.component.OpenException
For testing purposes, any job can be manually pushed into the job process to the receiver.- Parameters:
aJob
- The job to be pushed to the receiver.- Throws:
org.refcodes.component.OpenException
- Thrown in case the operation failed due to an I/O malfunction such as the input- or output-connection (of an input- and output-connection pair) is not available or being disconnected.
-
digest
public void digest(Message aJob) throws org.refcodes.component.DigestException
Thedigest(Message)
method is invoked in order to trigger processing of the providedMessage
, e.g. start execution depending on theMessage
instance being provided from the outside. ARemoteClient
digests such aMessage
different than aRemoteServer
. This method is inspired by theDigester.digest(Object)
method.- Parameters:
aJob
- TheMessage
to be digested.- Throws:
org.refcodes.component.DigestException
- Thrown in case digesting (processing) a job by aDigester.digest(Object)
caused problems; the cause is usually wrapped by thisException
.- See Also:
Digester
-
close
protected void close(CloseConnectionMessage aJob)
Closes theRemote
upon a receivedCloseConnectionMessage
. Some client ID might be considered in order to determine whether to close all or just one of many connections. This default implementation callsclose()
(setting theConnectionStatus
to beConnectionStatus.CLOSED
); advanced implementations just closing dedicated connections may keep theRemote
itself open (and skip callingclose()
and close only a dedicated connection identified by the Meta-Data of theCloseConnectionMessage
.- Parameters:
aJob
- TheCloseConnectionMessage
being received for closing the connection.
-
onSubjectPublished
protected void onSubjectPublished(java.lang.Object aSubject)
Hook when a subject has been published.- Parameters:
aSubject
- The subject being published.
-
onSubjectSignedOff
protected void onSubjectSignedOff(java.lang.Object aSubject)
Hook when a subject has been signed-off.- Parameters:
aSubject
- The subject which has been signed-off.
-
isOpenable
public boolean isOpenable(org.refcodes.io.DatagramTransceiver<java.io.Serializable> aConnection)
- Specified by:
isOpenable
in interfaceorg.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<org.refcodes.io.DatagramTransceiver<java.io.Serializable>>
-
open
public void open(org.refcodes.io.DatagramTransceiver<java.io.Serializable> aTransceiver) throws org.refcodes.component.OpenException
- Specified by:
open
in interfaceorg.refcodes.component.ConnectionOpenable<org.refcodes.io.DatagramTransceiver<java.io.Serializable>>
- Throws:
org.refcodes.component.OpenException
-
toReceiver
protected void toReceiver(Message aJob) throws org.refcodes.component.OpenException
Forwards anMessage
from this sender to another receiver. A sub-class invokes this method when it sends anMessage
to the receiver counterpart. The communication path is to be implemented by the sub-class.- Parameters:
aJob
- theMessage
to be forwarded to this receiver from the sender counterpart.- Throws:
org.refcodes.component.OpenException
- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
fromSender
protected void fromSender(Message aJob)
Provides anMessage
from another sender to this receiver. A sub-class invokes this method when it receives anMessage
from a sender counterpart. The communication path is to be implemented by the sub-class.- Parameters:
aJob
- theMessage
to be forwarded to this receiver from the sender counterpart.
-
getExecutorService
protected java.util.concurrent.ExecutorService getExecutorService()
Hook method for retrieving theExecutorService
.- Returns:
- The
ExecutorService
as used by this implementation.
-
isDestroyed
protected boolean isDestroyed()
Hook to support theDestroyable
interface, determines the destroyed status property; set to true whendestroy()
is called.- Returns:
- The destroyed status property.
-
onOpened
protected void onOpened()
Hook when the connection has been opened.
-
onClosed
protected void onClosed()
Hook when the connection has been closed.
-
-