|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uk.ac.starlink.plastic.HubManager
Class which keeps track of registering and unregistering with the
PLASTIC hub on behalf of a listening application.
If you want to behave as a plastic
listener, call register()
. If you want to stop listening,
call unregister()
. Either of these may be called more than
once harmlessly. It is a good idea to call register
immediately before sending a plastic message to ensure that the
hub is up to date (it may be a different hub server than last time
you looked). This class implements PlasticListener
and deals with generic messages as well as unregistering from the
hub on JVM shutdown etc. Concrete subclasses must implement
doPerform(java.net.URI, java.net.URI, java.util.List)
to provide any application-specific services.
The generic messages which are handled by this object directly are currently:
Actions are also provided for registering/unregistering and starting a hub, ready for use in a GUI.
Field Summary |
Fields inherited from interface org.votech.plastic.PlasticListener |
CURRENT_VERSION |
Constructor Summary | |
HubManager(String appName,
URI[] supportedMessages)
Constructs a new manager. |
Method Summary | |
static boolean |
checkArgs(List args,
Class[] types)
Utility method to check the types of a list of arguments. |
static URI |
createURI(String uri)
Convenience method to turn a String into a URI without throwing any pesky checked exceptions. |
abstract Object |
doPerform(URI sender,
URI message,
List args)
Does the work for processing an application-type hub message. |
void |
finalize()
Finalizer makes an attempt to unregister from the hub, but won't wait around indefinitely for this to happen. |
ListModel |
getApplicationListModel()
Returns a ListModel which keeps track of the currently registered applications. |
PlasticHubListener |
getHub()
Returns the hub which this listener is registered with. |
Action |
getHubStartAction(boolean internal)
Returns an action which will attempt to start up a PLASTIC hub. |
Action |
getHubWatchAction()
Returns an action that can be used to post a window showing the state of the hub with which this object has a connection. |
Action |
getRegisterAction(boolean reg)
Returns an action which will register/unregister with the PLASTIC hub. |
URI |
getRegisteredId()
Returns the ID with which this listener is registered with the prevailing PLASTIC hub. |
JToggleButton.ToggleButtonModel |
getRegisterToggle()
Returns a toggle button model which keeps track (as far as possible) of whether this listener is currently registered with a hub. |
Object |
perform(URI sender,
URI message,
List args)
Implements the PlasticListener interface. |
void |
register()
Attempts to ensure that this listener is registered with the prevailing PLASTIC hub. |
void |
unregister()
Makes an attempt to unregister from the hub if it's not already been done. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HubManager(String appName, URI[] supportedMessages)
supportedMessages
argument lists the additional
messages for which support is provided. Some standard ones are
supported by the HubManager itself. If this array is empty, then
all messages will be delivered.
appName
- the name of the application whose connections this
object will managesupportedMessages
- URIs of PLASTIC messages supported directly
by this implementation's doPerform(java.net.URI, java.net.URI, java.util.List)
methodMethod Detail |
public URI getRegisteredId()
null
will be returned. If you want to do your best
to get a non-null ID, call register()
first.
public PlasticHubListener getHub()
null
will be returned. If you want to do your best
to get a non-null hub, call register()
first.
public void register() throws IOException
IOException
- if no registration can be achievedpublic void unregister()
public Action getRegisterAction(boolean reg)
reg
- true for register action, false for unregister action
public Action getHubStartAction(boolean internal)
internal
flag, the action may either
start a hub in this JVM (in which case it will expire when the JVM does)
or in a separate process.
An attempt is made to keep the enabledness of this action up to date
with current knowledge about whether the hub is running or not.
internal
- true for an in-JVM hub, false for one in a new JVM
public Action getHubWatchAction()
public JToggleButton.ToggleButtonModel getRegisterToggle()
setSelected
method.
public ListModel getApplicationListModel()
ApplicationItem
.
public Object perform(URI sender, URI message, List args)
perform
in interface PlasticListener
sender
- the ID of the originating application.message
- the URI representing the action.args
- any arguments to pass.
public abstract Object doPerform(URI sender, URI message, List args) throws IOException
sender
argument may be any of the URIs which
this object presented as the supported messages argument of
the HubManager
constructor.
sender
- sender IDmessage
- message ID (determines the action required)args
- message argument list
IOException
public void finalize() throws Throwable
Throwable
public static URI createURI(String uri)
uri
- URI text
IllegalArgumentException
- if uri doesn't look like a URIpublic static boolean checkArgs(List args, Class[] types) throws IOException
types
, or a
subclass of that.
args
- actual argument listtypes
- classes you want to see represented in the initial
elements of list
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |