public class CasaObservableObject extends Observable implements CasaObservable, Comparable<CasaObservableObject>
Copyright: Copyright 2003-2014, Knowledge Science Group, University of Calgary. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The Knowledge Science Group makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
Modifier and Type | Class and Description |
---|---|
(package private) class |
CasaObservableObject.ObserverComparator |
Modifier and Type | Field and Description |
---|---|
private AbstractProcess |
agent
The "owner" agent
|
private TreeMap<Observer,String[]> |
localObservers
Observers that we will notify via just the same as
Observable would. |
private TreeMap<URLDescriptor,String[]> |
remoteObservers
Observers on other machines or other process that we will notify via the
casa messaging system.
|
private URLDescriptor |
url
The url or the owner agent
|
Constructor and Description |
---|
CasaObservableObject(URLDescriptor url,
AbstractProcess agent) |
Modifier and Type | Method and Description |
---|---|
void |
addObserver(Observer o)
Adds an observer to the set of observers for this object, provided that
it is not the same as some observer already in the set.
|
void |
addObserver(Observer o,
String... notifyTypes)
Adds an observer to the set of observers for this object, provided that
it is not the same as some observer already in the set.
|
void |
addObserver(URLDescriptor observer,
String... notifyTypes)
Description: add an observer along with the type of event it wishes to be
notified about.
|
int |
compareTo(CasaObservableObject o) |
int |
countLocalObservers()
Returns the number of local observers of this Observable object.
|
int |
countObservers()
Returns the number of observers of this Observable object.
|
int |
countRemoteObservers()
Returns the number of remote observers of this Observable
object.
|
void |
deleteObserver(Observer o)
Deletes an observer from the set of observers of this object.
|
void |
deleteObserver(URLDescriptor observer) |
void |
deleteObservers()
Clears the observer list so that this object no longer has any observers.
|
ProcessInterface |
getAgent() |
URLDescriptor |
getURL() |
private String[] |
merge(String[] a,
String[] b)
Merges two event lists.
|
void |
notifyObservers()
Calls
notifyObservers(String, Object) with the first parameter
as ML.TOP, and the second parameter as null. |
void |
notifyObservers(Object arg)
Calls
notifyObservers(String, Object) with the first parameter
as ML.TOP, and the second parameter as arg. |
void |
notifyObservers(String notifyType,
Object arg)
|
void |
notifyObserversWithNoArg(String notifyType)
Calls
notifyObservers(String, Object) with the first parameter
as the argument notifyType and the second argument as null. |
void |
notifyObserversWithTop(Object arg)
Calls
notifyObservers(String, Object) with the first parameter
as ML.TOP, and the second parameter as the argument, arg. |
clearChanged, hasChanged, setChanged
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
hasChanged
private final URLDescriptor url
private final AbstractProcess agent
private TreeMap<URLDescriptor,String[]> remoteObservers
private TreeMap<Observer,String[]> localObservers
Observable
would. However, this is TreeMap of observers
as keys, the key value is either null (meaning
"send me all notifications") or a LinkedList of all the types (in the
casa ontology) for which the observer wants to receive notifications. Any
notification that is a a subtype of the registered type will also be
sent.public CasaObservableObject(URLDescriptor url, AbstractProcess agent)
url
- The URL of the "owner" agentagent
- The "owner" agentpublic URLDescriptor getURL()
public ProcessInterface getAgent()
public void notifyObservers()
notifyObservers(String, Object)
with the first parameter
as ML.TOP, and the second parameter as null.notifyObservers
in interface CasaObservable
notifyObservers
in class Observable
Observable.clearChanged()
,
Observable.hasChanged()
,
Observer.update(java.util.Observable, java.lang.Object)
,
notifyObservers(String, Object)
public void notifyObservers(Object arg)
notifyObservers(String, Object)
with the first parameter
as ML.TOP, and the second parameter as arg.notifyObservers
in class Observable
arg
- any object.Observable.clearChanged()
,
Observable.hasChanged()
,
Observer.update(java.util.Observable, java.lang.Object)
,
notifyObservers(String, Object)
public void notifyObserversWithTop(Object arg)
notifyObservers(String, Object)
with the first parameter
as ML.TOP, and the second parameter as the argument, arg.notifyObserversWithTop
in interface CasaObservable
arg
- any object.Observable.clearChanged()
,
Observable.hasChanged()
,
Observer.update(java.util.Observable, java.lang.Object)
,
notifyObservers(String, Object)
public void notifyObserversWithNoArg(String notifyType)
notifyObservers(String, Object)
with the first parameter
as the argument notifyType and the second argument as null.notifyObserversWithNoArg
in interface CasaObservable
notifyType
- The type (classification) of this notification; must be a type
for the ontology.Observable.clearChanged()
,
Observable.hasChanged()
,
Observer.update(java.util.Observable, java.lang.Object)
,
notifyObservers(String, Object)
public void notifyObservers(String notifyType, Object arg)
local
and
remote
) in the same manner as
Observable.notifyObservers(Object)
. However, filter the
notifications based on what notifications observer wants to receive
(based on when the observer registered). Any notification that is a
subtype of the registered type will also be sent.
This method will always construct a ObserverNotification
object
as the "object" argument of the
Observer.update(java.util.Observable, Object)
call.
Note that the Observable argument will NOT be the agent, but will be this
CasaObservable object (one can get the agent from the
ObserverNotification
object.
notifyObservers
in interface CasaObservable
notifyType
- The type (classification) of this notification; must be a type
for the ontology.arg
- An argument to pass to the observer in the update() method in
the ObserverNotification object.private final String[] merge(String[] a, String[] b)
a
- the first list to mergeb
- the second list to mergepublic void addObserver(URLDescriptor observer, String... notifyTypes)
TODO: rkyee: Be careful with this! You can cause an infinite inform loop
addObserver
in interface CasaObservable
public void deleteObserver(URLDescriptor observer)
deleteObserver
in interface CasaObservable
public void addObserver(Observer o)
addObserver
in class Observable
o
- an observer to be added.NullPointerException
- if the parameter o is null.public void addObserver(Observer o, String... notifyTypes)
addObserver
in interface CasaObservable
o
- an observer to be added.NullPointerException
- if the parameter o is null.public void deleteObserver(Observer o)
null
to this method will have no effect.deleteObserver
in interface CasaObservable
deleteObserver
in class Observable
o
- the observer to be deleted.public void deleteObservers()
deleteObservers
in interface CasaObservable
deleteObservers
in class Observable
public int countObservers()
countObservers
in interface CasaObservable
countObservers
in class Observable
public int countLocalObservers()
public int countRemoteObservers()
public int compareTo(CasaObservableObject o)
compareTo
in interface Comparable<CasaObservableObject>