edu.uiuc.cs.seclab.modem.xbee
Class XBeeTxnCoord

java.lang.Object
  extended by edu.uiuc.cs.seclab.modem.xbee.XBeeTxnCoord
All Implemented Interfaces:
XBeeModemRecvListener, java.lang.Runnable

public class XBeeTxnCoord
extends java.lang.Object
implements XBeeModemRecvListener, java.lang.Runnable

Coordinates the execution of a list of AT commands. It sends messages individually and asynchronously, and then associates the responses with the appropriate command.


Nested Class Summary
protected  class XBeeTxnCoord.TxnBabysitter
          Thread that waits for a single transaction to complete
 
Field Summary
protected  int babysitterCnt
           
protected  int cnt
           
protected  java.util.concurrent.BlockingQueue<XBeeTxn> completedQ
           
protected  java.lang.Thread coordThread
           
static int DEFL_BACKLOG
           
protected  boolean halted
           
protected  XBeeModem mdm
           
protected  int outstandingTxns
          Number of outstanding transactions tolerated by system
protected  java.util.Stack<XBeeTxnCoord.TxnBabysitter> sitters
           
protected  java.util.concurrent.BlockingQueue<XBeeTxn> toExec
           
static int TXN_TOUT
           
protected  XBeeTxn[] waiting
           
 
Constructor Summary
XBeeTxnCoord(XBeeModem mdm_, int outstandingTxns_)
          Create a command coordinator for a specified list of commands.
 
Method Summary
private  void abortTxn(XBeeTxn txn)
           
private  void completeTxn(XBeeTxn txn)
           
 void execCmd(XBeeAtCmd cmd, XBeeAtCmd.Mode mode, long toutMs)
          Insert a new command transaction into the queue.
 void execTxn(XBeeTxn txn, long toutMs)
          Insert a new transaction into the queue.
protected  void finalize()
           
private  XBeeTxnCoord.TxnBabysitter getBabysitter()
          Get/create an available transaction babysitter.
 java.util.concurrent.BlockingQueue<XBeeTxn> getCompletedQueue()
          Return a reference to the queue for completed transactions, so that the controlling process can synchronously process responses as they are received.
 void halt()
           
 void handleXBeePacket(XBeeApiPacket apiPkt)
           
private  void launchTxn(XBeeTxn txn)
           
private  void recycleBabysitter(XBeeTxnCoord.TxnBabysitter sitter)
           
 void run()
           
 void sendTx(XBeeTxPacket pkt, long toutMs)
          Insert a new transmission transaction into the queue.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

babysitterCnt

protected int babysitterCnt

cnt

protected int cnt

completedQ

protected java.util.concurrent.BlockingQueue<XBeeTxn> completedQ

coordThread

protected java.lang.Thread coordThread

DEFL_BACKLOG

public static final int DEFL_BACKLOG
See Also:
Constant Field Values

halted

protected boolean halted

mdm

protected XBeeModem mdm

outstandingTxns

protected int outstandingTxns
Number of outstanding transactions tolerated by system


sitters

protected java.util.Stack<XBeeTxnCoord.TxnBabysitter> sitters

toExec

protected java.util.concurrent.BlockingQueue<XBeeTxn> toExec

TXN_TOUT

public static final int TXN_TOUT
See Also:
Constant Field Values

waiting

protected XBeeTxn[] waiting
Constructor Detail

XBeeTxnCoord

public XBeeTxnCoord(XBeeModem mdm_,
                    int outstandingTxns_)
             throws ModemException,
                    java.io.IOException
Create a command coordinator for a specified list of commands. Must be a linked list for efficiency.

Throws:
java.io.IOException - getBabysitter().setTxn(txn, TXN_TOUT);
ModemException
Method Detail

abortTxn

private void abortTxn(XBeeTxn txn)

completeTxn

private void completeTxn(XBeeTxn txn)

execCmd

public void execCmd(XBeeAtCmd cmd,
                    XBeeAtCmd.Mode mode,
                    long toutMs)
             throws ModemException
Insert a new command transaction into the queue. Will block if desired frame ID is still outstanding in the mode. Will block up to toutMs milliseconds, or indefinitely if toutMs == 0.

Throws:
ModemException

execTxn

public void execTxn(XBeeTxn txn,
                    long toutMs)
             throws ModemException
Insert a new transaction into the queue.

Throws:
ModemException

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getBabysitter

private XBeeTxnCoord.TxnBabysitter getBabysitter()
Get/create an available transaction babysitter.


getCompletedQueue

public java.util.concurrent.BlockingQueue<XBeeTxn> getCompletedQueue()
Return a reference to the queue for completed transactions, so that the controlling process can synchronously process responses as they are received. Also returns aborted transactions, so it's important to manually verify that transactions have actually completed.


halt

public void halt()

handleXBeePacket

public void handleXBeePacket(XBeeApiPacket apiPkt)
Specified by:
handleXBeePacket in interface XBeeModemRecvListener

launchTxn

private void launchTxn(XBeeTxn txn)
                throws ModemException,
                       java.io.IOException
Throws:
ModemException
java.io.IOException

recycleBabysitter

private void recycleBabysitter(XBeeTxnCoord.TxnBabysitter sitter)

run

public void run()
Specified by:
run in interface java.lang.Runnable

sendTx

public void sendTx(XBeeTxPacket pkt,
                   long toutMs)
            throws ModemException
Insert a new transmission transaction into the queue.

Throws:
ModemException