at.ac.tuwien.infosys.sm4all.copal.api.publisher
Class BasePublisher

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.osgi.GenericActivator
      extended by at.ac.tuwien.infosys.sm4all.copal.api.publisher.BasePublisher
All Implemented Interfaces:
DependencyTrackerCustomizer, ContextPublisher, Observer<RegistryObservable.RegistrationState,ContextEventType>, RegistryObservable.RegistryObserver<ContextEventType>, org.osgi.framework.BundleActivator
Direct Known Subclasses:
PolledPublisher, RESTfulPublisher, SimplePublisher

public abstract class BasePublisher
extends GenericActivator
implements ContextPublisher, RegistryObservable.RegistryObserver<ContextEventType>

Base ContextPublisher that correctly activates itself with COPAL and is able to publish ContextEvents.

Author:
sanjin

Constructor Summary
protected BasePublisher(java.lang.String sourceID, java.lang.String... publishedTypes)
          Creates an instance of base processor with specified source ID and published types as return values for getSourceID() and getPublishedTypes() methods respectively.
 
Method Summary
protected  void add(Attribute attribute)
          Add specified Attribute in all ContextEvents published by this BasePublisher.
protected  void add(Authorization authorization)
          Adds specified Authorization to all ContextEvents published by this BasePublisher.
protected  void appendAction(UnprocessedAction action)
          Appends the specified UnprocessedAction to all ContextEvents published by this BasePublisher.
 java.lang.String[] getPublishedTypes()
          Returns the names of published ContextEventTypes.
 java.lang.String getSourceID()
          Returns the source ID of published ContextEvents.
protected  boolean isStarted(java.lang.String eventType)
          Returns if this BasePublisher is started and can publish ContextEvents of specified type.
protected  void publish(ContextEvent event)
          Publish specified ContextEvent.
protected  void removeAuthorization(java.lang.String method)
          Removes an Authorization that has specified name of AuthorizationMethod from being added to all ContextEvents published by this BasePublisher.
protected  void setPriority(int priority)
          Sets the default priority used for all ContextEvents published by this BasePublisher.
protected  void setTTL(long ttl)
          Sets the default time-to-live used for all ContextEvents published by this BasePublisher.
protected  void start()
          Called when all dependencies are met.
protected abstract  boolean start(ContextEventType type)
          This method is called when PublishingService becomes available for publishing @link ContextEvent}s of the specified ContextEventType.
protected  void stop()
          Called when GenericActivator.start() was previously called and one of the dependencies has been unregistered.
protected abstract  void stop(ContextEventType type)
          This method is called when PublishingService becomes unavailable for publishing ContextEvents of the specified ContextEventType.
protected  void unsetPriority()
          Unsets the default priority.
protected  void unsetTTL()
          Unsets the default time-to-live.
 void update(RegistryObservable.RegistrationState state, ContextEventType eventType)
          Called when specified objects changes its RegistryObservable.RegistrationState with a BaseRegistry.
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.osgi.GenericActivator
addingService, getDependency, modifiedService, register, register, removedService, start, stop, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasePublisher

protected BasePublisher(java.lang.String sourceID,
                        java.lang.String... publishedTypes)
Creates an instance of base processor with specified source ID and published types as return values for getSourceID() and getPublishedTypes() methods respectively.

Parameters:
sourceID - the source ID of this ContextPublisher.
publishedTypes - the names of published ContextEventTypes.
Throws:
java.lang.NullPointerException - if specified source ID or published types array is null.
java.lang.IllegalArgumentException - if specified source ID is an empty or blank string or published types array is empty.
Method Detail

start

protected abstract boolean start(ContextEventType type)
This method is called when PublishingService becomes available for publishing @link ContextEvent}s of the specified ContextEventType. This method should be implemented by specific publishers and is meant as a notification that publisher can start publishing ContextEvents of this ContextEventType.

Parameters:
type - the ContextEventType of published events.
Returns:
if this BasePublisher has been successfully started for specified ContextEventType.

stop

protected abstract void stop(ContextEventType type)
This method is called when PublishingService becomes unavailable for publishing ContextEvents of the specified ContextEventType. This method should be implemented by specific publishers and is meant as a notification that publisher should stop publishing ContextEvents of this ContextEventType.

Parameters:
type - the ContextEventType of published ContextEvents.

getSourceID

public java.lang.String getSourceID()
Description copied from interface: ContextPublisher
Returns the source ID of published ContextEvents.

Specified by:
getSourceID in interface ContextPublisher
Returns:
the source ID of published ContextEvents.

getPublishedTypes

public java.lang.String[] getPublishedTypes()
Description copied from interface: ContextPublisher
Returns the names of published ContextEventTypes.

Specified by:
getPublishedTypes in interface ContextPublisher
Returns:
the names of published ContextEventTypes.

isStarted

protected boolean isStarted(java.lang.String eventType)
Returns if this BasePublisher is started and can publish ContextEvents of specified type.

Parameters:
eventType - the type of ContextEvents.
Returns:
if this BasePublisher is started and can publish ContextEvents.

start

protected void start()
Description copied from class: GenericActivator
Called when all dependencies are met.

Specified by:
start in class GenericActivator

stop

protected void stop()
Description copied from class: GenericActivator
Called when GenericActivator.start() was previously called and one of the dependencies has been unregistered.

Specified by:
stop in class GenericActivator

update

public void update(RegistryObservable.RegistrationState state,
                   ContextEventType eventType)
Description copied from interface: RegistryObservable.RegistryObserver
Called when specified objects changes its RegistryObservable.RegistrationState with a BaseRegistry.

Specified by:
update in interface Observer<RegistryObservable.RegistrationState,ContextEventType>
Specified by:
update in interface RegistryObservable.RegistryObserver<ContextEventType>
Parameters:
state - the RegistryObservable.RegistrationState.
eventType - the changed object.

setTTL

protected void setTTL(long ttl)
Sets the default time-to-live used for all ContextEvents published by this BasePublisher.

Parameters:
ttl - the default time-to-live.

unsetTTL

protected void unsetTTL()
Unsets the default time-to-live.

See Also:
setTTL(long)

setPriority

protected void setPriority(int priority)
Sets the default priority used for all ContextEvents published by this BasePublisher.

Parameters:
priority - the default priority.

unsetPriority

protected void unsetPriority()
Unsets the default priority.

See Also:
setPriority(int)

add

protected void add(Attribute attribute)
Add specified Attribute in all ContextEvents published by this BasePublisher.

Parameters:
attribute - the Attribute.

add

protected void add(Authorization authorization)
Adds specified Authorization to all ContextEvents published by this BasePublisher. If there is already an Authorization with same name of the AuthorizationMethod as specified Authorization, their attributes will be merged with attributes from specified Authorization overwriting ones in already added Authorization.

Parameters:
authorization - the Authorization.

removeAuthorization

protected void removeAuthorization(java.lang.String method)
Removes an Authorization that has specified name of AuthorizationMethod from being added to all ContextEvents published by this BasePublisher.

Parameters:
method - the name of AuthorizationMethod.

appendAction

protected void appendAction(UnprocessedAction action)
Appends the specified UnprocessedAction to all ContextEvents published by this BasePublisher.

Parameters:
action - the UnprocessedAction.

publish

protected void publish(ContextEvent event)
                throws FailedPublishingException
Publish specified ContextEvent.

Parameters:
event - the ContextEvent.
Throws:
FailedPublishingException - if publishing was unsuccessful.


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