|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectnet.jackofalltrades.irc.BaseConnection
Provides functionality for all connection types (ie. IRC, binary DCC, and ascii DCC).
| Field Summary | |
static int |
DEFAULT_BUFFER_SIZE
default size of the send and receive buffers (1Kb). |
static int |
DEFAULT_CONNECTION_TIMEOUT
default amount of time for a connection attempt to fail (30 seconds). |
static int |
DEFAULT_READ_WRITE_TIMEOUT
default amount of time for an I/O operation to fail (30 seconds). |
static int |
MAX_PORT
maximum allowable port number. |
static int |
MIN_PORT
minimum allowable port number on the remote host. |
| Constructor Summary | |
BaseConnection()
Creates a new BaseConnection. |
|
BaseConnection(java.net.InetAddress remoteHost,
int port)
Creates a new BaseConnection to connect to the specified
remote host. |
|
BaseConnection(java.net.Socket socket)
Creates a new BaseConnection connected on the specified
connected java.net.Socket. |
|
BaseConnection(java.lang.String remoteHost,
int port)
Creates a new BaseConnection to connect to the specified
remote host. |
|
| Method Summary | |
void |
addConnectionListener(ConnectionListener l)
Registers a ConnectionListener instance to listen for
connected and disconnected events. |
protected void |
addEventListener(java.lang.Class clazz,
java.util.EventListener l)
Adds a java.util.EventListener to the registered list of
listeners. |
boolean |
connect()
Connects to the configured remote host on the remote port, and starts the reader thread. |
void |
disconnect()
Disconnects from the remote host, and as a result the reader thread will stop. |
int |
getBufferSize()
Returns the send/receive buffer size. |
int |
getConnectionTimeout()
Returns the time limit for a connection attempt. |
protected java.util.EventListener[] |
getEventListeners(java.lang.Class clazz)
Returns an array of java.util.EventListener objects. |
java.lang.Exception |
getLastException()
Returns the last exception thrown. |
int |
getPortNumber()
Returns the port number. |
int |
getReadWriteTimeout()
Return the timeout period for an I/O operation. |
java.net.InetAddress |
getRemoteHost()
Returns the java.net.InetAddress representing the IP address
of the IRC server. |
boolean |
isConnected()
Returns the connected status of the underlying java.net.Socket. |
protected abstract void |
processInput()
Reads from the java.io.InputStream, or
java.io.Reader provided by the subclass. |
void |
removeConnectionListener(ConnectionListener l)
Removes a ConnectionListener instance from the collection of
registered listeners. |
protected void |
removeEventListener(java.lang.Class clazz,
java.util.EventListener l)
Remove a java.util.EventListener from the registered list
of listeners. |
void |
run()
Continuously reads from the underlying java.net.Socket
until disconnection. |
void |
setBufferSize(int bufferSize)
Sets the send/receive buffer size. |
void |
setConnectionTimeout(int timeout)
Sets the time limit for a connection attempt. |
protected void |
setLastException(java.lang.Exception e)
Sets the last exception thrown. |
void |
setPortNumber(int portNumber)
Sets the port number. |
void |
setReadWriteTimeout(int timeout)
Sets the new I/O timeout period. |
void |
setRemoteHost(java.net.InetAddress remoteHost)
Sets the java.net.InetAddress of the remote host, to which,
a connection will be established. |
protected abstract void |
wrapInput(java.io.InputStream input)
Provides a hook for subclasses to implement either binary or ascii/unicode connections. |
protected abstract void |
wrapOutput(java.io.OutputStream output)
Provides a hook for subclasses to implement either binary or ascii/unicode connections. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int MIN_PORT
public static final int MAX_PORT
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_READ_WRITE_TIMEOUT
public static final int DEFAULT_BUFFER_SIZE
| Constructor Detail |
public BaseConnection()
BaseConnection.
public BaseConnection(java.net.InetAddress remoteHost,
int port)
BaseConnection to connect to the specified
remote host.
remoteHost - the java.net.InetAddress of the remote
host.port - the port number on the remote host.
java.lang.IllegalArgumentException - if remoteHost is
null or if port is not in the range 1 - 65535.
public BaseConnection(java.lang.String remoteHost,
int port)
throws java.net.UnknownHostException
BaseConnection to connect to the specified
remote host.
remoteHost - the name of the remote host.port - the port number on the server.
java.net.UnknownHostException - if the remoteHost
cannot be resolved.
java.lang.IllegalArgumentException - if the remoteHost
null or blank.public BaseConnection(java.net.Socket socket)
BaseConnection connected on the specified
connected java.net.Socket.
Retrieves the java.net.InetAddress and port number of the
remote host, Wraps the input and output, and starts the reader thread.
No buffer sizes are set and neither are the timeouts. These can be
set using the helper methods.
socket - the Socket connected to the remote host.
java.lang.IllegalArgumentException - if socket is
null.| Method Detail |
public java.net.InetAddress getRemoteHost()
java.net.InetAddress representing the IP address
of the IRC server.
public void setRemoteHost(java.net.InetAddress remoteHost)
java.net.InetAddress of the remote host, to which,
a connection will be established.
remoteHost - the new remote host address.
java.lang.IllegalArgumentException - if remoteHost is
null.
java.lang.IllegalStateException - if this connection is still
connected.public int getPortNumber()
public void setPortNumber(int portNumber)
portNumber - the new port number.
java.lang.IllegalArgumentException - if portNumber is
less than 1 or greater than 65535.
java.lang.IllegalStateException - if this connection is still
connected.public int getConnectionTimeout()
public void setConnectionTimeout(int timeout)
timeout - the maximum time to wait for an accepted
connection in milliseconds.
java.lang.IllegalArgumentException - if timeout is
less than zero.public int getReadWriteTimeout()
public void setReadWriteTimeout(int timeout)
timeout - the new timeout period.
java.lang.IllegalArgumentException - if timeout is
less than zero.public int getBufferSize()
public void setBufferSize(int bufferSize)
java.net.Socket connection. NOTE:
According to the javadoc for java.net.Socket buffer sizes
of 64Kb and higher MUST be set BEFORE connecting.
bufferSize - the new buffer size hint.
java.net.IllegalStateException - if the connection is connected and
a buffer size of 64Kb, or higher, is set.public java.lang.Exception getLastException()
protected void setLastException(java.lang.Exception e)
e - the last exception thrown.public boolean isConnected()
java.net.Socket.
protected void addEventListener(java.lang.Class clazz,
java.util.EventListener l)
java.util.EventListener to the registered list of
listeners.
clazz - the java.lang.Class of the of listener
interface type NOT the actual class type of the listener.l - the listener object to add.
protected void removeEventListener(java.lang.Class clazz,
java.util.EventListener l)
java.util.EventListener from the registered list
of listeners.
clazz - the java.lang.Class of the of listener
interface type NOT the actual class type of the listener.l - the listener object to add.protected java.util.EventListener[] getEventListeners(java.lang.Class clazz)
java.util.EventListener objects.
clazz - the java.lang.Class of the interface type
implemented by the objects being returned.public final boolean connect()
getLastException()
to get the cause of the connection failure.
public void disconnect()
public void run()
java.net.Socket
until disconnection.
run in interface java.lang.Runnable
protected abstract void wrapInput(java.io.InputStream input)
throws java.io.IOException
input - the java.io.InputStream from the underlying
java.net.Socket.
java.io.IOException - if an I/O error occurs.
protected abstract void wrapOutput(java.io.OutputStream output)
throws java.io.IOException
output - the java.io.OutputStream from the underlying
java.net.Socket.
java.io.IOException - if an I/O error occurs.
protected abstract void processInput()
throws java.io.IOException
java.io.InputStream, or
java.io.Reader provided by the subclass.
java.io.IOException - if an I/O error occurs, or if the
underlying java.net.Socket times out.public void addConnectionListener(ConnectionListener l)
ConnectionListener instance to listen for
connected and disconnected events.
l - the listener to register.public void removeConnectionListener(ConnectionListener l)
ConnectionListener instance from the collection of
registered listeners.
l - the listener to remove.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||