All Packages  This Package  Class Hierarchy  Class Search  Index

Class edu.utah.janos.antsr.core.UnknownMidPackets
java.lang.Object
   |
   +----edu.utah.janos.antsr.core.UnknownMidPackets

  Summary

class  UnknownMidPackets
     extends java.lang.Object
{
          // Fields 5
     private static final int MIDMAPSIZE;
     static final int NEVER_DEMULTIPLEXED;
     private static final int PACKETS_PER_SPACE;
     final CommSpaceHandle midToSpaceMap;
     private int nextSpace;

          // Constructors 2
     UnknownMidPackets();
     UnknownMidPackets(CommSpaceHandle);

          // Methods 3
     synchronized boolean addPacket(byte[], BufferHandle);
     void setInChannel(byte[], InChannelHandle);
     private CommSpaceHandle spaceForMID(byte[]);
}

UnknownMidPackets is a temporary storage place for packets of unknown MIDs to live in while the MID is being resolved. Although such a storage space isn't essential for correctness (we could just drop the packets and then have them retransmitted after the MID is resolved), holding the packets should smooth performance a bit. unknownMidPackets maps MIDs to arrays of BufferHandles.

In the absence of any decent synchronization mechanisms, we make unknownMidPackets a lock-free data structure. unknownMidPackets is a CommSpace consisting of a number of smaller "spaces". Each space is a CommSpace with the following elements:

   0: the MID whose packets are held in this space
   1: the number of buffered packets in this space
   2, 3, ...: data items
 
Each data item is either null (uninitialized), a BufferHandle holding a packet, or an InChannel onto which packets should be injected. The server tries to insert packets into the space, and the flow tries to initialize an InChannel and fill all the data items with the InChannel handle. Whoever gets to the space first simply inserts their item. Whoever gets to the space second takes the item that was already there, together with their own item, so that they have both a packet and an InChannel, and pushes the packet onto the InChannel. An atomic swap is used to insert things into the space, so that the server/flow can tell whether they got to each item first or second.

This is both the client and server end (via constructor).

Author:
Janos Ministry of Development




  Fields

· midToSpaceMap

Summary  |  Top

   final CommSpaceHandle midToSpaceMap

Map of MID bytes to a space. The element space has the following things stored at the following offsets:

   0: the MID bytes
   1: the number of buffered packets in this space
   2...: the packets (one per index).


· nextSpace

Summary  |  Top
   private int nextSpace

The next space to write a new (unknown) MID to. This value walks through midToSpaceMap showing where to insert new MIDs. It will wrap and start overwriting old MID maps in an (pseudo) LRU fashion.


· MIDMAPSIZE

Summary  |  Top
   private static final int MIDMAPSIZE

The number of MIDs that can be simultaneous tracked by this node.


· PACKETS_PER_SPACE

Summary  |  Top
   private static final int PACKETS_PER_SPACE

The number of packets with a given MID that are buffered before dropping.


· NEVER_DEMULTIPLEXED

Summary  |  Top
   static final int NEVER_DEMULTIPLEXED

This is a special flag used when "forwarding" buffered packets out of a midSpaceMap buffer. Only used in CapsuleChannel.receive()

See Also: receive


  Constructors

· UnknownMidPackets

Summary  |  Top

   UnknownMidPackets() 

Construct a server-side map for buffered packets.



· UnknownMidPackets

Summary  |  Top
   UnknownMidPackets(CommSpaceHandle midToSpaceMap) 

Construct a client-side handle on a buffered packet map.



  Methods

· spaceForMID

Summary  |  Top
   private CommSpaceHandle spaceForMID(byte[] midBytes) 

Given a mid (as a byte array) find the associated CommSpace in the spaceMap. This is deliberately not synchronized. It is safe for concurrent execution.



· addPacket

Summary  |  Top
   synchronized boolean addPacket(byte[] midBytes, 
                                  BufferHandle packet) 

add the given packet (which contains the given mid) to the buffered MID map. If no packet with the MID has been seen, a new entry in the MID map is made. Otherwise, the packet is added to the end of the appropriate list (or dropped if the maximum number of packets have already been buffered for that MID.

Returns true if the MID is not new (i.e., there are already packets buffered for that MID.

Synchronized to protect access/increment of 'nextSpace' and to prevent the same MID from being installed twice (don't know if (1) that's a real problem and (2) if its not already prevented elsewhere.)

XXX change to return true if packet was queued, false if dropped ??



· setInChannel

Summary  |  Top
   void setInChannel(byte[] midBytes, 
                     InChannelHandle inChannel) 


All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7