edu.rit.m2mp
Class Channel

java.lang.Object
  extended by edu.rit.m2mp.Channel
Direct Known Subclasses:
ControllableChannel, DaemonChannel, FlowController, NullChannel, UDPChannel

public abstract class Channel
extends Object

Class Channel is the abstract superclass for a channel in the Many-to-Many Protocol (M2MP). The channel is an abstraction of the external network underneath the M2MP Layer. The M2MP Layer uses a channel to send messages to and receive messages from the external network.

Several M2MP channel implementations are provided, including:

The M2MP properties file specifies which channel implementation the M2MP Layer will use. Parameters needed to configure the specified channel implementation also appear in the M2MP properties file. See class M2MPProperties for further information.

You can write your own custom M2MP channel implementation to use some other kind of external network. You can even write an M2MP channel implementation that sends messages to and receives messages from another channel. Thus, you can set up a "channel pipeline" by configuring the M2MP Layer to use a channel instance which in turn is configured to use another channel instance, and so on until you reach the final channel instance which hooks up to the external network. Outgoing M2MP messages will traverse the channel pipeline in forward order, and incoming M2MP messages will traverse the channel pipeline in reverse order. This capability can be used, for example, to insert debug logging or other debug controls into the incoming and outgoing M2MP message streams.

Requirements:


Field Summary
protected  PacketPool myPacketPool
          This channel's packet pool.
 
Constructor Summary
Channel(PacketPool thePacketPool)
          Construct a new channel.
 
Method Summary
abstract  Packet receivePacket()
          Receive an M2MP packet via this channel.
abstract  void transmitPacket(Packet thePacket)
          Send the given M2MP packet via this channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myPacketPool

protected PacketPool myPacketPool
This channel's packet pool.

Constructor Detail

Channel

public Channel(PacketPool thePacketPool)
Construct a new channel. To receive incoming packets, the channel implementation may obtain Packet objects from the given PacketPool.

The channel constructor must get any necessary parameter values from the M2MP properties file. See class M2MPProperties for further information.

Parameters:
thePacketPool - Packet pool.
Throws:
NullPointerException - (unchecked exception) Thrown if thePacketPool is null.
Method Detail

receivePacket

public abstract Packet receivePacket()
                              throws IOException
Receive an M2MP packet via this channel. This method must:
  1. Receive the next packet from the external network (or underlying channel), blocking until a packet is available.
  2. Fill in a Packet object's byte buffer with the contents of the received packet, including the header and data.
  3. Set the packet object's limit to the correct value.
  4. Return the packet object.

Note: The receivePacket() method must "loop back" any packet that was sent via the transmitPacket() method on this channel. However, the looped-back packet returned by receivePacket() must be a copy of, not a reference to, the outgoing packet.

Returns:
M2MP packet that was received.
Throws:
IOException - Thrown if an I/O error occurred.

transmitPacket

public abstract void transmitPacket(Packet thePacket)
                             throws IOException
Send the given M2MP packet via this channel. This method must:
  1. Extract the valid bytes out of thePacket's byte buffer as determined by thePacket's limit.
  2. Transmit those bytes on the external network (or underlying channel).
  3. Ensure that a copy of the packet is looped back and returned by the receivePacket() method.

Parameters:
thePacket - M2MP packet to be sent.
Throws:
IOException - Thrown if an I/O error occurred.


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.