at.ac.tuwien.infosys.sm4all.copal.api.query
Class ProcessedEventQuery

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.util.BaseObservable<QueryState,ContextQuery,QueryObserver>
      extended by at.ac.tuwien.infosys.sm4all.copal.api.query.ContextQuery
          extended by at.ac.tuwien.infosys.sm4all.copal.api.query.ProcessedEventQuery
All Implemented Interfaces:
Observable<QueryState,ContextQuery,QueryObserver>, Registry<java.lang.String,ContextListener>, org.osgi.framework.BundleActivator

public class ProcessedEventQuery
extends ContextQuery
implements Registry<java.lang.String,ContextListener>

This class is used with the ContextListeners to create queries which listen on occurrence of processed events (i.e. events for which all ContextEventActions are finished}.

Author:
sanjin

Constructor Summary
ProcessedEventQuery(java.lang.String name, java.lang.String listenedType)
          Create instance of query for processed events.
ProcessedEventQuery(java.lang.String name, java.lang.String listenedType, java.lang.String criteria)
          Create instance of the query for processed events.
 
Method Summary
 void destroy()
          Destroys this ContextQuery.
 ContextListener get(java.lang.String listenerName)
          Returns ContextListener with specified name or null if there is no such ContextListener registered.
 ContextListener[] getAll()
          Returns all currently registered ContextListeners.
 boolean isRegistered(java.lang.String listenerName)
          Returns if a ContextListener with specified name is currently registered.
 void onEvent(ContextEvent event)
          This method is called when a ContextEvent with same event name occurs for which the criteria is satisfied.
 void register(ContextListener listener)
          Register specified ContextListener with this ProcessedEventQuery.
 void start(org.osgi.framework.BundleContext bundleContext)
           
 void stop(org.osgi.framework.BundleContext bundleContext)
           
 void unregister(java.lang.String listenerName)
          Unregister ContextListener with specified name from this ProcessedEventQuery.
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.query.ContextQuery
attach, equals, getCriteria, getListenedType, getName, hasCriteria, hashCode, isDestroyed
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.util.BaseObservable
detach, detachAll, getObservers, notifyAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessedEventQuery

public ProcessedEventQuery(java.lang.String name,
                           java.lang.String listenedType)
Create instance of query for processed events. The name should be globally unique, meaning that if two context query have same name then their listenedTypes and criterias are equal. The listenedType is name of ContextEventType to be caught.

Parameters:
name - the globally unique name of the query.
listenedType - the name of listened ContextEventType.
Throws:
java.lang.NullPointerException - if specified name or event name is null.
java.lang.IllegalArgumentException - if specified name or event name is an empty or blank string.

ProcessedEventQuery

public ProcessedEventQuery(java.lang.String name,
                           java.lang.String listenedType,
                           java.lang.String criteria)
Create instance of the query for processed events. The name should be globally unique, meaning that if two context queries have same name then their listenedTypes and criterias are equal. The listenedType is name of ContextEventType on which criteria is executed. The criteria is the logical statement which further separates the processed events of interest. If query should catch all listenedType events, we set criteria to be null or blank string or use ContextQuery(String, String) constructor.

Parameters:
name - the globally unique name of the query.
listenedType - the name of listened ContextEventType.
criteria - the logical expression.
Throws:
java.lang.NullPointerException - if specified name or event name is null.
java.lang.IllegalArgumentException - if specified name or event name is an empty or blank string.
Method Detail

start

public final void start(org.osgi.framework.BundleContext bundleContext)
Specified by:
start in interface org.osgi.framework.BundleActivator
Specified by:
start in class ContextQuery

stop

public final void stop(org.osgi.framework.BundleContext bundleContext)
Specified by:
stop in interface org.osgi.framework.BundleActivator
Specified by:
stop in class ContextQuery

destroy

public void destroy()
             throws QueryDestroyedException
Description copied from class: ContextQuery
Destroys this ContextQuery. All registered ContextListeners will be unregistered and any future registration of a ContextListener and receiving of events will not be possible.

Overrides:
destroy in class ContextQuery
Throws:
QueryDestroyedException - if ContextQuery has been already destroyed.

onEvent

public void onEvent(ContextEvent event)
             throws QueryDestroyedException
Description copied from class: ContextQuery
This method is called when a ContextEvent with same event name occurs for which the criteria is satisfied. This method in return calls all registered ContextListeners with specified ContextEvent.

Specified by:
onEvent in class ContextQuery
Parameters:
event - the occurred ContextEvent.
Throws:
QueryDestroyedException - if ContextQuery has been previously destroyed.

register

public void register(ContextListener listener)
              throws AlreadyRegisteredException,
                     QueryDestroyedException
Register specified ContextListener with this ProcessedEventQuery. If ContextEvent is caught, for which the criteria evaluates to true, the specified ContextListener will be invoked.

Specified by:
register in interface Registry<java.lang.String,ContextListener>
Parameters:
listener - the ContextListener.
Throws:
AlreadyRegisteredException - if a ContextListener with same name is already registered.
java.lang.NullPointerException - if specified ContextListener is null.
QueryDestroyedException - if this ProcessedEventQuery has been previously destroyed.

unregister

public void unregister(java.lang.String listenerName)
                throws NotRegisteredException
Unregister ContextListener with specified name from this ProcessedEventQuery. The ContextListener will not receive any further ContextEvents from this ProcessedEventQuery.

Specified by:
unregister in interface Registry<java.lang.String,ContextListener>
Parameters:
listenerName - the name of the ContextListener.
Throws:
NotRegisteredException - if a ContextListener with specified name is not registered.
java.lang.NullPointerException - if specified name of the ContextListener is null.

isRegistered

public boolean isRegistered(java.lang.String listenerName)
Returns if a ContextListener with specified name is currently registered.

Specified by:
isRegistered in interface Registry<java.lang.String,ContextListener>
Parameters:
listenerName - the name of the ContextListener.
Returns:
if a ContextListener with specified name is currently registered.
Throws:
java.lang.NullPointerException - if specified name of ContextListener is null.

get

public ContextListener get(java.lang.String listenerName)
Returns ContextListener with specified name or null if there is no such ContextListener registered.

Specified by:
get in interface Registry<java.lang.String,ContextListener>
Parameters:
listenerName - the name of the ContextListener.
Returns:
the ContextListener or null if there is no such ContextListener registered.
Throws:
java.lang.NullPointerException - if specified name of ContextListener is null.

getAll

public ContextListener[] getAll()
Returns all currently registered ContextListeners.

Specified by:
getAll in interface Registry<java.lang.String,ContextListener>
Returns:
all currently registered ContextListeners.


Copyright © 2010 Distributed Systems Group, Vienna University of Technology. All Rights Reserved.