com.jabberwookie
Class Stream

java.lang.Object
  |
  +--com.jabberwookie.Stream
Direct Known Subclasses:
Client2Server, Component2Server

public abstract class Stream
extends java.lang.Object

This implements the most basic functions required to establish and maintain a Jabber stream. It must be extended to be truely useful. Currently this is done by the Client2Server and Component2Server classes.

Author:
smeiners

Field Summary
protected  com.jabberwookie.Stream.ChunkProcessor chunkProcessor
           
protected  java.util.Vector chunkQueue
           
protected  boolean connected
           
protected  java.lang.String connectionId
           
protected static boolean DEBUG
           
protected  java.io.DataInputStream in
           
protected  IQListener iqListener
           
protected  MessageListener mListener
           
protected  Namespaces ns
           
protected  java.io.OutputStream out
           
protected  java.io.Writer outWriter
           
protected  com.jabberwookie.Stream.ParserThread parserT
           
protected  PresenceListener pListener
           
protected  Processor processor
           
protected static int PROCESSOR_WAIT_TIME
          How long to wait before giving up on trying to process a chunk.
protected  UnrecognizedChunkListener unListener
           
protected  java.util.Hashtable waitingIds
           
 
Constructor Summary
Stream(java.io.InputStream in, java.io.OutputStream out)
          Creates a new instance of Stream.
Stream(java.io.InputStream in, java.io.OutputStream out, Processor processor)
          Creates a new instance of Stream.
 
Method Summary
 void cData(java.lang.String data)
           
 void chunkStart(java.lang.String tag, java.util.Hashtable attrs)
           
 void chunkStop(java.lang.String tag)
           
abstract  void close()
          Closes the stream, needs to be impelmented by the subclass.
 void docStart(java.lang.String tag, java.util.Hashtable attrs)
           
 void docStop(java.lang.String tag)
           
 void dtdData(java.lang.String dtd)
           
 void elementStart(java.lang.String tag, java.util.Hashtable attrs)
           
 void elementStop(java.lang.String tag)
           
 java.lang.String getConnectionId()
           
 boolean isConnected()
           
abstract  boolean open(java.lang.String serverName, int timeoutSecs)
          Opens the stream, needs to be impelmented by the subclass.
 void processChunk(Chunk chunk)
           
 void processingInstruction(java.lang.String element)
           
 void send(Chunk chunk)
          Sends the chunk to the other end and returns immediatly.
 Chunk send(Chunk chunk, int timeoutMillis)
          Sends the chunk to the other end and waits for a reply.
 void setAllListeners(java.lang.Object listener)
          Does NOT set the UnrecogizedChunkListener.
 void setIQListener(IQListener listener)
           
 void setMessageListener(MessageListener listener)
           
 void setNamespaces(Namespaces namespaces)
          Sets the namespaces used when interpreting incoming data.
 void setPresenceListener(PresenceListener listener)
           
 void setProcessor(Processor processor)
          Sets the internal Processor used when calling your *Listeners.
 void setUnrecogizedChunkListener(UnrecognizedChunkListener listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG
See Also:
Constant Field Values

PROCESSOR_WAIT_TIME

protected static final int PROCESSOR_WAIT_TIME
How long to wait before giving up on trying to process a chunk. (but only if you're using a Processor)

See Also:
Constant Field Values

in

protected java.io.DataInputStream in

out

protected java.io.OutputStream out

outWriter

protected java.io.Writer outWriter

parserT

protected com.jabberwookie.Stream.ParserThread parserT

processor

protected Processor processor

chunkQueue

protected java.util.Vector chunkQueue

chunkProcessor

protected com.jabberwookie.Stream.ChunkProcessor chunkProcessor

mListener

protected MessageListener mListener

pListener

protected PresenceListener pListener

iqListener

protected IQListener iqListener

unListener

protected UnrecognizedChunkListener unListener

connected

protected boolean connected

connectionId

protected java.lang.String connectionId

ns

protected Namespaces ns

waitingIds

protected java.util.Hashtable waitingIds
Constructor Detail

Stream

public Stream(java.io.InputStream in,
              java.io.OutputStream out)
Creates a new instance of Stream. If you use this constuctor it will block on any calls to your *Listeners.


Stream

public Stream(java.io.InputStream in,
              java.io.OutputStream out,
              Processor processor)
Creates a new instance of Stream. If you use this constructor and pass in a valid Processor it will call your *Listeners as fast as the Processor allows (when there is data available, of course).

Method Detail

setProcessor

public void setProcessor(Processor processor)
Sets the internal Processor used when calling your *Listeners. If you're going to take a while to process chunks it's highly recomended that you not only use a Processor, but that you use one with either a large queue, a lot of threads, or both. This is because if your processor refuses to accept a chunk for more than 10 seconds it will give up and drop it on the floor. No, this isn't the best behavior, but it is easily avoidable, just be careful.

Parameters:
processor -

setNamespaces

public void setNamespaces(Namespaces namespaces)
Sets the namespaces used when interpreting incoming data. If you don't know what the namespaces are I would suggest reading some of the Jabber protocol documentation.

Parameters:
namespaces -

open

public abstract boolean open(java.lang.String serverName,
                             int timeoutSecs)
                      throws java.io.IOException
Opens the stream, needs to be impelmented by the subclass.

Parameters:
serverName -
timeoutSecs -
Returns:
Throws:
java.io.IOException

close

public abstract void close()
Closes the stream, needs to be impelmented by the subclass.


send

public void send(Chunk chunk)
          throws java.io.IOException
Sends the chunk to the other end and returns immediatly.

Parameters:
chunk -
Throws:
java.io.IOException

send

public Chunk send(Chunk chunk,
                  int timeoutMillis)
           throws java.io.IOException
Sends the chunk to the other end and waits for a reply.

Parameters:
chunk -
timeoutMillis -
Returns:
Throws:
java.io.IOException

isConnected

public boolean isConnected()

getConnectionId

public java.lang.String getConnectionId()

setMessageListener

public void setMessageListener(MessageListener listener)

setPresenceListener

public void setPresenceListener(PresenceListener listener)

setIQListener

public void setIQListener(IQListener listener)

setUnrecogizedChunkListener

public void setUnrecogizedChunkListener(UnrecognizedChunkListener listener)

setAllListeners

public void setAllListeners(java.lang.Object listener)
Does NOT set the UnrecogizedChunkListener. This will only work it the passed listener implements MessageListener, PresenceListener, and IQListener. If not it will throw a ClassCastException.


cData

public void cData(java.lang.String data)

chunkStart

public void chunkStart(java.lang.String tag,
                       java.util.Hashtable attrs)

docStart

public void docStart(java.lang.String tag,
                     java.util.Hashtable attrs)

elementStart

public void elementStart(java.lang.String tag,
                         java.util.Hashtable attrs)

elementStop

public void elementStop(java.lang.String tag)

chunkStop

public void chunkStop(java.lang.String tag)

processChunk

public void processChunk(Chunk chunk)

docStop

public void docStop(java.lang.String tag)

processingInstruction

public void processingInstruction(java.lang.String element)

dtdData

public void dtdData(java.lang.String dtd)