net.jackofalltrades.irc
Class IrcConnection

java.lang.Object
  extended bynet.jackofalltrades.irc.BaseConnection
      extended bynet.jackofalltrades.irc.IrcConnection
All Implemented Interfaces:
java.util.EventListener, IrcCommandListener, java.lang.Runnable

public final class IrcConnection
extends BaseConnection
implements IrcCommandListener

Provides functionality for receiving, and sending, IRC commands.

 // create a new IrcConnection to "irc.darkmyst.org" on port 6667.
 IrcConnection darkMyst = new IrcConnection(
         InetAddress.getByName("irc.darkmyst.org"), 6667);
 
 // add ConnectionListeners and IrcCommandListeners.
 
 // connect to "irc.darkmyst.org".
 for (int i = 5; ((!darkMyst.connect()) && (i > 0)); i--) {
     Thread.sleep(1000);  // sleep for a second between connection attempts.
 }
 
 // perform tasks.
 
 darkMyst.disconnect();
 

Since:
0.5-alpha
Version:
$Revision: 1.7 $ $Date: 2003/08/03 21:01:37 $
Author:
Bradley M. Handy

Field Summary
 
Fields inherited from class net.jackofalltrades.irc.BaseConnection
DEFAULT_BUFFER_SIZE, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_READ_WRITE_TIMEOUT, MAX_PORT, MIN_PORT
 
Constructor Summary
IrcConnection()
          Creates a new IrcConnection.
IrcConnection(java.net.InetAddress remoteHost, int port)
          Creates a new IrcConnection to connect to the specified remote host.
IrcConnection(java.net.Socket socket)
          Creates a new IrcConnection connected on the specified java.net.Socket.
IrcConnection(java.lang.String remoteHost, int port)
          Creates a new IrcConnection to connect to the specified remote host.
 
Method Summary
 void addIrcCommandListener(IrcCommandListener l)
          Registers an IrcCommandListener for all commands.
 void addIrcCommandListener(java.lang.String name, IrcCommandListener l)
          Registers an IrcCommandListener for specific commands.
 void commandPrepared(IrcCommandEvent event)
          Writes an IrcCommand to the output stream.
 void commandReceived(IrcCommandEvent event)
          Does nothing.
protected  void processInput()
          Reads the commands from the , and notifies IrcCommandListeners events.
 void removeIrcCommandListener(IrcCommandListener l)
          Removes an IrcCommandListener from the list of registered listeners for all commands.
 void removeIrcCommandListener(java.lang.String name, IrcCommandListener l)
          Removes an IrcCommandListener from the list of registered listeners for specific commands.
protected  void wrapInput(java.io.InputStream input)
          Wraps the InputStream in a java.io.Reader.
protected  void wrapOutput(java.io.OutputStream output)
          Wraps the OutputStream in a java.io.Writer.
 
Methods inherited from class net.jackofalltrades.irc.BaseConnection
addConnectionListener, addEventListener, connect, disconnect, getBufferSize, getConnectionTimeout, getEventListeners, getLastException, getPortNumber, getReadWriteTimeout, getRemoteHost, isConnected, removeConnectionListener, removeEventListener, run, setBufferSize, setConnectionTimeout, setLastException, setPortNumber, setReadWriteTimeout, setRemoteHost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IrcConnection

public IrcConnection()
Creates a new IrcConnection.


IrcConnection

public IrcConnection(java.net.InetAddress remoteHost,
                     int port)
Creates a new IrcConnection to connect to the specified remote host.

Parameters:
remoteHost - the java.net.InetAddress of the remote host.
port - the port number on the remote host.
Throws:
java.lang.IllegalArgumentException - if remoteHost is null, or blank, or if port is not in the range 1 - 65535.

IrcConnection

public IrcConnection(java.lang.String remoteHost,
                     int port)
              throws java.net.UnknownHostException
Creates a new IrcConnection to connect to the specified remote host.

Parameters:
remoteHost - the name of the remote host.
port - the port number on the server.
Throws:
java.net.UnknownHostException - if the remoteHost cannot be resolved.
java.lang.IllegalArgumentException - if the remoteHost null or blank.

IrcConnection

public IrcConnection(java.net.Socket socket)
Creates a new IrcConnection connected on the specified java.net.Socket.

Parameters:
socket - the Socket connected to the remote host.
Method Detail

processInput

protected void processInput()
                     throws java.io.IOException
Reads the commands from the , and notifies IrcCommandListeners events.

Specified by:
processInput in class BaseConnection
Throws:
java.io.IOException - if an I/O error occurs.

wrapInput

protected void wrapInput(java.io.InputStream input)
Wraps the InputStream in a java.io.Reader.

Specified by:
wrapInput in class BaseConnection
Parameters:
input - the InputStream from the underlying java.net.Socket.

wrapOutput

protected void wrapOutput(java.io.OutputStream output)
Wraps the OutputStream in a java.io.Writer.

Specified by:
wrapOutput in class BaseConnection
Parameters:
output - the OutputStream from the underlying java.net.Socket.

commandPrepared

public void commandPrepared(IrcCommandEvent event)
Writes an IrcCommand to the output stream.

Specified by:
commandPrepared in interface IrcCommandListener
Parameters:
event - the event fired by a command generating component.

commandReceived

public void commandReceived(IrcCommandEvent event)
Does nothing.

Specified by:
commandReceived in interface IrcCommandListener

addIrcCommandListener

public void addIrcCommandListener(IrcCommandListener l)
Registers an IrcCommandListener for all commands.

Parameters:
l - the new registered listener.

addIrcCommandListener

public void addIrcCommandListener(java.lang.String name,
                                  IrcCommandListener l)
Registers an IrcCommandListener for specific commands.

Parameters:
l - the new registered listener.

removeIrcCommandListener

public void removeIrcCommandListener(IrcCommandListener l)
Removes an IrcCommandListener from the list of registered listeners for all commands.

Parameters:
l - the listener to remove.

removeIrcCommandListener

public void removeIrcCommandListener(java.lang.String name,
                                     IrcCommandListener l)
Removes an IrcCommandListener from the list of registered listeners for specific commands.

Parameters:
l - the listener to remove.


Copyright © 2002-2003 Jack-of-all-trades Programming Services. All Rights Reserved.