net.yura.mobile.io
Class SocketClient

java.lang.Object
  extended by net.yura.mobile.io.SocketClient
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ServiceLink

public abstract class SocketClient
extends Object
implements Runnable

Author:
Yura Mamyrin

Field Summary
static int COMMUNICATING
           
protected  javax.microedition.io.StreamConnection conn
           
static int CONNECTED
           
static int CONNECTING
           
static int DISCONNECTED
           
static int DISCONNECTED_AND_PAUSED
           
protected  InputStream in
           
protected  int initialWaitValue
           
protected  int maxRetries
           
protected  int maxWaitTimeMillis
           
protected  Vector offlineBox
          not sure how useful this is, as sometimes write does NOT throw any exception when trying to send something, even though it was not able to send, and the connection is shut down right after, that message would have been lost, and will not end up in the offline inbox
protected  OutputStream out
           
(package private)  boolean pauseReconnectOnFailure
           
protected  String protocol
           
protected  int retryWaitMultiplier
           
protected  QueueProcessorThread writeThread
           
 
Constructor Summary
SocketClient(String server)
          you can pass null into this method, but then you need to Override getNextServer()
SocketClient(String server, int maxRetries, int retryWaitMultiplier, int initialWaitValue, int maxWaitTimeMillis, boolean pauseReconnectOnFailure)
           
 
Method Summary
 void addToOfflineBox(Object t)
          if we are in the DISCONNECTED_AND_PAUSED state, wake us up
 void addToOutbox(Object obj)
           
protected abstract  void connected(InputStream in, OutputStream out)
          this method is called when a connection is established
 void disconnect()
           
protected abstract  void disconnected()
          This method is called when a connection is lost this should send a new message if you want to make a connection again the message you send will be something like 'hello' or 'login'
protected  int getMaxRetries()
           
protected  String getNextServer()
           
 Vector getOfflineBox()
           
protected  int getRetryCount()
           
protected abstract  void handleObject(Object task)
          this is called when a object is recieved from the server
protected  javax.microedition.io.StreamConnection openConnection(String serv)
           
protected abstract  Object read(InputStream in)
           
 void run()
          This is the run() method of the Socket read thread this thread can sometimes block and stick around even after a socket is closed and a new one reopened
protected  void securityException()
           
protected  void sendOfflineInboxMessages()
           
 void setDisconnected(boolean b)
           
 void setRetryCount(int retryCount)
           
protected abstract  void updateState(int c)
          this is used to update a connection indicator
 void wake()
          if we are in the DISCONNECTED_AND_PAUSED state, wake us up
protected abstract  void write(OutputStream out, Object object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMUNICATING

public static final int COMMUNICATING
See Also:
Constant Field Values

conn

protected javax.microedition.io.StreamConnection conn

CONNECTED

public static final int CONNECTED
See Also:
Constant Field Values

CONNECTING

public static final int CONNECTING
See Also:
Constant Field Values

DISCONNECTED

public static final int DISCONNECTED
See Also:
Constant Field Values

DISCONNECTED_AND_PAUSED

public static final int DISCONNECTED_AND_PAUSED
See Also:
Constant Field Values

in

protected InputStream in

initialWaitValue

protected int initialWaitValue

maxRetries

protected int maxRetries

maxWaitTimeMillis

protected int maxWaitTimeMillis

offlineBox

protected Vector offlineBox
not sure how useful this is, as sometimes write does NOT throw any exception when trying to send something, even though it was not able to send, and the connection is shut down right after, that message would have been lost, and will not end up in the offline inbox


out

protected OutputStream out

pauseReconnectOnFailure

boolean pauseReconnectOnFailure

protocol

protected String protocol

retryWaitMultiplier

protected int retryWaitMultiplier

writeThread

protected QueueProcessorThread writeThread
Constructor Detail

SocketClient

public SocketClient(String server)
you can pass null into this method, but then you need to Override getNextServer()

Parameters:
server -

SocketClient

public SocketClient(String server,
                    int maxRetries,
                    int retryWaitMultiplier,
                    int initialWaitValue,
                    int maxWaitTimeMillis,
                    boolean pauseReconnectOnFailure)
Method Detail

addToOfflineBox

public void addToOfflineBox(Object t)
if we are in the DISCONNECTED_AND_PAUSED state, wake us up


addToOutbox

public void addToOutbox(Object obj)

connected

protected abstract void connected(InputStream in,
                                  OutputStream out)
this method is called when a connection is established


disconnect

public void disconnect()

disconnected

protected abstract void disconnected()
This method is called when a connection is lost this should send a new message if you want to make a connection again the message you send will be something like 'hello' or 'login'


getMaxRetries

protected int getMaxRetries()

getNextServer

protected String getNextServer()

getOfflineBox

public Vector getOfflineBox()

getRetryCount

protected int getRetryCount()

handleObject

protected abstract void handleObject(Object task)
this is called when a object is recieved from the server


openConnection

protected javax.microedition.io.StreamConnection openConnection(String serv)
                                                         throws IOException
Throws:
IOException

read

protected abstract Object read(InputStream in)
                        throws IOException
Throws:
IOException

run

public final void run()
This is the run() method of the Socket read thread this thread can sometimes block and stick around even after a socket is closed and a new one reopened

Specified by:
run in interface Runnable

securityException

protected void securityException()

sendOfflineInboxMessages

protected void sendOfflineInboxMessages()

setDisconnected

public void setDisconnected(boolean b)

setRetryCount

public void setRetryCount(int retryCount)

updateState

protected abstract void updateState(int c)
this is used to update a connection indicator


wake

public void wake()
if we are in the DISCONNECTED_AND_PAUSED state, wake us up


write

protected abstract void write(OutputStream out,
                              Object object)
                       throws IOException
Throws:
IOException