Package host.anzo.simon
Class Simon
java.lang.Object
host.anzo.simon.Simon
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intOfficial port assigned by IANAprotected static final StringIdentifies the class, that is used as SIMON's standard protocol codec factory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InterfaceLookupcreateInterfaceLookup(String host) Creates a interface lookup object that is used to lookup remote objects.static LookupcreateInterfaceLookup(String host, int port) Creates a interface lookup object that is used to lookup remote objects.static LookupcreateInterfaceLookup(InetAddress address) Creates a interface lookup object that is used to lookup remote objects.static InterfaceLookupcreateInterfaceLookup(InetAddress address, int port) Creates a interface lookup object that is used to lookup remote objects.static LookupcreateNameLookup(String host) Creates a name lookup object that is used to lookup remote objects.static LookupcreateNameLookup(String host, int port) Creates a name lookup object that is used to lookup remote objects.static LookupcreateNameLookup(InetAddress address) Creates a name lookup object that is used to lookup remote objects.static LookupcreateNameLookup(InetAddress address, int port) Creates a name lookup object that is used to lookup remote objects.static RegistryCreates a registry listening on all interfaces with the last known worker thread pool size set bysetWorkerThreadPoolSize(int)and the SIMON's default portDEFAULT_PORT.static RegistrycreateRegistry(int port) Creates a registry listening on all interfaces with the last known worker thread pool size set bysetWorkerThreadPoolSize(int)static RegistrycreateRegistry(SslContextFactory sslContextFactory, InetAddress address) Creates a registry listening on a specific network interface, identified by the givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int)and the SIMON's default portDEFAULT_PORT.static RegistrycreateRegistry(SslContextFactory sslContextFactory, InetAddress address, int port) Creates a registry listening on a specific network interface, identified by the givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int).static RegistrycreateRegistry(InetAddress address) Creates a registry listening on a specific network interface, identified by the givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int)and the SIMON's default portDEFAULT_PORTstatic RegistrycreateRegistry(InetAddress address, int port) Creates a registry listening on a specific network interface, identified by the givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int).static booleanTests if both objects denote the same remote object.static intGets the default connect timeout in milliseconds.static intGets the default network write timeout time in seconds.static intDeprecated.static intGets the default keep-alive interval time in seconds.static intgetKeepAliveInterval(Object remoteObject) Gets the keep alive interval time in seconds of the given remote object.static intgetKeepAliveTimeout(Object remoteObject) Gets the keep alive timeout time in seconds of the given remote object.static InetSocketAddressgetLocalInetSocketAddress(Object proxyObject) Gets the InetSocketAddress used on the local-side of the given proxy objectstatic StringReturns the current set class name for the protocol codec factorystatic InetSocketAddressgetRemoteInetSocketAddress(Object proxyObject) Gets the InetSocketAddress used on the remote-side of the given proxy objectstatic longReturns the SIMON internal session id of a current running remote call.protected static SimonProxyRetrievesSimonProxyinvocation handler wrapped in a simple proxystatic SimonRemoteStatisticsgetStatistics(Object remoteObject) Returns a object that lets you get some network related information on the session of the given remote object (an instance ofSimonProxyprotected static ExecutorServiceReturns the reference to the worker thread poolstatic ObjectMarks the object with SimonRemote to make it able to receive incoming calls.static RawChannelopenRawChannel(int channelToken, Object simonRemote) Opens a raw channel to transfer data from the current station to the remote station described by the givensimonRemotestatic intprepareRawChannel(RawChannelDataListener listener, Object simonRemote) PreparesimonRemote's internal message dispatcher for receiving raw data.
The result of this method is a token, which identifies the channel on both sides: on the receiving side with the registeredRawChannelDataListener, and on the sending side for opening theRawChannelby callingopenRawChannel(int, Object).
This method has to be called on the receiving side.protected static voidpublish(SimonPublication simonPublication) Publishes a remote object.protected static voidpublishRemote(SimonPublication simonPublication, InetSocketAddress remoteRegistry) protected static voidregisterLookupTable(LookupTable lookupTable) TODO document mestatic List<SimonPublication>searchRemoteObjects(int searchTime) Starts a search on the local network for published remote objects.static PublicationSearchersearchRemoteObjects(SearchProgressListener listener, int searchTime) Creates a background thread that searches for published remote objects on the local networkstatic voidsetCustomInvokeTimeout(Method method, int timeout) Sets a custom invoke timeout for a remote methodstatic voidsetDefaultConnectTimeout(int millis) Sets the default connect timeout for establishing a connection via Lookupstatic voidsetDefaultKeepAliveInterval(int seconds) Sets the keep alive default interval time in seconds.static voidsetDefaultKeepAliveTimeout(int seconds) Sets the default keep alive timeout time in seconds.static voidsetDgcInterval(int milliseconds) Deprecated.usesetDefaultKeepAliveInterval(int)instead!static voidsetKeepAliveInterval(Object remoteObject, int seconds) Sets the keep alive interval time in seconds for the specified remote objectstatic voidsetKeepAliveTimeout(Object remoteObject, int seconds) Sets the keep alive timeout time in seconds for the specified remote object.static voidsetProtocolCodecFactory(String protocolFactoryClassName) Sets class name for the protocol codec factory to use for all futurecreateRegistry()orlookup()calls.static voidsetWorkerThreadPoolSize(int size) Sets the size of the worker thread pool.
This will setting only affect new pool that have to be created in future.protected static booleanunpublish(SimonPublication simonPublication) Unpublishs a already publishedSimonPublication.protected static voidunregisterLookupTable(LookupTable lookupTable) TODO document me
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORTOfficial port assigned by IANA- Since:
- 1.2.0
- See Also:
-
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
Creates a registry listening on all interfaces with the last known worker thread pool size set bysetWorkerThreadPoolSize(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 foundIOException- if there is a problem with the networking layer
-
createRegistry
Creates a registry listening on all interfaces with the last known worker thread pool size set bysetWorkerThreadPoolSize(int)and the SIMON's default portDEFAULT_PORT.- Returns:
- the created registry object
- Throws:
UnknownHostException- if no IP address for the host could be foundIOException- 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 givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int).- Parameters:
address- theInetAddressthe registry is bind toport- the port the registry is bind to- Returns:
- the created registry
- Throws:
IOException- if there is a problem with the networking layerIllegalArgumentException- 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 givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int)and the SIMON's default portDEFAULT_PORT- Parameters:
address- theInetAddressthe registry is bind to- Returns:
- the created registry
- Throws:
IOException- if there is a problem with the networking layerIllegalArgumentException- 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 givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(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 registryaddress- theInetAddressthe registry is bind toport- the port the registry is bind to- Returns:
- the created registry
- Throws:
IOException- if there is a problem with the networking layerIllegalArgumentException- 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 givenInetAddresswith the last known worker thread pool size set bysetWorkerThreadPoolSize(int)and the SIMON's default portDEFAULT_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 registryaddress- theInetAddressthe registry is bind to- Returns:
- the created registry
- Throws:
IOException- if there is a problem with the networking layerIllegalArgumentException- i.e. if specified protocol codec factory class cannot be used- Since:
- 1.2.0
-
createInterfaceLookup
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 runsport- 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
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 runsport- the port on which the registry server is listening- Returns:
- the lookup object
- Since:
- version 1.1.0
-
createInterfaceLookup
Creates a interface lookup object that is used to lookup remote objects. The connection is done via SIMON's default portDEFAULT_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
Creates a interface lookup object that is used to lookup remote objects. The connection is done via SIMON's default portDEFAULT_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
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 runsport- 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
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 runsport- the port on which the registry server is listening- Returns:
- the lookup object
- Since:
- version 1.1.0
-
createNameLookup
Creates a name lookup object that is used to lookup remote objects. The connection is done via SIMON's default portDEFAULT_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
Creates a name lookup object that is used to lookup remote objects. The connection is done via SIMON's default portDEFAULT_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
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
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
RetrievesSimonProxyinvocation 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
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 ofExecutors.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.usesetDefaultKeepAliveInterval(int)instead!Sets the DGC's interval time in milliseconds- Parameters:
milliseconds- time in milliseconds
-
getDgcInterval
Deprecated.usegetKeepAliveInterval()instead!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
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
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
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
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
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
Unpublishs a already publishedSimonPublication. 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- aSearchProgressListenerimplementation which is informed about the current search progresssearchTime- the time the background search thread spends for searching published remote objects- Returns:
- a
PublicationSearcherwhich is used to access the search result
-
searchRemoteObjects
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
ListofSimonPublications
-
setProtocolCodecFactory
public static void setProtocolCodecFactory(String protocolFactoryClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException, ClassCastException Sets class name for the protocol codec factory to use for all futurecreateRegistry()orlookup()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 extendsSimonProtocolCodecFactory. The important thing is, that this class correctly overridesSimonProtocolCodecFactory.setup(boolean). For further details, look atSimonProtocolCodecFactory!- 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 ofSimonProtocolCodecFactory
-
getProtocolCodecFactory
Returns the current set class name for the protocol codec factory- Returns:
- the name of the protocol codec class
-
getStatistics
Returns a object that lets you get some network related information on the session of the given remote object (an instance ofSimonProxy- Parameters:
remoteObject- the remote object that is asked for the statistics- Returns:
- an implementation of
SimonRemoteStatisticsthat 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 givensimonRemote- 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 theprepareRawChannel(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 thechannelToken. 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 PreparesimonRemote's internal message dispatcher for receiving raw data.
The result of this method is a token, which identifies the channel on both sides:- on the receiving side with the
registered
RawChannelDataListener, - and on the sending side
for opening the
RawChannelby callingopenRawChannel(int, Object).
This method has to be called on the receiving side.- Parameters:
listener- the listener which gets all the received data related to this channelsimonRemote- a reference to the remote object whosDispatcheris prepared to receive raw data.- Returns:
- a token that identifies the prepared channel
- Throws:
SimonException
- on the receiving side with the
registered
-
registerLookupTable
TODO document me- Parameters:
lookupTable-
-
unregisterLookupTable
TODO document me- Parameters:
lookupTable-
-
markAsRemote
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
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
Sets a custom invoke timeout for a remote method- Parameters:
method- Method for which the custom timeout should be settimeout- timeout in milliseconds. A value <= 0 resets to default.
-
getKeepAliveInterval()instead!