Class Simon

java.lang.Object
host.anzo.simon.Simon

public class Simon extends Object
This is SIMONs core class which contains all the core functionality like setting up a SIMON server or lookup a remote object from the client side
  • Field Details

    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      Official port assigned by IANA
      Since:
      1.2.0
      See Also:
    • SIMON_STD_PROTOCOL_CODEC_FACTORY

      protected static final String SIMON_STD_PROTOCOL_CODEC_FACTORY
      Identifies the class, that is used as SIMON's standard protocol codec factory
  • Constructor Details

    • Simon

      public Simon()
  • Method Details

    • createRegistry

      public static Registry createRegistry(int port) throws UnknownHostException, IOException
      Creates a registry listening on all interfaces with the last known worker thread pool size set by setWorkerThreadPoolSize(int)
      Parameters:
      port - the port on which SIMON listens for connections
      Returns:
      the created registry object
      Throws:
      UnknownHostException - if no IP address for the host could be found
      IOException - if there is a problem with the networking layer
    • createRegistry

      public static Registry createRegistry() throws UnknownHostException, IOException
      Creates a registry listening on all interfaces with the last known worker thread pool size set by setWorkerThreadPoolSize(int) and the SIMON's default port DEFAULT_PORT.
      Returns:
      the created registry object
      Throws:
      UnknownHostException - if no IP address for the host could be found
      IOException - if there is a problem with the networking layer
      Since:
      1.2.0
    • createRegistry

      public static Registry createRegistry(InetAddress address, int port) throws IOException, IllegalArgumentException
      Creates a registry listening on a specific network interface, identified by the given InetAddress with the last known worker thread pool size set by setWorkerThreadPoolSize(int).
      Parameters:
      address - the InetAddress the registry is bind to
      port - the port the registry is bind to
      Returns:
      the created registry
      Throws:
      IOException - if there is a problem with the networking layer
      IllegalArgumentException - i.e. if specified protocol codec factory class cannot be used
    • createRegistry

      public static Registry createRegistry(InetAddress address) throws IOException, IllegalArgumentException
      Creates a registry listening on a specific network interface, identified by the given InetAddress with the last known worker thread pool size set by setWorkerThreadPoolSize(int) and the SIMON's default port DEFAULT_PORT
      Parameters:
      address - the InetAddress the registry is bind to
      Returns:
      the created registry
      Throws:
      IOException - if there is a problem with the networking layer
      IllegalArgumentException - i.e. if specified protocol codec factory class cannot be used
      Since:
      1.2.0
    • createRegistry

      public static Registry createRegistry(SslContextFactory sslContextFactory, InetAddress address, int port) throws IOException, IllegalArgumentException
      Creates a registry listening on a specific network interface, identified by the given InetAddress with the last known worker thread pool size set by setWorkerThreadPoolSize(int). The communication is done via SSL encryption provided by the given SslContextFactory
      Parameters:
      sslContextFactory - the factory that provides the ssl context for the SSL powered registry
      address - the InetAddress the registry is bind to
      port - the port the registry is bind to
      Returns:
      the created registry
      Throws:
      IOException - if there is a problem with the networking layer
      IllegalArgumentException - i.e. if specified protocol codec factory class cannot be used
    • createRegistry

      public static Registry createRegistry(SslContextFactory sslContextFactory, InetAddress address) throws IOException, IllegalArgumentException
      Creates a registry listening on a specific network interface, identified by the given InetAddress with the last known worker thread pool size set by setWorkerThreadPoolSize(int) and the SIMON's default port DEFAULT_PORT. The communication is done via SSL encryption provided by the given SslContextFactory
      Parameters:
      sslContextFactory - the factory that provides the ssl context for the SSL powered registry
      address - the InetAddress the registry is bind to
      Returns:
      the created registry
      Throws:
      IOException - if there is a problem with the networking layer
      IllegalArgumentException - i.e. if specified protocol codec factory class cannot be used
      Since:
      1.2.0
    • createInterfaceLookup

      public static Lookup createInterfaceLookup(String host, int port) throws UnknownHostException
      Creates a interface lookup object that is used to lookup remote objects.
      Lookup is made via a known interface of the remote object.
      Parameters:
      host - the name of the host on which the registry server runs
      port - the port on which the registry server is listening
      Returns:
      the lookup object
      Throws:
      UnknownHostException - if the specified hostname is unknown
      Since:
      version 1.1.0
    • createInterfaceLookup

      public static InterfaceLookup createInterfaceLookup(InetAddress address, int port)
      Creates a interface lookup object that is used to lookup remote objects.
      Lookup is made via a known interface of the remote object.
      Parameters:
      address - the address of the host on which the registry server runs
      port - the port on which the registry server is listening
      Returns:
      the lookup object
      Since:
      version 1.1.0
    • createInterfaceLookup

      public static InterfaceLookup createInterfaceLookup(String host) throws UnknownHostException
      Creates a interface lookup object that is used to lookup remote objects. The connection is done via SIMON's default port DEFAULT_PORT.
      Lookup is made via a known interface of the remote object.
      Parameters:
      host - the name of the host on which the registry server runs
      Returns:
      the lookup object
      Throws:
      UnknownHostException - if the specified hostname is unknown
      Since:
      1.2.0
    • createInterfaceLookup

      public static Lookup createInterfaceLookup(InetAddress address)
      Creates a interface lookup object that is used to lookup remote objects. The connection is done via SIMON's default port DEFAULT_PORT.
      Lookup is made via a known interface of the remote object.
      Parameters:
      address - the address of the host on which the registry server runs
      Returns:
      the lookup object
      Since:
      1.2.0
    • createNameLookup

      public static Lookup createNameLookup(String host, int port) throws UnknownHostException
      Creates a name lookup object that is used to lookup remote objects.
      Lookup is made via a known name of the remote object.
      Parameters:
      host - the name of the host on which the registry server runs
      port - the port on which the registry server is listening
      Returns:
      the lookup object
      Throws:
      UnknownHostException - if the specified hostname is unknown
      Since:
      version 1.1.0
    • createNameLookup

      public static Lookup createNameLookup(InetAddress address, int port)
      Creates a name lookup object that is used to lookup remote objects.
      Lookup is made via a known name of the remote object.
      Parameters:
      address - the address of the host on which the registry server runs
      port - the port on which the registry server is listening
      Returns:
      the lookup object
      Since:
      version 1.1.0
    • createNameLookup

      public static Lookup createNameLookup(String host) throws UnknownHostException
      Creates a name lookup object that is used to lookup remote objects. The connection is done via SIMON's default port DEFAULT_PORT.
      Lookup is made via a known name of the remote object.
      Parameters:
      host - the name of the host on which the registry server runs
      Returns:
      the lookup object
      Throws:
      UnknownHostException - if the specified hostname is unknown
      Since:
      1.2.0
    • createNameLookup

      public static Lookup createNameLookup(InetAddress address)
      Creates a name lookup object that is used to lookup remote objects. The connection is done via SIMON's default port DEFAULT_PORT.
      Lookup is made via a known name of the remote object.
      Parameters:
      address - the address of the host on which the registry server runs
      Returns:
      the lookup object
      Since:
      1.2.0
    • getRemoteInetSocketAddress

      public static InetSocketAddress getRemoteInetSocketAddress(Object proxyObject)
      Gets the InetSocketAddress used on the remote-side of the given proxy object
      Parameters:
      proxyObject - the proxy object
      Returns:
      the InetSocketAddress on the remote-side
    • getLocalInetSocketAddress

      public static InetSocketAddress getLocalInetSocketAddress(Object proxyObject)
      Gets the InetSocketAddress used on the local-side of the given proxy object
      Parameters:
      proxyObject - the proxy object
      Returns:
      the InetSocketAddress on the local-side
    • getSimonProxy

      protected static SimonProxy getSimonProxy(Object o) throws IllegalArgumentException
      Retrieves SimonProxy invocation handler wrapped in a simple proxy
      Parameters:
      o - the object that holds the proxy
      Returns:
      the extracted SimonProxy
      Throws:
      IllegalArgumentException - if the object does not contain a SimonProxy invocation handler
    • getThreadPool

      protected static ExecutorService getThreadPool()
      Returns the reference to the worker thread pool
      Returns:
      the threadPool
    • setWorkerThreadPoolSize

      public static void setWorkerThreadPoolSize(int size)
      Sets the size of the worker thread pool.
      This will setting only affect new pool that have to be created in future. If given size has value -1, a new pool will create new threads as needed, but will reuse previously constructed threads when they are available. This is the most common setting. Old, for 60 seconds unused threads will be removed. These pools will typically improve the performance of programs that execute many short-lived asynchronous tasks. See documentation of Executors.newCachedThreadPool()

      If size has value >=1, a new pool has a fixed size by the given value

      Parameters:
      size - the size of the used worker thread pool
    • setDgcInterval

      @Deprecated public static void setDgcInterval(int milliseconds)
      Deprecated.
      Sets the DGC's interval time in milliseconds
      Parameters:
      milliseconds - time in milliseconds
    • getDgcInterval

      @Deprecated public static int getDgcInterval()
      Deprecated.
      Gets the DGC's interval time in milliseconds
      Returns:
      the current set DGC interval
    • setDefaultConnectTimeout

      public static void setDefaultConnectTimeout(int millis)
      Sets the default connect timeout for establishing a connection via Lookup
      Parameters:
      millis - time in milliseconds to wait for the established connection
    • getDefaultConnectTimeout

      public static int getDefaultConnectTimeout()
      Gets the default connect timeout in milliseconds. This value is the used default value for all new connections.
      Returns:
      time in milliseconds to wait for the established connection
    • setDefaultKeepAliveInterval

      public static void setDefaultKeepAliveInterval(int seconds)
      Sets the keep alive default interval time in seconds. This value is used as a default value for all new connections.
      Parameters:
      seconds - time in seconds
    • getKeepAliveInterval

      public static int getKeepAliveInterval()
      Gets the default keep-alive interval time in seconds. This value is the used default value for all new connections.
      Returns:
      the current set keep alive interval
    • setDefaultKeepAliveTimeout

      public static void setDefaultKeepAliveTimeout(int seconds)
      Sets the default keep alive timeout time in seconds. This value is used as a default value for all new connections.
      Parameters:
      seconds - time in seconds
    • getDefaultKeepAliveTimeout

      public static int getDefaultKeepAliveTimeout()
      Gets the default network write timeout time in seconds. This value is the used default value for all new connections.
      Returns:
      the current set network write timeout
    • setKeepAliveInterval

      public static void setKeepAliveInterval(Object remoteObject, int seconds)
      Sets the keep alive interval time in seconds for the specified remote object
      Parameters:
      remoteObject -
      seconds - time in seconds
      Throws:
      IllegalArgumentException - if the object is not a valid remote object
    • getKeepAliveInterval

      public static int getKeepAliveInterval(Object remoteObject)
      Gets the keep alive interval time in seconds of the given remote object.
      Parameters:
      remoteObject -
      Returns:
      current set keep alive interval of given remote object
      Throws:
      IllegalArgumentException - if the object is not a valid remote object
    • setKeepAliveTimeout

      public static void setKeepAliveTimeout(Object remoteObject, int seconds)
      Sets the keep alive timeout time in seconds for the specified remote object.
      Parameters:
      remoteObject -
      seconds - time in seconds
      Throws:
      IllegalArgumentException - if the object is not a valid remote object
    • getKeepAliveTimeout

      public static int getKeepAliveTimeout(Object remoteObject) throws IllegalArgumentException
      Gets the keep alive timeout time in seconds of the given remote object.
      Parameters:
      remoteObject -
      Returns:
      current set keep alive timeout of given remote object
      Throws:
      IllegalArgumentException - if the object is not a valid remote object
    • publish

      protected static void publish(SimonPublication simonPublication) throws IOException
      Publishes a remote object. If not already done, publish service thread is started.
      Parameters:
      simonPublication - the object to publish
      Throws:
      IOException - if the publish service cannot be started due to IO problems
    • publishRemote

      protected static void publishRemote(SimonPublication simonPublication, InetSocketAddress remoteRegistry) throws IOException
      Throws:
      IOException
    • unpublish

      protected static boolean unpublish(SimonPublication simonPublication)
      Unpublishs a already published SimonPublication. If there are no more publications available, shutdown the publish service.
      Parameters:
      simonPublication - the publication to unpublish
      Returns:
      true, if elemet was present and is now removed, false if not
    • searchRemoteObjects

      public static PublicationSearcher searchRemoteObjects(SearchProgressListener listener, int searchTime)
      Creates a background thread that searches for published remote objects on the local network
      Parameters:
      listener - a SearchProgressListener implementation which is informed about the current search progress
      searchTime - the time the background search thread spends for searching published remote objects
      Returns:
      a PublicationSearcher which is used to access the search result
    • searchRemoteObjects

      public static List<SimonPublication> searchRemoteObjects(int searchTime)
      Starts a search on the local network for published remote objects.
      Be warned: This method blocks until the search is finished or the current thread is interrupted
      Parameters:
      searchTime - the time that is spend to search for published remote objects
      Returns:
      a List of SimonPublications
    • setProtocolCodecFactory

      public static void setProtocolCodecFactory(String protocolFactoryClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException, ClassCastException
      Sets class name for the protocol codec factory to use for all future createRegistry() or lookup() calls. This does not affect already created registry or already established sessions.
      Parameters:
      protocolFactoryClassName - a class name like "com.mydomain.myproject.codec.mySimonProtocolCodecFactory" which points to a class, that extends SimonProtocolCodecFactory. The important thing is, that this class correctly overrides SimonProtocolCodecFactory.setup(boolean). For further details, look at SimonProtocolCodecFactory!
      Throws:
      IllegalAccessException - if the class or its nullary constructor is not accessible.
      InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.
      ClassNotFoundException - if the class is not found by the classloader. if so, please check your classpath.
      ClassCastException - if the given class is no instance of SimonProtocolCodecFactory
    • getProtocolCodecFactory

      public static String getProtocolCodecFactory()
      Returns the current set class name for the protocol codec factory
      Returns:
      the name of the protocol codec class
    • getStatistics

      public static SimonRemoteStatistics getStatistics(Object remoteObject)
      Returns a object that lets you get some network related information on the session of the given remote object (an instance of SimonProxy
      Parameters:
      remoteObject - the remote object that is asked for the statistics
      Returns:
      an implementation of SimonRemoteStatistics that gives access to the statistics data
    • openRawChannel

      public static RawChannel openRawChannel(int channelToken, Object simonRemote) throws SimonRemoteException
      Opens a raw channel to transfer data from the current station to the remote station described by the given simonRemote
      Parameters:
      channelToken - a token that identifies the already prepared raw channel from the remote station. Those token can only be created on the remote station. Thus a remote call which does the prepareRawChannel(RawChannelDataListener, Object) is needed in advance.
      simonRemote - the remote object which lives on the remote station which has a prepared raw data channel, related to the channelToken. Note: This has to be a remote object stub.
      Returns:
      the opened raw channel object
      Throws:
      SimonRemoteException
    • prepareRawChannel

      public static int prepareRawChannel(RawChannelDataListener listener, Object simonRemote) throws SimonException
      Prepare simonRemote's internal message dispatcher for receiving raw data.
      The result of this method is a token, which identifies the channel on both sides:
      This method has to be called on the receiving side.
      Parameters:
      listener - the listener which gets all the received data related to this channel
      simonRemote - a reference to the remote object whos Dispatcher is prepared to receive raw data.
      Returns:
      a token that identifies the prepared channel
      Throws:
      SimonException
    • registerLookupTable

      protected static void registerLookupTable(LookupTable lookupTable)
      TODO document me
      Parameters:
      lookupTable -
    • unregisterLookupTable

      protected static void unregisterLookupTable(LookupTable lookupTable)
      TODO document me
      Parameters:
      lookupTable -
    • markAsRemote

      public static Object markAsRemote(Object o)
      Marks the object with SimonRemote to make it able to receive incoming calls.
      Parameters:
      o - the object to mark as an SimonRemote
      Returns:
      a marked (proxy) class
      Throws:
      IllegalRemoteObjectException - thrown in case of missing interfaces of given object
      Since:
      1.1.0
    • denoteSameRemoteObjekt

      public static boolean denoteSameRemoteObjekt(Object a, Object b)
      Tests if both objects denote the same remote object. Comparison is done on
      • remote object name
      • underlying IO session

      If both objects denote a remote object and the values match for both objects, result will be true. In any other case, false is returned

      Parameters:
      a -
      b -
      Returns:
      boolean
      Since:
      1.2.0
    • getSessionId

      public static long getSessionId()
      Returns the SIMON internal session id of a current running remote call. This method only works if called within a remote call. Means: Don't use it anywhere else than in the remote implementation. Be careful!
      Returns:
      SIMON internal session id
      Throws:
      IllegalStateException - if called from outside a remote call
    • setCustomInvokeTimeout

      public static void setCustomInvokeTimeout(Method method, int timeout)
      Sets a custom invoke timeout for a remote method
      Parameters:
      method - Method for which the custom timeout should be set
      timeout - timeout in milliseconds. A value <= 0 resets to default.