de.root1.simon
Class LookupTable

java.lang.Object
  extended by de.root1.simon.LookupTable

public class LookupTable
extends java.lang.Object

This class is "the brain" of SIMON. It saves all known remote object <-> name relations, as well as hashcodes for all the methods in the remote object. If a object is getting unreferenced over the network connection, it gets "informed" by the unreferenced() method, if SimonUnreferenced is implemented.

Author:
ACHR

Constructor Summary
protected LookupTable(Dispatcher dispatcher)
          Called via Dispatcher to create a lookup table.
 
Method Summary
protected  void cleanup()
          Clears the whole LookupTable
protected  java.util.HashMap<java.lang.Long,java.lang.reflect.Method> computeMethodHashMap(java.lang.Class<?> remoteClass)
          Computes for each method of the given remote object a method has and save this in an internal map for later lookup
protected  Dispatcher getDispatcher()
          TODO document me
 java.lang.reflect.Method getMethod(java.lang.String remoteObject, long methodHash)
          Gets a method according to the given remote object name and method hash value
protected  RemoteObjectContainer getRemoteObjectContainer(java.lang.String remoteObjectName)
          Gets a already bind remote object according to the given remote object name
protected  RemoteObjectContainer getRemoteObjectContainerByInterface(java.lang.String interfaceName)
          Gets a already bind remote object according to the given remote interface name
protected  boolean isSimonRemoteRegistered(java.lang.Object simonRemote)
          TODO document me
protected  void putRemoteBinding(java.lang.String remoteObjectName, java.lang.Object remoteObject)
          Saves a remote object in the lookup table for later reference
protected  void putRemoteInstanceBinding(long sessionId, java.lang.String remoteObjectName, java.lang.Object remoteObject)
          This method is used by the Dispatcher and the ProcessMessageRunnable class.
protected  void releaseRemoteBinding(java.lang.String name)
          Frees a saved remote object.
protected  void unreference(long sessionId)
          Removes remote instance objects from LookupTable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookupTable

protected LookupTable(Dispatcher dispatcher)
Called via Dispatcher to create a lookup table. There's only one LookupTabnle for one Dispatcher.

Parameters:
dispatcher -
Method Detail

putRemoteBinding

protected void putRemoteBinding(java.lang.String remoteObjectName,
                                java.lang.Object remoteObject)
Saves a remote object in the lookup table for later reference

Parameters:
remoteObjectName - the name of the remote object
remoteObject - a simon remote object

putRemoteInstanceBinding

protected void putRemoteInstanceBinding(long sessionId,
                                        java.lang.String remoteObjectName,
                                        java.lang.Object remoteObject)
This method is used by the Dispatcher and the ProcessMessageRunnable class. Calling this method will store the simon remote object for later GC along with the session This is necessary for the DGC to release all remote instances which are related to a specific IoSession. The object is also stored as a remote binding.

Parameters:
sessionId - the id from IoSession.getId() from the related IoSession
remoteObjectName - the related remote object name
remoteObject - the remote object that has been found in a method argument or method result

getRemoteObjectContainer

protected RemoteObjectContainer getRemoteObjectContainer(java.lang.String remoteObjectName)
                                                  throws LookupFailedException
Gets a already bind remote object according to the given remote object name

Parameters:
remoteObjectName - the name of the object we are interested in
Returns:
the remote object
Throws:
LookupFailedException - if remote object is not available in lookup table

releaseRemoteBinding

protected void releaseRemoteBinding(java.lang.String name)
Frees a saved remote object. After a remote object is freed, it cannot be looked up again until it's bind again.

Parameters:
name - the remote object to free

getMethod

public java.lang.reflect.Method getMethod(java.lang.String remoteObject,
                                          long methodHash)
Gets a method according to the given remote object name and method hash value

Parameters:
remoteObject - the remote object which contains the method
methodHash - the hash of the method
Returns:
the method

computeMethodHashMap

protected java.util.HashMap<java.lang.Long,java.lang.reflect.Method> computeMethodHashMap(java.lang.Class<?> remoteClass)
Computes for each method of the given remote object a method has and save this in an internal map for later lookup

Parameters:
remoteClass - the class that contains the methods
Returns:
a map that holds the methods hash as the key and the method itself as the value

cleanup

protected void cleanup()
Clears the whole LookupTable


unreference

protected void unreference(long sessionId)
Removes remote instance objects from LookupTable. If the remote object implements the interface SimonUnreferenced, the SimonUnreferenced.unreferenced() method is finally called.

Parameters:
sessionId - the id from IoSession.getId() from the related IoSession

getDispatcher

protected Dispatcher getDispatcher()
TODO document me

Returns:
related diuspatcher

isSimonRemoteRegistered

protected boolean isSimonRemoteRegistered(java.lang.Object simonRemote)
TODO document me

Parameters:
simonRemote -
Returns:
true, if the given object is registered, false if not

getRemoteObjectContainerByInterface

protected RemoteObjectContainer getRemoteObjectContainerByInterface(java.lang.String interfaceName)
                                                             throws LookupFailedException
Gets a already bind remote object according to the given remote interface name

Parameters:
interfaceName - then name of the interface to query for
Returns:
the corresponding RemoteObjectContainer
Throws:
LookupFailedException - if nothing was found, or if the found result is not unique


Copyright © 2011. All Rights Reserved.