|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttriptracker.client.net.SocketConnection<E>
public abstract class SocketConnection<E extends SocketListener>
Connects to the server through a socket.
| Field Summary | |
|---|---|
protected BufferedReader |
in
|
protected InputStream |
inStream
|
protected Set<E> |
listeners
Listener set for Model View Controller (MVC) separation. |
protected boolean |
loggedIn
|
protected PrintStream |
out
|
protected OutputStream |
outStream
|
| Constructor Summary | |
|---|---|
SocketConnection()
|
|
| Method Summary | |
|---|---|
void |
addListener(E listener)
Register a listener for server events. |
protected void |
brokenListener(SocketListener listener,
RuntimeException exception)
Reports a broken listener, removes it from the listener queue and logs the error. |
void |
connect()
Connects to the hostname and port number set by setHost(String)
and setPort(int). |
void |
connect(String host,
int port)
Connect to server on specified port. |
protected void |
connectionUpdate(ConnectionState state)
Publish a connection state change event to all listeners. |
void |
disconnect()
Disconnect from the socket. |
String |
getHost()
Returns the current hostname. |
int |
getPort()
Returns the current port. |
void |
getRoutes(String username)
Request a list of routes for a given user. |
String |
getUsername()
Returns the name of the active user. |
protected void |
invalidMessage(String message)
Publish an invalid message event to all listeners. |
boolean |
isClosed()
Checks if the client connection is closed. |
boolean |
isConnected()
Checks if the client is connected to the server. |
boolean |
isLoggedIn()
Checks if the client is logged in. |
protected void |
logon(int type,
String user,
String pass)
Logon a user. |
protected abstract boolean |
messageHandler(String message)
Message handler for data received on socket. |
protected void |
messageLoop()
Checks for messages recieved from the server, and pass them to the message handler for further processing. |
void |
removeListener(E listener)
Remove listener from listener queue. |
protected void |
sendMessage(Object... message)
Sends a message to the server |
void |
setHost(String host)
Set hostname to connect to. |
void |
setPort(int port)
Set port to connect to. |
void |
setRoute(Route route)
Sets route to track |
protected void |
socketErrorEvent(IOException exception)
Publish a socket error event to all listeners. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected InputStream inStream
protected OutputStream outStream
protected BufferedReader in
protected PrintStream out
protected boolean loggedIn
protected Set<E extends SocketListener> listeners
| Constructor Detail |
|---|
public SocketConnection()
| Method Detail |
|---|
public void connect()
throws IOException
setHost(String)
and setPort(int).
IOException - on connection failureconnect(String, int)
public void connect(String host,
int port)
throws IOException
host - server hostnameport - destination port
IOException - on connection failure#connect(String)
protected void logon(int type,
String user,
String pass)
throws IOException
type - type of useruser - usernamepass - password
IOException - on connection failurepublic void setRoute(Route route)
public void getRoutes(String username)
protected void sendMessage(Object... message)
message - public boolean isConnected()
public boolean isClosed()
public boolean isLoggedIn()
protected void messageLoop()
throws IOException
IOExceptionprotected abstract boolean messageHandler(String message)
message - received message from server
public void disconnect()
throws IOException
IOException - on socket errorpublic void addListener(E listener)
listener - event receiver to registerpublic void removeListener(E listener)
listener - event receiver to remove
protected void brokenListener(SocketListener listener,
RuntimeException exception)
listener - broken listenerexception - exception thrown by listenerprotected void socketErrorEvent(IOException exception)
exception - socket exception thrownprotected void invalidMessage(String message)
message - full messageprotected void connectionUpdate(ConnectionState state)
state - new connection statepublic String getHost()
Protocol.HOST.
public void setHost(String host)
Protocol.HOST.
host - host to setpublic int getPort()
Protocol.PORTNR.
public void setPort(int port)
Protocol.PORTNR.
port - The port to set.public String getUsername()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||