Class RemoteServer
java.lang.Object
org.refcodes.component.AbstractConnectable
org.refcodes.component.AbstractConnectableAutomaton
org.refcodes.remoting.RemoteServer
- All Implemented Interfaces:
Closable, Closable.CloseAutomaton, ClosedAccessor, Component, ConnectableComponent, ConnectableComponent.ConnectableAutomaton, ConnectionComponent<DatagramTransceiver<Serializable>>, ConnectionComponent.ConnectionAutomaton<DatagramTransceiver<Serializable>>, ConnectionOpenable<DatagramTransceiver<Serializable>>, ConnectionOpenable.ConnectionOpenAutomaton<DatagramTransceiver<Serializable>>, ConnectionStatusAccessor, Destroyable, OpenedAccessor, BusyAccessor, Clearable, EmptyAccessor, Remote, Containable
A
RemoteServer promotes subjects to be operated on by
RemoteClient instances.-
Nested Class Summary
Nested classes/interfaces inherited from interface BusyAccessor
BusyAccessor.BusyMutator, BusyAccessor.BusyPropertyNested classes/interfaces inherited from interface Closable
Closable.CloseAutomaton, Closable.CloseBuilder<B>Nested classes/interfaces inherited from interface ClosedAccessor
ClosedAccessor.ClosedMutator, ClosedAccessor.ClosedPropertyNested classes/interfaces inherited from interface ConnectableComponent
ConnectableComponent.ConnectableAutomatonNested classes/interfaces inherited from interface ConnectionComponent
ConnectionComponent.ConnectionAutomaton<CON>, ConnectionComponent.ConnectionComponentBuilder<CON,B> Nested classes/interfaces inherited from interface ConnectionOpenable
ConnectionOpenable.ConnectionOpenAutomaton<CON>, ConnectionOpenable.ConnectionOpenBuilder<CON,B> Nested classes/interfaces inherited from interface ConnectionStatusAccessor
ConnectionStatusAccessor.ConnectionStatusMutator, ConnectionStatusAccessor.ConnectionStatusPropertyNested classes/interfaces inherited from interface Destroyable
Destroyable.DestroyAutomatonNested classes/interfaces inherited from interface EmptyAccessor
EmptyAccessor.EmptyBuilder<B>, EmptyAccessor.EmptyMutator, EmptyAccessor.EmptyPropertyNested classes/interfaces inherited from interface OpenedAccessor
OpenedAccessor.OpenedMutator, OpenedAccessor.OpenedProperty -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor of theRemoteServerwill use a defaultExecutorService.RemoteServer(ExecutorService aExecutorService) Instantiates a newRemoteServerinstance with the givenExecutorServiceto be used. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidclose()protected voidCloses theRemoteupon a receivedCloseConnectionMessage.voiddestroy()voidprotected voidFor testing purposes, any job can be manually pushed into the job process to the receiver.protected voidfromSender(Message aJob) Provides anMessagefrom another sender to this receiver.protected ExecutorServiceHook method for retrieving theExecutorService.booleanhasSubject(Object aSubject) Returns true if the provided subject is contained inside thisRemoteServer.booleanisBusy()protected booleanHook to support theDestroyableinterface, determines the destroyed status property; set to true whenDestroyable.destroy()is called.booleanisEmpty()booleanisOpenable(DatagramTransceiver<Serializable> aConnection) protected voidonClosed()Hook when the connection has been closed.protected voidonOpened()Hook when the connection has been opened.protected voidonSubjectPublished(Object aSubject) Hook when a subject has been published.protected voidonSubjectSignedOff(Object aSubject) Hook when a subject has been signed-off.voidopen(DatagramTransceiver<Serializable> aTransceiver) booleanpublishSubject(Object aSubject) Publishes an object to anyRemoteClientconnected to theRemoteServer.booleansignOffSubject(Object aSubject) Tries to sign off the (previously published) subject, this can be vetoed in case the subject is still in use by aRemoteClient.booleansignOffSubject(Object aSubject, int aTimeoutMillis) 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.intsize()subjects()Returns an (immutable) iterator containing all the proxy objects previously being published.protected voidtoReceiver(Message aJob) Forwards anMessagefrom this sender to another receiver.Methods inherited from class AbstractConnectableAutomaton
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatusMethods inherited from class AbstractConnectable
isThrownAsOfAlreadyClosedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Closable
closeIn, closeQuietly, closeUncheckedMethods inherited from interface Closable.CloseAutomaton
isClosableMethods inherited from interface ClosedAccessor
isClosedMethods inherited from interface ConnectionOpenable
openUncheckedMethods inherited from interface ConnectionStatusAccessor
getConnectionStatus, isOpened
-
Constructor Details
-
RemoteServer
public RemoteServer()Default constructor of theRemoteServerwill use a defaultExecutorService. -
RemoteServer
Instantiates a newRemoteServerinstance with the givenExecutorServiceto be used.- Parameters:
aExecutorService- TheExecutorServiceto be used.
-
-
Method Details
-
clear
public void clear() -
close
- Specified by:
closein interfaceClosable- Throws:
IOException
-
isBusy
public boolean isBusy() -
hasSubject
Returns true if the provided subject is contained inside thisRemoteServer.- Parameters:
aSubject- The subject to be tested if it is contained inside theRemoteServer.- Returns:
- True if the given subject is contained inside the
RemoteServer.
-
subjects
Returns an (immutable) iterator containing all the proxy objects previously being published. Use thesignOffSubject(Object)method in order to remove a published subject.- Returns:
- An iterator containing the published proxy objects.
-
isEmpty
public boolean isEmpty() -
publishSubject
Publishes an object to anyRemoteClientconnected to theRemoteServer.- 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:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
signOffSubject
Tries to sign off the (previously published) subject, this can be vetoed in case the subject is still in use by aRemoteClient.- 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
RemoteClientthrew aVetoExceptionthen the sign-off is aborted. - Throws:
VetoException- the veto exceptionIOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
signOffSubject
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.- Parameters:
aSubject- The subject to be signed off.aTimeoutMillis- 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
RemoteClientthrew aVetoExceptionthen the sign-off is aborted. - Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
size
public int size() -
destroy
public void destroy()- Specified by:
destroyin interfaceDestroyable
-
doSendJob
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:
IOException- 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
This method is invoked in order to trigger processing of the providedMessage, e.g. start execution depending on theMessageinstance being provided from the outside. ARemoteClientdigests such aMessagedifferent than aRemoteServer. This method is inspired by theDigester.digest(Object)method.- Parameters:
aJob- TheMessageto be digested.- Throws:
DigestException- Thrown in case digesting (processing) a job by aDigester.digest(Object)caused problems; the aCause is usually wrapped by thisException.- See Also:
-
close
Closes theRemoteupon 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 callsClosable.close()(setting theConnectionStatusto beConnectionStatus.CLOSED); advanced implementations just closing dedicated connections may keep theRemoteitself open (and skip callingClosable.close()and close only a dedicated connection identified by the Meta-Data of theCloseConnectionMessage.- Parameters:
aJob- TheCloseConnectionMessagebeing received for closing the connection.
-
onSubjectPublished
Hook when a subject has been published.- Parameters:
aSubject- The subject being published.
-
onSubjectSignedOff
Hook when a subject has been signed-off.- Parameters:
aSubject- The subject which has been signed-off.
-
isOpenable
- Specified by:
isOpenablein interfaceConnectionOpenable.ConnectionOpenAutomaton<DatagramTransceiver<Serializable>>
-
open
- Specified by:
openin interfaceConnectionOpenable<DatagramTransceiver<Serializable>>- Throws:
IOException
-
toReceiver
Forwards anMessagefrom this sender to another receiver. A sub-class invokes this method when it sends anMessageto the receiver counterpart. The communication path is to be implemented by the sub-class.- Parameters:
aJob- theMessageto be forwarded to this receiver from the sender counterpart.- Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
fromSender
-
getExecutorService
Hook method for retrieving theExecutorService.- Returns:
- The
ExecutorServiceas used by this implementation.
-
isDestroyed
protected boolean isDestroyed()Hook to support theDestroyableinterface, determines the destroyed status property; set to true whenDestroyable.destroy()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.
-