de.bb.bejy
Class Protocol

java.lang.Object
  |
  +--de.bb.bejy.Protocol

public abstract class Protocol
extends java.lang.Object

base class for all protocols used in BEJY.

provides some usefull functions to handle incoming data


Field Summary
protected  Factory factory
          reference to this protocol's factory
protected  java.io.InputStream is
          the input stream to read from
protected  java.io.OutputStream os
          the output stream to write to
protected  java.lang.String remoteAddress
          address ot the other side
protected  de.bb.bejy.Server server
          reference to this protocol's server (thread)
 
Constructor Summary
protected Protocol(Factory f)
          the only constructor
 
Method Summary
protected abstract  boolean doit()
          contains the protocol main loop.
protected  boolean goodStream()
          checks whether current streams are still usable
protected  ByteRef readFirst()
          read the first available bytes into a ByteArray object
protected  ByteRef readLine(ByteRef br)
          read the next line into a ByteArray using a 2nd ByteArray as buffer.
If there is no complete line in the provided buffer, the next chunk of data is read from the input stream.
protected  void trigger()
          a callback function which is called before the server starts to listen for incoming data.
Necessary when the server must send data before the clients starts sending.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

os

protected java.io.OutputStream os
the output stream to write to

is

protected java.io.InputStream is
the input stream to read from

factory

protected Factory factory
reference to this protocol's factory

server

protected de.bb.bejy.Server server
reference to this protocol's server (thread)

remoteAddress

protected java.lang.String remoteAddress
address ot the other side
Constructor Detail

Protocol

protected Protocol(Factory f)
the only constructor
Parameters:
f - the Factory object which creates this object
Method Detail

doit

protected abstract boolean doit()
                         throws java.lang.Exception
contains the protocol main loop.
Returns:
  • true when the established connection is reused
  • false when a new connection must be established
  • in both cases the server object and the protocol object is reused

    Throws:
    java.lang.Exception - indicates that even the server object must be discarded
    java.lang.Exception -  

    goodStream

    protected boolean goodStream()
    checks whether current streams are still usable
    Returns:
    true if streams are usable

    trigger

    protected void trigger()
                    throws java.lang.Exception
    a callback function which is called before the server starts to listen for incoming data.
    Necessary when the server must send data before the clients starts sending. E.g. SMTP or POP3 protocols send first data to the client, before they start to read data.
    Throws:
    java.lang.Exception -  

    readFirst

    protected ByteRef readFirst()
    read the first available bytes into a ByteArray object
    Returns:
    returns a ByteArray containing the first chunk of read data or null at EOS

    readLine

    protected ByteRef readLine(ByteRef br)
    read the next line into a ByteArray using a 2nd ByteArray as buffer.
    If there is no complete line in the provided buffer, the next chunk of data is read from the input stream.
    Parameters:
    br - the read buffer which contains already read data
    Returns:
    returns a ByteArray referring to the next line of data or null at EOS