Purple Code

com.purpletech.message
Class AbstractPeer

java.lang.Object
  |
  +--com.purpletech.message.AbstractPeer
All Implemented Interfaces:
MessagePeer, java.lang.Runnable
Direct Known Subclasses:
BlockingPeer

public abstract class AbstractPeer
extends java.lang.Object
implements MessagePeer, java.lang.Runnable

An abstract implementation of a message peer. Subclasses need to provide the following methods: connect, disconnect, isConnected, sendMessage, receiveMessage. This superclass takes care of the listeners, the printer, and bind/lookup.

Version:
$Id: AbstractPeer.java,v 1.3 2002/11/24 05:32:55 alex Exp $
Author:
Alex Chaffee

Field Summary
protected  boolean doSendSystemMessages
           
protected  java.util.Vector listeners
           
protected  java.io.PrintStream outPrint
           
protected  MessagePeerPrinter printer
           
 
Constructor Summary
AbstractPeer(MessagePeerPrinter printer)
           
AbstractPeer(java.io.PrintStream outPrint)
           
 
Method Summary
 void addMessageListener(MessageListener x)
          adds an event listener that receives all incoming messages received by this peer
 void bind(java.lang.String name)
           
abstract  void connect()
          Try to connect to the server
abstract  void disconnect()
          Try to disconnect from the server
 int getID()
          get the ID of this peer
abstract  boolean isConnected()
          are we connected or not?
 int lookup(java.lang.String name)
          Look up a peer id that's been bound to a name on this server
protected  Message processSystemMessage(Message m)
          process a SystemMessage
abstract  Message receiveMessage()
           
 void removeMessageListener(MessageListener x)
           
 void run()
          continually look for messages and dispatch them while connected
abstract  void sendMessage(Message message)
          sends a message out across the pipe
 void setSendSystemMessages(boolean doIt)
          If doSendSystemMessages is TRUE, then all system messages get dispatched to all listeners.
 void start()
          Spawn a thread to start receiving messages.
 void stop()
          Stop receiving messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printer

protected MessagePeerPrinter printer

outPrint

protected java.io.PrintStream outPrint

listeners

protected java.util.Vector listeners

doSendSystemMessages

protected boolean doSendSystemMessages
Constructor Detail

AbstractPeer

public AbstractPeer(MessagePeerPrinter printer)

AbstractPeer

public AbstractPeer(java.io.PrintStream outPrint)
Method Detail

getID

public int getID()
Description copied from interface: MessagePeer
get the ID of this peer

Specified by:
getID in interface MessagePeer

setSendSystemMessages

public void setSendSystemMessages(boolean doIt)
If doSendSystemMessages is TRUE, then all system messages get dispatched to all listeners. (Default = FALSE)

Specified by:
setSendSystemMessages in interface MessagePeer

addMessageListener

public void addMessageListener(MessageListener x)
Description copied from interface: MessagePeer
adds an event listener that receives all incoming messages received by this peer

Specified by:
addMessageListener in interface MessagePeer

removeMessageListener

public void removeMessageListener(MessageListener x)
Specified by:
removeMessageListener in interface MessagePeer

start

public void start()
Spawn a thread to start receiving messages. Note that client code can just spawn their own thread and pass the thread this object (it's a Runnable).

Specified by:
start in interface MessagePeer

stop

public void stop()
Stop receiving messages. Stops the thread.

Specified by:
stop in interface MessagePeer

run

public void run()
continually look for messages and dispatch them while connected

Specified by:
run in interface java.lang.Runnable

processSystemMessage

protected Message processSystemMessage(Message m)
process a SystemMessage

Returns:
null if the message gets eaten, or the old message (or possibly a new one)

bind

public void bind(java.lang.String name)
Specified by:
bind in interface MessagePeer
Parameters:
name - name to bind this client to

lookup

public int lookup(java.lang.String name)
Look up a peer id that's been bound to a name on this server

Specified by:
lookup in interface MessagePeer

connect

public abstract void connect()
                      throws java.io.IOException
Description copied from interface: MessagePeer
Try to connect to the server

Specified by:
connect in interface MessagePeer
java.io.IOException

disconnect

public abstract void disconnect()
Description copied from interface: MessagePeer
Try to disconnect from the server

Specified by:
disconnect in interface MessagePeer

receiveMessage

public abstract Message receiveMessage()

sendMessage

public abstract void sendMessage(Message message)
Description copied from interface: MessagePeer
sends a message out across the pipe

Specified by:
sendMessage in interface MessagePeer

isConnected

public abstract boolean isConnected()
Description copied from interface: MessagePeer
are we connected or not?

Specified by:
isConnected in interface MessagePeer

Documentation generated March 5 2003