jview
Class ApplicationJoiner

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiListener
                      extended by jview.ApplicationJoiner
All Implemented Interfaces:
Cloneable, Remote, EventListener, SubComponentListener, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiEventListener, RmiListener, RmiPropertyBearing
Direct Known Subclasses:
JSwitcherStub

public class ApplicationJoiner
extends AbstractRmiListener
implements SubComponentListener

An application joiner is the receiving edge of an sub component and forwards this to an application switcher. This means, that this class is a SubComponentListener that registers at the SubComponentCasters that are bound with names provided in KEY_COMPONENTCASTERS, or, if this list is empty, the local registry is scanned for SubComponentCasters. Casters are distinguished by their SubComponentCaster.respondTo() class returned, which means that multiple casters, responding to the same class, cannot be supported.
The other end is a RemoteSwitching instance. This is determined either by the KEY_APPLICATION key or, if this is not accessible, by scanning the registries on the KEY_APPLICATIONHOSTS list, or, if this, too, is not given or unsuccessful, by a scan through the local host. The first RemoteSwitching instance found is the one served.
When a remote switching instance has been found, it is scanned for all components via its RemoteSwitching.knownSwitches() method. Only the names (i.e. the keys in the mapping) are used by this application, but the entire mapping is available after initialization to subclasses. For all switches found, the RemoteSwitching instance is asked if this name links to a SubComponent by calling RemoteSwitching.getSubResponse(java.lang.String). Classes retrieved here are matched with the caster's classes. Matches found result in caching of the current subcomponent state to allow later #switchTo with the appropriate state.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  RemoteSwitching application
          The remote switching instance served.
static String KEY_APPLICATION
          The RemoteSwitching bindname, if known.
static String KEY_APPLICATIONHOSTS
          If the name of the server is not known, try these hosts.
static String KEY_COMPONENTCASTERS
          The list of component casters, if known.
static String KEY_COMPONENTHOSTS
          The hosts of component casters, if known.
private  Map<String,Icon> names
          If the application was found, this are the names/icons.
private  Map<String,Class<?>> subkeys
          Mapping of application names that are subcomponents to their keys.
private  Map<Class<?>,Object> substates
          Mapping of caster class keys to caster current configuration.
 
Fields inherited from class util.rmi.AbstractRmiListener
KEY_ALIVE, KEY_EXPORTPORT, KEY_INIT, KEY_LISTENERNAME, KEY_RETRY, KEY_RETRYSLEEP, KEY_SHUTDOWNDELAY
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
ApplicationJoiner(Map<String,String> prop)
          Construct a new ApplicationJoiner.
 
Method Summary
protected  boolean deregisterAtCaster(RmiCaster caster, Class reference)
          Deregisters from this caster.
private  RemoteSwitching getApplication(String bindname)
          Looks up the name and returns a RemoteSwitching instance if successful.
protected  Map<String,Icon> getApplications()
          Returns the mapping of names to icons for subclasses.
private  Object getApplicationState(String id)
          Returns the current substate to this named component served in the RemoteSwitching we are connected to.
 void init()
          On init, retrieve the references to the RemoteSwitching application server and register to all SubComponentCasters.
static void main(String[] arg)
           
 void newKey(Object id)
          This method is called by the casters if any state changed.
protected  boolean registerAtCaster(RmiCaster caster, Class reference)
          Registers at this caster.
private  boolean scanNeeded(List<String> binds, Collection<Class<?>> keys)
          Scans a list of binding names for casters of the appropriate keys.
private  List<String> scanRegistry(String host, Class<? extends Remote> id)
          Scans the registry on the given host for entries that are instances of the stated class or subclass.
 boolean visible(String id)
          We make the remote switching application to show its subcomponent.
 
Methods inherited from class util.rmi.AbstractRmiListener
allBound, blockBinding, blockBinding, disconnect, exit, getIP, getListenerName, isConnected, listenerName, releaseBinding, releaseBinding, rescanned, startBinding, startBinding
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

KEY_APPLICATION

public static final String KEY_APPLICATION
The RemoteSwitching bindname, if known.

See Also:
Constant Field Values

KEY_APPLICATIONHOSTS

public static final String KEY_APPLICATIONHOSTS
If the name of the server is not known, try these hosts.

See Also:
Constant Field Values

KEY_COMPONENTCASTERS

public static final String KEY_COMPONENTCASTERS
The list of component casters, if known.

See Also:
Constant Field Values

KEY_COMPONENTHOSTS

public static final String KEY_COMPONENTHOSTS
The hosts of component casters, if known.

See Also:
Constant Field Values

application

private RemoteSwitching application
The remote switching instance served.


names

private Map<String,Icon> names
If the application was found, this are the names/icons.


subkeys

private Map<String,Class<?>> subkeys
Mapping of application names that are subcomponents to their keys.


substates

private Map<Class<?>,Object> substates
Mapping of caster class keys to caster current configuration.

Constructor Detail

ApplicationJoiner

public ApplicationJoiner(Map<String,String> prop)
                  throws RemoteException
Construct a new ApplicationJoiner. Binding is done in init.

Throws:
RemoteException
Method Detail

init

public void init()
On init, retrieve the references to the RemoteSwitching application server and register to all SubComponentCasters.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyResources

newKey

public void newKey(Object id)
            throws RemoteException
This method is called by the casters if any state changed. We might serve multiple casters, but the class of the key has to be unique.

Specified by:
newKey in interface SubComponentListener
Throws:
RemoteException

visible

public boolean visible(String id)
We make the remote switching application to show its subcomponent.


getApplications

protected Map<String,Icon> getApplications()
Returns the mapping of names to icons for subclasses.


getApplicationState

private Object getApplicationState(String id)
Returns the current substate to this named component served in the RemoteSwitching we are connected to. We first look-up the ID in the subcomponent list, if it is not found there we retrun null. If this ID points to a known subcomponent, we query further and see, if we also know its state. If not, we return null.

Returns:
The current state object of the component in question.

registerAtCaster

protected boolean registerAtCaster(RmiCaster caster,
                                   Class reference)
Registers at this caster.

Specified by:
registerAtCaster in class AbstractRmiListener
Returns:
True, if this listener can register at the specified caster

deregisterAtCaster

protected boolean deregisterAtCaster(RmiCaster caster,
                                     Class reference)
Deregisters from this caster.

Specified by:
deregisterAtCaster in class AbstractRmiListener
Returns:
True, if this listener can deregister at the specified caster

getApplication

private RemoteSwitching getApplication(String bindname)
Looks up the name and returns a RemoteSwitching instance if successful.


scanRegistry

private List<String> scanRegistry(String host,
                                  Class<? extends Remote> id)
Scans the registry on the given host for entries that are instances of the stated class or subclass. Only return the binding names, not the remote reference. If no entries are found, return an empty list. If the host string is null, scan the local host. If remote exceptions are thrown, swallow them silently.

Returns:
A list of Naming-resolvable binding names.

scanNeeded

private boolean scanNeeded(List<String> binds,
                           Collection<Class<?>> keys)
Scans a list of binding names for casters of the appropriate keys. As soon as all keys have been found, we return true.


main

public static void main(String[] arg)
                 throws Exception
Throws:
Exception