|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.ivmaidns.util.ObservedCore
public class ObservedCore
Root class for observable objects.
This is an implementation of MultiObservable
. An
observable object (which class extends or includes a variable of
this class) represents mutable 'data' in the model-view paradigm.
Each time an observable object is changed, it must call
notifyObservers(this, argument)
to notify every
registered observer agent (in an unspecified order) about the
event, where argument describes the occurred changes
(as it must be specified for a particular object). Important
notes: agents must not modify observed object anyhow;
notification should be performed just after changes; this
notification mechanism has nothing to do with threads and is
completely separate from the 'wait-notify' mechanism of
Object
.
Notifiable
Constructor Summary | |
---|---|
ObservedCore()
Constructs an observable object. |
Method Summary | |
---|---|
void |
addObserver(Notifiable agent)
Registers one more observer. |
protected java.lang.Object |
clone()
Creates and returns a copy of this object. |
boolean |
hasObservers()
Tests whether this observable object has any
observers. |
void |
integrityCheck()
Verifies this object for its integrity. |
void |
notifyObservers(MultiObservable observed,
java.lang.Object argument)
Notifies each registered observer agent on the event that just occurred. |
void |
removeObserver(Notifiable agent)
Unregisters a particular observer. |
void |
trimToSize()
Frees extra memory. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObservedCore()
addObserver(net.sf.ivmaidns.util.Notifiable)
Method Detail |
---|
public void trimToSize()
trimToSize
in interface TrimToSizeable
addObserver(net.sf.ivmaidns.util.Notifiable)
,
removeObserver(net.sf.ivmaidns.util.Notifiable)
public void addObserver(Notifiable agent) throws java.lang.NullPointerException
this
observable object
is changed somehow. If the specified agent is already registered
here then the registration of this agent is not performed (no
duplicate agents). Internal observers array may be
re-allocated (to have at least enough space for holding all
registered agents). If an exception is thrown then state of
this
object is not changed. This method must be
synchronized outside. Important notes: registered observers are
not accessible for other objects, not copied when
this
object is cloned, and not serialized.
addObserver
in interface MultiObservable
agent
- the observer agent (must be non-null
) to be
registered.
java.lang.NullPointerException
- if agent is null
.
java.lang.OutOfMemoryError
- if there is not enough memory.removeObserver(net.sf.ivmaidns.util.Notifiable)
,
notifyObservers(net.sf.ivmaidns.util.MultiObservable,
java.lang.Object)
public void removeObserver(Notifiable agent)
null
or
equals(agent)
is false
for every
registered agent then nothing is performed. Else the specified
agent is removed from observers of this
observable object (this action is just the opposite to the agent
registration). Internal observers array is not
re-allocated. This method must be synchronized outside.
removeObserver
in interface MultiObservable
agent
- the observer agent (may be null
) to be unregistered.addObserver(net.sf.ivmaidns.util.Notifiable)
public final boolean hasObservers()
this
observable object has any
observers.
If the result is false
then there is no observers
which must be updated so at this moment it is useless to call
notifyObservers(MultiObservable, Object)
method.
false
only if no observer agents registered.addObserver(net.sf.ivmaidns.util.Notifiable)
,
removeObserver(net.sf.ivmaidns.util.Notifiable)
,
notifyObservers(net.sf.ivmaidns.util.MultiObservable,
java.lang.Object)
public void notifyObservers(MultiObservable observed, java.lang.Object argument) throws java.lang.RuntimeException
update(observed, argument)
for every agent which is
in observers list of this
observable object. The
order of notification is undefined. Important notes: notification
should be done after committing of the occurred modification of
observed; argument object should provide
minimum yet enough information to effectively find out new state
of the object; RuntimeException
(and
OutOfMemoryError
) should be handled properly (since
some of the agents may have already been notified before the
exception is thrown); this method should be called only from the
observable object (so, in subclasses this method should be
overridden with a public
dummy method).
observed
- the observed object (may be null
, but normally
this
).argument
- the argument (may be null
), describing the occurred
event.
java.lang.RuntimeException
- if the notification process for some registered agent has failed
(a custom exception, not all of the agents may have been
notified).
java.lang.OutOfMemoryError
- if there is not enough memory to complete notification (not all
of the agents may have been notified).addObserver(net.sf.ivmaidns.util.Notifiable)
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
this
object.
This method overrides clone()
of Object
to prevent copying of observers list (it is set empty in the
returned observable object). Of course, this method works only
for subclasses which implement Cloneable
interface.
This method may be overridden and made public
in
the subclasses if needed.
clone
in class java.lang.Object
null
) of this
instance.
java.lang.CloneNotSupportedException
- if Cloneable
interface is not implemented (in a
subclass).
java.lang.OutOfMemoryError
- if there is not enough memory.public void integrityCheck()
this
object for its integrity.
Observer agents of this
observable are not checked.
For debug purpose only.
integrityCheck
in interface Verifiable
java.lang.InternalError
- if integrity violation is detected.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |