at.ac.tuwien.infosys.sm4all.copal.api.event
Class ContextEvent

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.event.BaseEvent
      extended by at.ac.tuwien.infosys.sm4all.copal.api.event.ContextEvent
Direct Known Subclasses:
XMLContextEvent

public class ContextEvent
extends BaseEvent

Class which contains meta-data for all context events. This class is not thread safe.

Author:
fei, sanjin

Constructor Summary
protected ContextEvent(ContextEventType type, java.lang.String sourceID, java.util.Date timeStamp)
          Create instance of ContextEvent with specified ContextEventType, source ID, and time stamp.
 
Method Summary
 void add(Attribute attribute)
          Add specified Attribute into this ContextEvent.
 void add(Authorization authorization)
          Adds specified Authorization into this ContextEvent.
 boolean equals(java.lang.Object obj)
          Compares this ContextEvent to the specified Object.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of ContextEvent Attribute that has specified name.
 Attribute[] getAttributes()
          Returns all currently added Attributes.
 Authorization getAuthorization(java.lang.String method)
          Returns the Authorization that has specified name of AuthorizationMethod.
 Authorization[] getAuthorizations()
          Returns all currently added Authorizations.
 int getPriority()
          Returns the priority of this ContextEventType.
 long getTTL()
          Returns the time-to-live in milliseconds of this ContextEventType .
 ContextEventType getType()
          Returns the ContextEventType associated with this ContextEvent.
 boolean hasAttribute(java.lang.String name)
          Returns if an Attribute that has specified name is currently present in this ContextEvent.
 boolean hasAuthorization(java.lang.String method)
          Returns if an Authorization that has specified name of AuthorizationMethod is currently present in this ContextEvent.
 boolean hasAuthorizations()
          Returns if there is any added Authorization in this ContextEvent.
 int hashCode()
          Returns hash code for this ContextEvent.
 boolean isStale()
          Returns if this ContextEvent is stale (i.e.
 void removeAttribute(java.lang.String name)
          Remove an Attribute that has specified from this ContextEvent.
 void removeAuthorization(java.lang.String method)
          Removes an Authorization that has specified name of AuthorizationMethod from this ContextEvent.
protected  void set(Attribute... attributes)
          Add specified Attributes and remove all previously registered Attributes.
protected  void set(Authorization... authorizations)
          Add specified Authorizations and remove all previously registered Authorizations.
 void setPriority(int priority)
          Sets the priority of this ContextEventType.
 void setTTL(long ttl)
          Sets the time-to-live of this ContextEventType.
 
Methods inherited from class at.ac.tuwien.infosys.sm4all.copal.api.event.BaseEvent
append, getAction, getActions, getCurrentAction, getCurrentActionIndex, getNumberOfActions, getSourceID, getTimeStamp, hasAction, insert, nextAction, removeAction, replace, set
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextEvent

protected ContextEvent(ContextEventType type,
                       java.lang.String sourceID,
                       java.util.Date timeStamp)
Create instance of ContextEvent with specified ContextEventType, source ID, and time stamp. TTL and priority are set to specified ContextEventType time-to-live and priority respectively.

Parameters:
type - the ContextEventType.
sourceID - the source ID of the ContextEvent.
timeStamp - the time stamp for the ContextEvent.
Throws:
java.lang.NullPointerException - if specified type, source ID or time stamp is null.
java.lang.IllegalArgumentException - if specified source ID is an empty or blank string.
Method Detail

getType

public ContextEventType getType()
Returns the ContextEventType associated with this ContextEvent.

Returns:
the ContextEventType associated with this ContextEvent.

getTTL

public long getTTL()
Returns the time-to-live in milliseconds of this ContextEventType .

Returns:
the time-to-live in milliseconds of this ContextEventType .

setTTL

public void setTTL(long ttl)
Sets the time-to-live of this ContextEventType. The specified value represents time in milliseconds. If specified value is negative then time-to-live will be set to zero. Value of zero means that time-to-live is indefinite, i.e. the ContextEvent never gets old.

Parameters:
ttl - the time-to-live of this ContextEventType.

isStale

public boolean isStale()
Returns if this ContextEvent is stale (i.e. time-stamp + time-to-live < current time).

Returns:
if this ContextEvent is stale.

getPriority

public int getPriority()
Returns the priority of this ContextEventType.

Returns:
the priority of this ContextEventType.

setPriority

public void setPriority(int priority)
Sets the priority of this ContextEventType. If specified value is greater than ContextEventType.PRIORITY_MAX than the priority will be set to ContextEventType.PRIORITY_MAX. If specified value is less than ContextEventType.PRIORITY_MIN than the priority will be set to ContextEventType.PRIORITY_MIN

Parameters:
priority - the priority of this ContextEventType.

add

public void add(Attribute attribute)
Add specified Attribute into this ContextEvent. If there is already an Attribute with same name as specified Attribute, specified Attribute will overwrite Attribute that is already added.

Parameters:
attribute - the Attribute.

removeAttribute

public void removeAttribute(java.lang.String name)
Remove an Attribute that has specified from this ContextEvent.

Parameters:
name - the name of Attribute.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value of ContextEvent Attribute that has specified name. If this ContextEventType does not have Attribute with specified name, null will be returned.

Parameters:
name - the name of the Attribute.
Returns:
the value of Attribute or null if there is no such Attribute.

getAttributes

public Attribute[] getAttributes()
Returns all currently added Attributes.

Returns:
all currently added Attributes.

hasAttribute

public boolean hasAttribute(java.lang.String name)
Returns if an Attribute that has specified name is currently present in this ContextEvent. If the Attribute was never added (or was added and consequently removed by adding it with null value), false will be returned; otherwise true will be returned.

Parameters:
name - the name of Attribute.
Returns:
if an Attribute that has specified name is currently present in this ContextEvent.

set

protected void set(Attribute... attributes)
Add specified Attributes and remove all previously registered Attributes.

Parameters:
attributes - Attributes.

add

public void add(Authorization authorization)
Adds specified Authorization into this ContextEvent. 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

public void removeAuthorization(java.lang.String method)
Removes an Authorization that has specified name of AuthorizationMethod from this ContextEvent.

Parameters:
method - the name of AuthorizationMethod.

getAuthorization

public Authorization getAuthorization(java.lang.String method)
Returns the Authorization that has specified name of AuthorizationMethod. If this ContextEventType does not have Authorization with specified name AuthorizationMethod, null will be returned.

Parameters:
method - the name of AuthorizationMethod.
Returns:
the Authorization; or null if there is no such Authorization.

getAuthorizations

public Authorization[] getAuthorizations()
Returns all currently added Authorizations.

Returns:
all currently added Authorizations.

hasAuthorization

public boolean hasAuthorization(java.lang.String method)
Returns if an Authorization that has specified name of AuthorizationMethod is currently present in this ContextEvent. If the Authorization was never added (or was added and consequently removed), false will be returned; otherwise true will be returned.

Parameters:
method - the name of AuthorizationMethod.
Returns:
if an Authorization that has specified name of AuthorizationMethod is currently present in this ContextEvent.

hasAuthorizations

public boolean hasAuthorizations()
Returns if there is any added Authorization in this ContextEvent.

Returns:
if there is any added Authorization in this ContextEvent.

set

protected void set(Authorization... authorizations)
Add specified Authorizations and remove all previously registered Authorizations.

Parameters:
authorizations - Authorizations.

hashCode

public int hashCode()
Returns hash code for this ContextEvent. The hash code for a ContextEvent object is computed as:
 type * 31 + super
 
using integer arithmetic.

Overrides:
hashCode in class BaseEvent
Returns:
a hash code value for this ContextEvent.

equals

public boolean equals(java.lang.Object obj)
Compares this ContextEvent to the specified Object. The result is true if and only if the argument is not null and is a ContextEvent object that has same type, source ID, and time stamp as this ContextEvent.

Overrides:
equals in class BaseEvent
Parameters:
obj - the Object to compare this ContextEvent against.
Returns:
true if this ContextEvents are equal; false otherwise.


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