org.universAAL.middleware.bus.model
Class BusStrategy

Package class diagram package BusStrategy
java.lang.Object
  extended by java.lang.Thread
      extended by org.universAAL.middleware.bus.model.BusStrategy
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ContextStrategy, EventBasedStrategy, ServiceStrategy

public abstract class BusStrategy
extends Thread

A bus strategy for handling messages. Subclasses must implement their strategy within the handle(Message) method.

Author:
mtazari - Saied Tazari

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  AbstractBus bus
           
protected  ModuleContext busModule
           
protected  CommunicationModule commModule
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected BusStrategy(CommunicationModule commModule)
          Constructor receiving the CommunicationModule instance and creating queue for the messages.
protected BusStrategy(CommunicationModule commModule, String name)
          Constructor receiving the CommunicationModule instance and creating queue for the messages.
 
Method Summary
protected  ChannelMessage buildChannelMessage(BusMessage m)
           
protected  BusMember getBusMember(String memberID)
          Returns bus member instance based on the bus member ID.
protected  AbstractBus getLocalBusByName(String name)
          Returns bus based on the passed bus name.
protected abstract  void handle(BusMessage m, String senderID)
          Handle the message.
 void handleMessage(BusMessage m, String senderID)
          This method handles the message asynchronously, while trying to preserve the order of the messages from the same source, according to the counters of the messages.
 void run()
          Runs BusStrategy.
protected  void send(BusMessage message)
           
 void setBus(AbstractBus bus)
          Joins the bus and the BusStrategy.
 void stopThread()
          Stops BusStrategy Thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bus

protected AbstractBus bus

busModule

protected ModuleContext busModule

commModule

protected CommunicationModule commModule
Constructor Detail

BusStrategy

protected BusStrategy(CommunicationModule commModule)
Constructor receiving the CommunicationModule instance and creating queue for the messages.

Parameters:
commModule - CommunicationModule instance

BusStrategy

protected BusStrategy(CommunicationModule commModule,
                      String name)
Constructor receiving the CommunicationModule instance and creating queue for the messages.

Parameters:
commModule - CommunicationModule instance
name - Human-readable name of the Bus Strategy
Method Detail

getBusMember

protected BusMember getBusMember(String memberID)
Returns bus member instance based on the bus member ID.

Parameters:
memberID - bus member ID
Returns:
BusMember

handle

protected abstract void handle(BusMessage m,
                               String senderID)
Handle the message. This method is different from the handleMessage(), in that handeMessage() handle the message asynchronously, while queuing the messages to preserve the order of the messages. This method is executed synchronously, without any queuing.

Parameters:
m - message
senderID - sender (bus member) ID

getLocalBusByName

protected AbstractBus getLocalBusByName(String name)
Returns bus based on the passed bus name.

Parameters:
name - bus name
Returns:
bus

handleMessage

public final void handleMessage(BusMessage m,
                                String senderID)
This method handles the message asynchronously, while trying to preserve the order of the messages from the same source, according to the counters of the messages. (The counters are part of the message ID). The messages are queued, and they are inserted into the queue according to their counter.

Parameters:
m - message to be handled
senderID - sender ID

run

public final void run()
Runs BusStrategy. Until stopping process messages (in separate Threads)

Specified by:
run in interface Runnable
Overrides:
run in class Thread

setBus

public void setBus(AbstractBus bus)
Joins the bus and the BusStrategy.

Parameters:
bus - bus

stopThread

public final void stopThread()
Stops BusStrategy Thread.


buildChannelMessage

protected ChannelMessage buildChannelMessage(BusMessage m)

send

protected void send(BusMessage message)


Copyright © 2014 universAAL Consortium. All Rights Reserved.