Class RemoteServer

java.lang.Object
org.refcodes.component.AbstractConnectable
org.refcodes.component.AbstractConnectableAutomaton
org.refcodes.remoting.RemoteServer
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 RemoteServer extends org.refcodes.component.AbstractConnectableAutomaton
A RemoteServer promotes subjects to be operated on by RemoteClient instances.
  • 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 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.ConnectionStatusProperty

    Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable

    org.refcodes.component.Destroyable.DestroyAutomaton

    Nested classes/interfaces inherited from interface org.refcodes.mixin.EmptyAccessor

    org.refcodes.mixin.EmptyAccessor.EmptyMutator, org.refcodes.mixin.EmptyAccessor.EmptyProperty

    Nested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor

    org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor of the RemoteServer will use a default ExecutorService.
    RemoteServer(ExecutorService aExecutorService)
    Instantiates a new RemoteServer instance with the given ExecutorService to be used.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    void
    protected void
    close(org.refcodes.remoting.CloseConnectionMessage aJob)
    Closes the Remote upon a received CloseConnectionMessage.
    void
    void
    The digest(Message) method is invoked in order to trigger processing of the provided Message, e.g. start execution depending on the Message instance being provided from the outside.
    protected void
    For testing purposes, any job can be manually pushed into the job process to the receiver.
    protected void
    Provides an Message from another sender to this receiver.
    protected ExecutorService
    Hook method for retrieving the ExecutorService.
    boolean
    hasSubject(Object aSubject)
    Returns true if the provided subject is contained inside this RemoteServer.
    boolean
    protected boolean
    Hook to support the Destroyable interface, determines the destroyed status property; set to true when Destroyable.destroy() is called.
    boolean
    boolean
    isOpenable(org.refcodes.io.DatagramTransceiver<Serializable> aConnection)
    protected void
    Hook when the connection has been closed.
    protected void
    Hook when the connection has been opened.
    protected void
    Hook when a subject has been published.
    protected void
    Hook when a subject has been signed-off.
    void
    open(org.refcodes.io.DatagramTransceiver<Serializable> aTransceiver)
    boolean
    Publishes an object to any RemoteClient connected to the RemoteServer.
    boolean
    Tries to sign off the (previously published) subject, this can be vetoed in case the subject is still in use by a RemoteClient.
    boolean
    signOffSubject(Object aSubject, int aTimeoutMillis)
    Signs off the (previously published) subject, this be vetoed even in case the subject is still in use by a RemoteClient, but the veto will only delay the sign off by the given timeout.
    int
    Returns an (immutable) iterator containing all the proxy objects previously being published.
    protected void
    Forwards an Message from this sender to another receiver.

    Methods inherited from class org.refcodes.component.AbstractConnectableAutomaton

    getConnectionStatus, isClosable, isClosed, isOpenable, isOpened, open, setConnectionStatus

    Methods inherited from class org.refcodes.component.AbstractConnectable

    isThrownAsOfAlreadyClosed

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.refcodes.component.Closable

    closeIn, closeQuietly, closeUnchecked

    Methods inherited from interface org.refcodes.component.Closable.CloseAutomaton

    isClosable

    Methods inherited from interface org.refcodes.component.ClosedAccessor

    isClosed

    Methods inherited from interface org.refcodes.component.ConnectionOpenable

    openUnchecked

    Methods inherited from interface org.refcodes.component.ConnectionStatusAccessor

    getConnectionStatus, isOpened
  • Constructor Details

  • Method Details

    • clear

      public void clear()
    • close

      public void close() throws IOException
      Specified by:
      close in interface org.refcodes.component.Closable
      Throws:
      IOException
    • isBusy

      public boolean isBusy()
    • hasSubject

      public boolean hasSubject(Object aSubject)
      Returns true if the provided subject is contained inside this RemoteServer.
      Parameters:
      aSubject - The subject to be tested if it is contained inside the RemoteServer.
      Returns:
      True if the given subject is contained inside the RemoteServer.
    • subjects

      public Iterator<Object> subjects()
      Returns an (immutable) iterator containing all the proxy objects previously being published. Use the signOffSubject(Object) method in order to remove a published subject.
      Returns:
      An iterator containing the published proxy objects.
    • isEmpty

      public boolean isEmpty()
    • publishSubject

      public boolean publishSubject(Object aSubject) throws IOException
      Publishes an object to any RemoteClient connected to the RemoteServer.
      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

      public boolean signOffSubject(Object aSubject) throws IOException, 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 a RemoteClient.
      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 a VetoException then the sign-off is aborted.
      Throws:
      org.refcodes.exception.VetoException - the veto exception
      IOException - Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
    • signOffSubject

      public boolean signOffSubject(Object aSubject, int aTimeoutMillis) throws IOException
      Signs off the (previously published) subject, this be vetoed even in case the subject is still in use by a RemoteClient, 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 RemoteClient threw a VetoException then 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:
      destroy in interface org.refcodes.component.Destroyable
    • doSendJob

      protected void doSendJob(Message aJob) throws IOException
      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

      public void digest(Message aJob) throws org.refcodes.component.DigestException
      The digest(Message) method is invoked in order to trigger processing of the provided Message, e.g. start execution depending on the Message instance being provided from the outside. A RemoteClient digests such a Message different than a RemoteServer. This method is inspired by the Digester.digest(Object) method.
      Parameters:
      aJob - The Message to be digested.
      Throws:
      org.refcodes.component.DigestException - Thrown in case digesting (processing) a job by a Digester.digest(Object) caused problems; the aCause is usually wrapped by this Exception.
      See Also:
      • Digester
    • close

      protected void close(org.refcodes.remoting.CloseConnectionMessage aJob)
      Closes the Remote upon a received CloseConnectionMessage. Some client ID might be considered in order to determine whether to close all or just one of many connections. This default implementation calls Closable.close() (setting the ConnectionStatus to be ConnectionStatus.CLOSED); advanced implementations just closing dedicated connections may keep the Remote itself open (and skip calling Closable.close() and close only a dedicated connection identified by the Meta-Data of the CloseConnectionMessage.
      Parameters:
      aJob - The CloseConnectionMessage being received for closing the connection.
    • onSubjectPublished

      protected void onSubjectPublished(Object aSubject)
      Hook when a subject has been published.
      Parameters:
      aSubject - The subject being published.
    • onSubjectSignedOff

      protected void onSubjectSignedOff(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<Serializable> aConnection)
      Specified by:
      isOpenable in interface org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<org.refcodes.io.DatagramTransceiver<Serializable>>
    • open

      public void open(org.refcodes.io.DatagramTransceiver<Serializable> aTransceiver) throws IOException
      Specified by:
      open in interface org.refcodes.component.ConnectionOpenable<org.refcodes.io.DatagramTransceiver<Serializable>>
      Throws:
      IOException
    • toReceiver

      protected void toReceiver(Message aJob) throws IOException
      Forwards an Message from this sender to another receiver. A sub-class invokes this method when it sends an Message to the receiver counterpart. The communication path is to be implemented by the sub-class.
      Parameters:
      aJob - the Message to 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

      protected void fromSender(Message aJob)
      Provides an Message from another sender to this receiver. A sub-class invokes this method when it receives an Message from a sender counterpart. The communication path is to be implemented by the sub-class.
      Parameters:
      aJob - the Message to be forwarded to this receiver from the sender counterpart.
    • getExecutorService

      protected ExecutorService getExecutorService()
      Hook method for retrieving the ExecutorService.
      Returns:
      The ExecutorService as used by this implementation.
    • isDestroyed

      protected boolean isDestroyed()
      Hook to support the Destroyable interface, determines the destroyed status property; set to true when Destroyable.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.