net.jetrix.clients
Class TetrinetClient

java.lang.Object
  extended by net.jetrix.clients.TetrinetClient
All Implemented Interfaces:
Runnable, Client, Destination
Direct Known Subclasses:
IRCClient, QueryClient, TSpecClient

public class TetrinetClient
extends Object
implements Client

Layer handling communication with a tetrinet or tetrifast client. Incomming messages are turned into a server understandable format and forwarded to the apropriate destination for processing (the player's channel or the main server thread)

Version:
$Revision: 627 $, $Date: 2005-02-18 01:00:43 +0100 (ven., 18 févr. 2005) $
Author:
Emmanuel Bourg

Field Summary
protected  Date connectionTime
           
protected  boolean disconnected
           
protected  Reader in
           
protected  long lastMessageTime
           
protected  Logger log
           
protected  Writer out
           
protected  BlockingQueue<Message> queue
           
protected  ServerConfig serverConfig
           
protected  Socket socket
           
 
Constructor Summary
TetrinetClient()
           
TetrinetClient(User user)
           
TetrinetClient(User user, Socket socket)
           
 
Method Summary
 void disconnect()
          Trigger the disconnection of this client.
 Channel getChannel()
          Return the channel this client subscribed to.
 Date getConnectionTime()
          Return the time of the connection to the server.
 long getIdleTime()
          Return the time in miliseconds of inactivity.
 InetAddress getInetAddress()
          Return the Internet address of this client.
 Protocol getProtocol()
          Return the protocol used by this client.
 Socket getSocket()
           
 String getType()
          Return the type of the client.
 User getUser()
          Return the user associated to this client.
 String getVersion()
          Return the version number of this client.
protected  boolean isAsynchronous()
          Tells if the messages are sent asynchroneously to the client.
 Message receiveMessage()
          Receive a message sent by the client.
 void run()
          Main loop listening and parsing messages sent by the client.
 void send(Message message)
          Send a message to the client.
 void setChannel(Channel channel)
          Set the channel.
 void setProtocol(Protocol protocol)
          Set the protocol.
 void setSocket(Socket socket)
           
 void setType(String type)
           
 void setUser(User user)
           
 void setVersion(String version)
           
 boolean supportsAutoJoin()
          Tell if the client can be affected automatically to a channel on connecting to the server.
 boolean supportsMultipleChannels()
          Tell if the client supports multiple channels simultaneously.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

connectionTime

protected Date connectionTime

lastMessageTime

protected long lastMessageTime

disconnected

protected boolean disconnected

in

protected Reader in

out

protected Writer out

socket

protected Socket socket

serverConfig

protected ServerConfig serverConfig

log

protected Logger log

queue

protected BlockingQueue<Message> queue
Constructor Detail

TetrinetClient

public TetrinetClient()

TetrinetClient

public TetrinetClient(User user)

TetrinetClient

public TetrinetClient(User user,
                      Socket socket)
Method Detail

getProtocol

public Protocol getProtocol()
Return the protocol used by this client.

Specified by:
getProtocol in interface Client

setProtocol

public void setProtocol(Protocol protocol)
Set the protocol.


run

public void run()
Main loop listening and parsing messages sent by the client.

Specified by:
run in interface Runnable

send

public void send(Message message)
Description copied from interface: Client
Send a message to the client. The raw message property must be set.

Specified by:
send in interface Client
Specified by:
send in interface Destination
Parameters:
message - the message to send

receiveMessage

public Message receiveMessage()
                       throws IOException
Description copied from interface: Client
Receive a message sent by the client.

Specified by:
receiveMessage in interface Client
Throws:
IOException

setSocket

public void setSocket(Socket socket)

getSocket

public Socket getSocket()

getInetAddress

public InetAddress getInetAddress()
Description copied from interface: Client
Return the Internet address of this client.

Specified by:
getInetAddress in interface Client

setChannel

public void setChannel(Channel channel)
Description copied from interface: Client
Set the channel.

Specified by:
setChannel in interface Client

getChannel

public Channel getChannel()
Description copied from interface: Client
Return the channel this client subscribed to.

Specified by:
getChannel in interface Client

supportsMultipleChannels

public boolean supportsMultipleChannels()
Description copied from interface: Client
Tell if the client supports multiple channels simultaneously.

Specified by:
supportsMultipleChannels in interface Client

supportsAutoJoin

public boolean supportsAutoJoin()
Description copied from interface: Client
Tell if the client can be affected automatically to a channel on connecting to the server.

Specified by:
supportsAutoJoin in interface Client

setUser

public void setUser(User user)

getUser

public User getUser()
Description copied from interface: Client
Return the user associated to this client.

Specified by:
getUser in interface Client

setVersion

public void setVersion(String version)

getVersion

public String getVersion()
Description copied from interface: Client
Return the version number of this client.

Specified by:
getVersion in interface Client

setType

public void setType(String type)

getType

public String getType()
Description copied from interface: Client
Return the type of the client.

Specified by:
getType in interface Client

getConnectionTime

public Date getConnectionTime()
Description copied from interface: Client
Return the time of the connection to the server.

Specified by:
getConnectionTime in interface Client

getIdleTime

public long getIdleTime()
Description copied from interface: Client
Return the time in miliseconds of inactivity.

Specified by:
getIdleTime in interface Client

disconnect

public void disconnect()
Description copied from interface: Client
Trigger the disconnection of this client.

Specified by:
disconnect in interface Client

isAsynchronous

protected boolean isAsynchronous()
Tells if the messages are sent asynchroneously to the client.

Since:
0.2

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2001-2008 Emmanuel Bourg. All Rights Reserved.