common
Class TCPHandler

java.lang.Object
  extended by java.lang.Thread
      extended by common.StoppableThread
          extended by common.TransfertSlave
              extended by common.TCPHandler
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
TCPClient, TCPConnection

public class TCPHandler
extends TransfertSlave

Gère une connexion TCP avec un hôte distant et permet de fermer correctement la connexion avec celui-ci.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  BufferedReader inputStream
          Flux en entrée de la connexion.
private  PrintWriter outputStream
          Flux en sortie de la connexion.
private  Socket tcpSocket
          Socket de connexion TCP.
protected static int TIME_WAITING_TRANSFERT_CLOSING
           
 
Fields inherited from class common.TransfertSlave
master
 
Fields inherited from class common.StoppableThread
quitQuery
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected TCPHandler(TransfertMaster master, Socket tcpSocket)
          Prépare la connexion TCP en initialisant les flux E/S.
protected TCPHandler(TransfertMaster master, String host, int port)
          Prépare la connexion TCP en initialisant les flux E/S.
 
Method Summary
protected  void doFree()
          Libère les ressources utilisées et ferme le socket TCP.
 void quit()
          Ferme le thread ainsi que la connexion TCP.
 void sendCommand(RemoteCommand command)
          Envoit une commande par le flux TCP.
 void sendCommand(RemoteCommand command, String argument)
          Envoit une commande et son argument par le flux TCP.
 
Methods inherited from class common.StoppableThread
doQuit, free
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIME_WAITING_TRANSFERT_CLOSING

protected static final int TIME_WAITING_TRANSFERT_CLOSING
See Also:
Constant Field Values

tcpSocket

private final Socket tcpSocket
Socket de connexion TCP.


inputStream

protected final BufferedReader inputStream
Flux en entrée de la connexion.


outputStream

private final PrintWriter outputStream
Flux en sortie de la connexion.

Constructor Detail

TCPHandler

protected TCPHandler(TransfertMaster master,
                     Socket tcpSocket)
              throws SocketStartFailure
Prépare la connexion TCP en initialisant les flux E/S.

Parameters:
master - le transfert parent
tcpSocket - le socket de connexion à manipluer
Throws:
SocketStartFailure - s'il est impossible d'ouvrir les flux E/S.

TCPHandler

protected TCPHandler(TransfertMaster master,
                     String host,
                     int port)
              throws SocketStartFailure
Prépare la connexion TCP en initialisant les flux E/S.

Parameters:
master - le transfert parent
host - l'hôte sur lequel se connecter
port - le port de connexion
Throws:
SocketStartFailure - en cas de problème d'ouverture du socket, de connexion au serveur ou s'il est impossible d'ouvrir les flux E/S.
Method Detail

sendCommand

public final void sendCommand(RemoteCommand command,
                              String argument)
Envoit une commande et son argument par le flux TCP.

Parameters:
command - la commande à envoyer.
argument - l'argument (si applicable).

sendCommand

public final void sendCommand(RemoteCommand command)
Envoit une commande par le flux TCP. Si c'est une commande d'annulation, l'argument est alors "cause inconnue".

Parameters:
command - la commande à envoyer.

quit

public final void quit()
Ferme le thread ainsi que la connexion TCP. Avant la fermeture de la connexion, une demande d'annulation est envoyée à l'hôte distant.

Overrides:
quit in class StoppableThread
See Also:
Thread.join(), StoppableThread.free(), StoppableThread.doQuit()

doFree

protected final void doFree()
Libère les ressources utilisées et ferme le socket TCP. La fonction attend d'abord un certain temps pour laisser l'hôte distant finaliser sa connexion TCP.

Overrides:
doFree in class StoppableThread
See Also:
TIME_WAITING_TRANSFERT_CLOSING