org.universAAL.middleware.ui.impl.generic
Class CallBasedStrategy

Package class diagram package CallBasedStrategy
java.lang.Object
  extended by java.lang.Thread
      extended by org.universAAL.middleware.bus.model.BusStrategy
          extended by org.universAAL.middleware.ui.impl.generic.EventBasedStrategy
              extended by org.universAAL.middleware.ui.impl.generic.CallBasedStrategy
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
CoordinatedStrategy

public class CallBasedStrategy
extends EventBasedStrategy

A set of methods to place calls and responses, both for synchronous and asynchronous calls.

Author:
amedrano

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class org.universAAL.middleware.bus.model.BusStrategy
bus, busModule, commModule
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CallBasedStrategy(CommunicationModule commModule)
           
CallBasedStrategy(CommunicationModule commModule, String name)
           
 
Method Summary
 void abortAll()
          Abort all pending calls,
 void abortCall(String msgId)
          Abort the call with the given ID. it unblocks the call and the CallSynchronizer#performCall(Object, Object) will throw a InterruptedException.
protected  void handle(BusMessage m, String senderID)
          
protected  void placeAsynchronousRequest(PeerCard peer, CallMessage<? extends CallBasedStrategy> callMessage)
          Send an asynchronous request to memberID.
protected  void placeAsynchronousRequest(String memberID, CallMessage<? extends CallBasedStrategy> callMessage)
          Send an asynchronous request to memberID.
protected  Object placeSynchronousRequest(PeerCard peer, CallMessage<? extends CallBasedStrategy> callMessage)
          Place a Synchronous request, The CallMessage is sent and the message is anotated as waiting for response, the calling thread will be set in a waiting state until either a response to the message is received, or the call is aborted.
protected  Object placeSynchronousRequest(String memberID, CallMessage<? extends CallBasedStrategy> callMessage)
          Place a Synchronous request, The CallMessage is sent and the message is anotated as waiting for response, the calling thread will be set in a waiting state until either a response to the message is received, or the call is aborted.
 void sendAsynchronousResponse(PeerCard peer, CallMessage<? extends CallBasedStrategy> response)
           
 void sendAsynchronousResponse(String memberID, CallMessage<? extends CallBasedStrategy> response)
           
 void sendSynchronousResponse(BusMessage original, Object resp)
          For use of CallMessage subclasses to send a response to the call.
 
Methods inherited from class org.universAAL.middleware.ui.impl.generic.EventBasedStrategy
sendEventToRemoteBusMember, sendEventToRemoteBusMember, sendEventToRemoteBusMember, sendEventToRemoteBusMember, sendEventToRemoteBusMember
 
Methods inherited from class org.universAAL.middleware.bus.model.BusStrategy
buildChannelMessage, getBusMember, getLocalBusByName, handleMessage, run, send, setBus, stopThread
 
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
 

Constructor Detail

CallBasedStrategy

public CallBasedStrategy(CommunicationModule commModule,
                         String name)
Parameters:
commModule -
name -

CallBasedStrategy

public CallBasedStrategy(CommunicationModule commModule)
Parameters:
commModule -
Method Detail

handle

protected void handle(BusMessage m,
                      String senderID)

Overrides:
handle in class EventBasedStrategy
Parameters:
m - message
senderID - sender (bus member) ID

placeSynchronousRequest

protected Object placeSynchronousRequest(String memberID,
                                         CallMessage<? extends CallBasedStrategy> callMessage)
                                  throws InterruptedException
Place a Synchronous request, The CallMessage is sent and the message is anotated as waiting for response, the calling thread will be set in a waiting state until either a response to the message is received, or the call is aborted.

Parameters:
memberID - The recipient of the request
callMessage - The Message to send.
Returns:
the response to the message
Throws:
InterruptedException - if the call was aborted.

placeAsynchronousRequest

protected void placeAsynchronousRequest(String memberID,
                                        CallMessage<? extends CallBasedStrategy> callMessage)
Send an asynchronous request to memberID. This method will not store the call thus the response has to be able to perform the response part by it self, by for example replying a EventMessage or a CallMessage the onResponse will have to manage.

Parameters:
memberID -
callMessage -

placeSynchronousRequest

protected Object placeSynchronousRequest(PeerCard peer,
                                         CallMessage<? extends CallBasedStrategy> callMessage)
                                  throws InterruptedException
Place a Synchronous request, The CallMessage is sent and the message is anotated as waiting for response, the calling thread will be set in a waiting state until either a response to the message is received, or the call is aborted.

Parameters:
memberID - The recipient of the request
callMessage - The Message to send.
Returns:
the response to the message
Throws:
InterruptedException - if the call was aborted.

placeAsynchronousRequest

protected void placeAsynchronousRequest(PeerCard peer,
                                        CallMessage<? extends CallBasedStrategy> callMessage)
Send an asynchronous request to memberID. This method will not store the call thus the response has to be able to perform the response part by it self, by for example replying a EventMessage or a CallMessage the onResponse will have to manage.

Parameters:
memberID -
callMessage -

abortCall

public void abortCall(String msgId)
Abort the call with the given ID. it unblocks the call and the CallSynchronizer#performCall(Object, Object) will throw a InterruptedException.

Parameters:
msgId - the messageId of the call that should be aborted.

abortAll

public void abortAll()
Abort all pending calls,


sendSynchronousResponse

public void sendSynchronousResponse(BusMessage original,
                                    Object resp)
For use of CallMessage subclasses to send a response to the call.

Parameters:
original -
resp -

sendAsynchronousResponse

public void sendAsynchronousResponse(PeerCard peer,
                                     CallMessage<? extends CallBasedStrategy> response)

sendAsynchronousResponse

public void sendAsynchronousResponse(String memberID,
                                     CallMessage<? extends CallBasedStrategy> response)


Copyright © 2014 universAAL Consortium. All Rights Reserved.