java.lang.Object
org.refcodes.component.AbstractConnectableAutomaton
org.refcodes.remoting.RemoteClient
- 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<Serializable>>,org.refcodes.component.ConnectionComponent.ConnectionAutomaton<org.refcodes.io.DatagramTransceiver<Serializable>>,org.refcodes.component.ConnectionOpenable<org.refcodes.io.DatagramTransceiver<Serializable>>,org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<org.refcodes.io.DatagramTransceiver<Serializable>>,org.refcodes.component.ConnectionStatusAccessor,org.refcodes.component.Destroyable,org.refcodes.component.OpenedAccessor,org.refcodes.mixin.BusyAccessor,org.refcodes.mixin.Clearable,org.refcodes.mixin.EmptyAccessor,Remote,org.refcodes.struct.Containable
public class RemoteClient
extends org.refcodes.component.AbstractConnectableAutomaton
implements Remote
A
RemoteClient promotes subjects to be operated on by a
RemoteServer.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.mixin.BusyAccessor
org.refcodes.mixin.BusyAccessor.BusyMutator, org.refcodes.mixin.BusyAccessor.BusyPropertyNested 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.ClosedPropertyNested classes/interfaces inherited from interface org.refcodes.component.ConnectableComponent
org.refcodes.component.ConnectableComponent.ConnectableAutomatonNested classes/interfaces inherited from interface org.refcodes.component.ConnectionComponent
org.refcodes.component.ConnectionComponent.ConnectionAutomaton<CON extends Object>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON extends 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 Object>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON extends 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.ConnectionStatusPropertyNested classes/interfaces inherited from interface org.refcodes.component.Destroyable
org.refcodes.component.Destroyable.DestroyAutomatonNested classes/interfaces inherited from interface org.refcodes.mixin.EmptyAccessor
org.refcodes.mixin.EmptyAccessor.EmptyMutator, org.refcodes.mixin.EmptyAccessor.EmptyPropertyNested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor of theRemoteClientwill use a defaultExecutorService.RemoteClient(ExecutorService aExecutorService) Instantiates a newRemoteClientinstance with the givenExecutorServiceto be used. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()voidclose()protected voidclose(org.refcodes.remoting.CloseConnectionMessage aJob) Closes theRemoteupon a receivedCloseConnectionMessage.voiddestroy()protected voidThedigest(Message)method is invoked in order to trigger processing of the providedMessage, e.g. start execution depending on theMessageinstance being provided from the outside.protected 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.<T> TReturns the proxy which can be cast to the given type.booleanReturns true if there is at least one proxy of the given type.booleanReturns true if the provided proxy is contained inside theRemoteClient.booleanisBusy()protected booleanHook to support theDestroyableinterface, determines the destroyed status property; set to true whenDestroyable.destroy()is called.booleanisEmpty()booleanisOpenable(org.refcodes.io.DatagramTransceiver<Serializable> aConnection) protected voidonClosed()Hook when the connection has been closed.protected voidonOpened()Hook when the connection has been opened.protected voidonProxyPublished(Object aProxy) Hook when a proxy has been published.protected voidonProxySignedOff(Object aProxy) Hook when a proxy has been signed-off.protected voidonPublishProxy(Class<?> aType) Hook when a proxy is about to be published.voidopen(org.refcodes.io.DatagramTransceiver<Serializable> aTransceiver) proxies()Returns a read-only iterator containing all the proxy objects previously being published.booleansignOffProxy(Object aProxy) Signs off an instance previously published using the publishClassDescriptor() method.intsize()protected voidtoReceiver(Message aJob) Forwards anMessagefrom this sender to another receiver.Methods inherited from class org.refcodes.component.AbstractConnectableAutomaton
getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUncheckedMethods inherited from interface org.refcodes.component.Closable.CloseAutomaton
isClosableMethods inherited from interface org.refcodes.component.ClosedAccessor
isClosedMethods inherited from interface org.refcodes.component.ConnectionOpenable
open, openUncheckedMethods inherited from interface org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton
isOpenableMethods inherited from interface org.refcodes.component.ConnectionStatusAccessor
getConnectionStatus, isOpened
-
Constructor Details
-
RemoteClient
public RemoteClient()Default constructor of theRemoteClientwill use a defaultExecutorService. -
RemoteClient
Instantiates a newRemoteClientinstance with the givenExecutorServiceto be used.- Parameters:
aExecutorService- TheExecutorServiceto be used.
-
-
Method Details
-
clear
public void clear()- Specified by:
clearin interfaceorg.refcodes.mixin.Clearable
-
close
- Specified by:
closein interfaceorg.refcodes.component.Closable- Throws:
IOException
-
isBusy
public boolean isBusy()- Specified by:
isBusyin interfaceorg.refcodes.mixin.BusyAccessor
-
hasProxy
Returns true if the provided proxy is contained inside theRemoteClient.- Parameters:
aProxy- The proxy to be tested if it is contained inside theRemoteClient.- Returns:
- True if the given proxy is contained inside the
RemoteClient.
-
getProxy
Returns the proxy which can be cast to the given type. Note that this method may throw anAmbiguousProxyExceptioneven ifhasProxy(Class)returns true! The methodhasProxy(Class)returns true in case at least one proxy of the given type was found whereas this method only returns a proxy in case there is exactly one proxy of the required type is present.- Type Parameters:
T- the generic type- Parameters:
aType- the type- Returns:
- The proxy for an instance of the given type.
- Throws:
AmbiguousProxyException- Thrown in case a proxy for a given type was requested but more than one proxies matched the requested type.NoSuchProxyException- Thrown in case a proxy for a given type was requested but not any proxy matched the requested type.
-
hasProxy
Returns true if there is at least one proxy of the given type.- Parameters:
aType- the type- Returns:
- True in case there is at least one proxy of the given type.
-
proxies
Returns a read-only iterator containing all the proxy objects previously being published. Use the sign-off methods in order to remove a published proxy object.- Returns:
- An iterator containing the published proxy objects.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceorg.refcodes.mixin.EmptyAccessor
-
signOffProxy
Signs off an instance previously published using the publishClassDescriptor() method.- Parameters:
aProxy- An object of type GenericInstanceDescriptor containing the information needed to sign-off an instance.- Returns:
- True is returned if the instance described by the proxy object could be signed off, else false is returned
- Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
size
public int size()- Specified by:
sizein interfaceorg.refcodes.struct.Containable
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.refcodes.component.Destroyable
-
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
Thedigest(Message)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. -
close
protected void close(org.refcodes.remoting.CloseConnectionMessage aJob) Closes theRemoteupon a receivedCloseConnectionMessage. Some client TID 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.
-
onPublishProxy
Hook when a proxy is about to be published.- Parameters:
aType- The type to be stored by the property.- Throws:
org.refcodes.exception.VetoException- Thrown to signal that an operation is being vetoed by a third party observing the invocation of the given operation.
-
onProxyPublished
Hook when a proxy has been published.- Parameters:
aProxy- The proxy to being published.
-
onProxySignedOff
Hook when a proxy has been signed-off.- Parameters:
aProxy- The proxy which has been signed-off.
-
isOpenable
- Specified by:
isOpenablein interfaceorg.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<org.refcodes.io.DatagramTransceiver<Serializable>>
-
open
- Specified by:
openin interfaceorg.refcodes.component.ConnectionOpenable<org.refcodes.io.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
Provides anMessagefrom another sender to this receiver. A sub-class invokes this method when it receives anMessagefrom a sender counterpart. The communication path is to be implemented by the sub-class.- Parameters:
aJob- theMessageto be forwarded to this receiver from the sender counterpart.
-
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.
-