cat.app
Class ContextApp

java.lang.Object
  extended bycat.app.ContextApp
All Implemented Interfaces:
java.lang.Runnable, SensorListener, SigListener

public abstract class ContextApp
extends java.lang.Object
implements SigListener, SensorListener

This class is a template for building applications using CAT. It implements a few useful features (which can be overwritten) and defines what needs to be implemented.


Field Summary
private  java.util.Vector eventsQueue
          Keep a queue of sensor events, for processing in a thread.
private  ContextManager manager
          The ContextManager for this wearable application.
 
Constructor Summary
ContextApp(java.lang.String id, int port)
          This constructor will start the application.
 
Method Summary
 void appSetUp()
          This method sets up the basic information for the application.
 ContextManager getContextManager()
          Returns the Context Manager for the app to use.
 java.util.Vector getSensorQueue()
          Returns a list of non-processed sensor events.
 void handleSigEvent(SigEvent ce)
          This method gets SIG events, it can process most of the information itself, and then it merely asks the extending application if it would like to join a SIG, or to inform it of an agent that joined.
abstract  void joinedSig(java.lang.String name, Agent agent)
          This method gets called when an agent joined a SIG that you part of.
abstract  boolean joinSig(java.lang.String name, java.util.Vector agents, java.util.Vector wanted_sensors, java.util.Vector sharing_sensors)
          This method gets called when app receives a SIG join request.
static void p2pSend(Agent agent, java.lang.Object obj)
          This method can be used to send p2p communication.
abstract  void run()
          This method is for handling sensor events.
 void update(java.lang.Object event)
          Get sensor events in here.
 void willJoinSig(java.lang.String s, java.util.Vector a, java.util.Vector wanted, java.util.Vector sharing)
          This method tells the ContextApp, that the app wants to join the given SIG.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eventsQueue

private java.util.Vector eventsQueue
Keep a queue of sensor events, for processing in a thread. Prevents this app from being a bottleneck in event passing.


manager

private ContextManager manager
The ContextManager for this wearable application.

Constructor Detail

ContextApp

public ContextApp(java.lang.String id,
                  int port)
This constructor will start the application. It will call a setup method which signs us up as a listener to sensors. And the rest is up to whoever extends this class.

Parameters:
id - The unique of this agent/device.
port - The port number that CAT will use to communicate.
Method Detail

appSetUp

public void appSetUp()
This method sets up the basic information for the application. It creates the ContextManagaer, and signs up us as a sensor listener to all sensors. (note: soft sensors have not been created yet, that is up to whoever extends this class)


p2pSend

public static void p2pSend(Agent agent,
                           java.lang.Object obj)
This method can be used to send p2p communication. Can send any serializable object to the given peer/agent.

Parameters:
agent - The agent to send a message/object to.
obj - The object to send to the agent.

joinSig

public abstract boolean joinSig(java.lang.String name,
                                java.util.Vector agents,
                                java.util.Vector wanted_sensors,
                                java.util.Vector sharing_sensors)
This method gets called when app receives a SIG join request.


joinedSig

public abstract void joinedSig(java.lang.String name,
                               Agent agent)
This method gets called when an agent joined a SIG that you part of.

Parameters:
name - The name of the SIG that agent joined.
agent - The agent that joined the SIG that you are part of.

handleSigEvent

public void handleSigEvent(SigEvent ce)
This method gets SIG events, it can process most of the information itself, and then it merely asks the extending application if it would like to join a SIG, or to inform it of an agent that joined.

Specified by:
handleSigEvent in interface SigListener
Parameters:
ce - The incoming SIG event

willJoinSig

public void willJoinSig(java.lang.String s,
                        java.util.Vector a,
                        java.util.Vector wanted,
                        java.util.Vector sharing)
This method tells the ContextApp, that the app wants to join the given SIG. This abstract class can then handle the details of joining the SIG.

Parameters:
s - SIG name.
a - Agents in SIG.
wanted - Sensors wanted for SIG.
sharing - Sensors giving to SIG.

run

public abstract void run()
This method is for handling sensor events.

Specified by:
run in interface java.lang.Runnable

update

public void update(java.lang.Object event)
Get sensor events in here.

Specified by:
update in interface SensorListener
Parameters:
event - The sensor data.

getContextManager

public ContextManager getContextManager()
Returns the Context Manager for the app to use.


getSensorQueue

public java.util.Vector getSensorQueue()
Returns a list of non-processed sensor events.