Class UserConnection

java.lang.Object
  |
  +--UserConnection
All Implemented Interfaces:
java.lang.Runnable

public class UserConnection
extends java.lang.Object
implements java.lang.Runnable

This class manages a users connections. It makes it possible to send messages to the user or to IRC and it handles relaying between them as well.


Field Summary
static char oop
          Out of protocol delimiter.
 
Constructor Summary
UserConnection(ChatServlet servlet, User user, java.io.ObjectOutputStream userOutputStream)
          Creates the connection object.
 
Method Summary
 void close()
          Used to close the connections to the IRC server and to the user.
 void connect(java.lang.String server, int port)
          Used to connect to the given IRC server.
 void execute(java.lang.String input)
          Used to parse and execute a command from the Chatlet.
 void execute(java.lang.String command, java.lang.String argument)
          Used to execute specific commands sent by the Chatlet user.
 int getLocalPort()
          Used to get the local port after a connection has been established.
 int getPort()
          Used to get the port of the IRC server the user is connected to.
 java.lang.String getServer()
          Used to get the IRC server the user is connected to.
 User getUser()
          Used to get the user associated with this connection.
 boolean isConnected()
          Used to check if this connection has been established.
 void keepAlive(long keepAliveDelay)
          Used to keep a connection alive (fake keep-alive).
 java.lang.String parse(java.lang.String str)
          Used to parse a String from the IRC server.
 void run()
          Here we relay everything from the IRC server to the user after it has been parsed.
 void sendToIRC(java.lang.String str)
          Used to send a String to the IRC server.
 void sendToUser(java.lang.String str)
          Used to send a String to the user.
static java.lang.String[] split(java.lang.String str, java.lang.String pattern)
          Used to split a string into parts according to a given pattern;
 java.lang.String toString()
          Used to retrieve a String containing connection information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

oop

public static final char oop
Out of protocol delimiter.
Constructor Detail

UserConnection

public UserConnection(ChatServlet servlet,
                      User user,
                      java.io.ObjectOutputStream userOutputStream)
Creates the connection object. It will try to establish a connection to the specified IRC server and start relaying information from it back to the user.
Parameters:
servlet - A reference to the ChatServlet.
user - The associated user.
userOutputStream - The output stream to the user.
server - The address of the IRC server.
port - The port of the IRC server.
Method Detail

isConnected

public boolean isConnected()
Used to check if this connection has been established.
Returns:
true if connected

connect

public void connect(java.lang.String server,
                    int port)
             throws java.io.IOException
Used to connect to the given IRC server.
Parameters:
server - The address of the IRC server.
port - The port of the IRC server.

keepAlive

public void keepAlive(long keepAliveDelay)
               throws java.io.IOException
Used to keep a connection alive (fake keep-alive).

sendToIRC

public void sendToIRC(java.lang.String str)
               throws java.io.IOException
Used to send a String to the IRC server.
Parameters:
str - The String to be sent.

sendToUser

public void sendToUser(java.lang.String str)
                throws java.io.IOException
Used to send a String to the user.
Parameters:
str - The String to be sent.

run

public void run()
Here we relay everything from the IRC server to the user after it has been parsed.
Specified by:
run in interface java.lang.Runnable

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String pattern)
Used to split a string into parts according to a given pattern;
Parameters:
str - The string to be split.
pattern - The pattern to use when splitting, where a * symbolises a part that should be returned.
Returns:
An array of Strings corresponding to the parts of the pattern, or null if the pattern did not match.

parse

public java.lang.String parse(java.lang.String str)
                       throws java.io.IOException
Used to parse a String from the IRC server.
Parameters:
str - The String to be parsed.
Returns:
A parsed String or null if nothing should be sent back to the user.

execute

public void execute(java.lang.String input)
             throws java.io.IOException
Used to parse and execute a command from the Chatlet.
Parameters:
input - The input the user typed in the Chatlet.

execute

public void execute(java.lang.String command,
                    java.lang.String argument)
             throws java.io.IOException
Used to execute specific commands sent by the Chatlet user.
Parameters:
command - The command issued by the user.
argument - The argument of the command, or null if none.

close

public void close()
Used to close the connections to the IRC server and to the user.

getServer

public java.lang.String getServer()
Used to get the IRC server the user is connected to.
Returns:
The IRC server the user is connected to.

getPort

public int getPort()
Used to get the port of the IRC server the user is connected to.
Returns:
The port of the IRC server the user is connected to.

getLocalPort

public int getLocalPort()
Used to get the local port after a connection has been established.
Returns:
The local port number.

getUser

public User getUser()
Used to get the user associated with this connection.
Returns:
The user associated with this connection.

toString

public java.lang.String toString()
Used to retrieve a String containing connection information.
Overrides:
toString in class java.lang.Object
Returns:
A String with connection information.