Project JXTA

net.jxta.util
Class AbstractSimpleSelectable

java.lang.Object
  extended by net.jxta.util.AbstractSimpleSelectable
All Implemented Interfaces:
SimpleSelectable
Direct Known Subclasses:
AbstractMessenger, Message, SimpleSelector

public abstract class AbstractSimpleSelectable
extends Object
implements SimpleSelectable

This a tool to implement selectable objects. It may be composed or extended.

SimpleSelectable objects that are not SimpleSelector objects only report changes to their listeners.

The listeners of a SimpleSelectable may be SimpleSelector objects or other SimpleSelectable objects. However the method to register non-sectors is and must remain protected since it would allow the connection of arbitrary listeners.

See Also:
SimpleSelector

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.jxta.util.SimpleSelectable
SimpleSelectable.IdentityReference
 
Field Summary
 SimpleSelectable.IdentityReference identityReference
           
 
Constructor Summary
AbstractSimpleSelectable()
           
AbstractSimpleSelectable(SimpleSelectable srcObject)
           
 
Method Summary
 SimpleSelectable.IdentityReference getIdentityReference()
           
protected  boolean haveListeners()
          Tells whether there are registered selectors right now, or not.
protected  boolean notifyChange()
          This method tells us that something changed and so we need to notify our selectors by invoking their itemChanged method.
 void register(SimpleSelector s)
          Registers the given selector with this selectable object.
protected  void registerListener(SimpleSelectable selectable)
          This method takes any listener, not just a SimpleSelector.
 void unregister(SimpleSelector s)
          Unregisters the given selector, so that it is no-longer notified when this object changes.
protected  void unregisterListener(SimpleSelectable selectable)
          This method takes any listener, not just a SimpleSelector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.jxta.util.SimpleSelectable
itemChanged
 

Field Detail

identityReference

public final SimpleSelectable.IdentityReference identityReference
Constructor Detail

AbstractSimpleSelectable

public AbstractSimpleSelectable()

AbstractSimpleSelectable

public AbstractSimpleSelectable(SimpleSelectable srcObject)
Method Detail

getIdentityReference

public SimpleSelectable.IdentityReference getIdentityReference()
Specified by:
getIdentityReference in interface SimpleSelectable
Returns:
A canonical IdentityReference for this object. A given SimpleSelectable always provides the same IdentityReference object. An IdentityReference must never overload hashcode and equals in a way that could make different objects be equal or that could provide different results from invocation to invocation.

haveListeners

protected boolean haveListeners()
Tells whether there are registered selectors right now, or not. A simpleselectable that also registers with something else may want to unregister (with the obvious consistency precautions) if it nolonger has selectors of its own.

Returns:
true if there are listeners.

registerListener

protected void registerListener(SimpleSelectable selectable)
This method takes any listener, not just a SimpleSelector.

Parameters:
selectable - The SimpleSelectable to register

unregisterListener

protected void unregisterListener(SimpleSelectable selectable)
This method takes any listener, not just a SimpleSelector.

Parameters:
selectable - The SimpleSelectable to unregister

register

public void register(SimpleSelector s)
Registers the given selector with this selectable object. This always causes one change event for this object to be reported through the selector. As a result, when selecting for a condition, it is not necessary to verify whether it has already happened or not; the next call to select will be able to detect it.

Specified by:
register in interface SimpleSelectable
Parameters:
s - The SimpleSelector to register

unregister

public void unregister(SimpleSelector s)
Unregisters the given selector, so that it is no-longer notified when this object changes.

Specified by:
unregister in interface SimpleSelectable
Parameters:
s - The SimpleSelector to unregister

notifyChange

protected final boolean notifyChange()
This method tells us that something changed and so we need to notify our selectors by invoking their itemChanged method. This is normally invoked internally by the implementation. One of the reasons for the implementation to invoke this method is that a SimpleSelectable object that this one is registered with has changed and so has invoked the itemChanged method. However, the correlation between the two is left up to the implementation.

No external synchronization needed, nor desirable.

Returns:
false if there are no selectors left (that's a suggestion for the implementation to use haveListeners and possibly unregister itself).

JXTA J2SE