jBittorrentAPI
Class MessageSender

java.lang.Object
  extended by java.lang.Thread
      extended by jBittorrentAPI.MessageSender
All Implemented Interfaces:
java.lang.Runnable

public class MessageSender
extends java.lang.Thread

Thread created to send message to the remote peer. Hold a queue for outgoing messages


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  javax.swing.event.EventListenerList listeners
           
private  long lmst
           
private  java.io.OutputStream os
           
private  java.util.concurrent.LinkedBlockingQueue<Message> outgoingMessage
           
private  boolean run
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MessageSender(java.lang.String id, java.io.OutputStream os)
           
 
Method Summary
 void addMessageToQueue(Message m)
          Puts the message in parameter in the queue, waiting to be sent
 void addOutgoingListener(OutgoingListener listener)
           
protected  void fireConnectionClosed()
          Called when the connection to the peer has been closed.
protected  void fireKeepAliveSent()
          Called when a keep-alive message has been sent.
 OutgoingListener[] getOutgoingListeners()
           
 void removeOutgoingListener(OutgoingListener listener)
           
 void run()
          Sends messages from the queue.
 void stopThread()
          Sets the 'run' variable to false, causing the thread to stop on its next loop.
 
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, 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

listeners

private final javax.swing.event.EventListenerList listeners

lmst

private long lmst

os

private java.io.OutputStream os

outgoingMessage

private java.util.concurrent.LinkedBlockingQueue<Message> outgoingMessage

run

private boolean run
Constructor Detail

MessageSender

public MessageSender(java.lang.String id,
                     java.io.OutputStream os)
Method Detail

addMessageToQueue

public void addMessageToQueue(Message m)
Puts the message in parameter in the queue, waiting to be sent

Parameters:
m - Message

addOutgoingListener

public void addOutgoingListener(OutgoingListener listener)

fireConnectionClosed

protected void fireConnectionClosed()
Called when the connection to the peer has been closed. Advertise the DownloadTask that there is no more connection to the remote peer.


fireKeepAliveSent

protected void fireKeepAliveSent()
Called when a keep-alive message has been sent. This happens about every 2 minutes if there has not been any other messages sent to avoid the connection to be closed by the remote peer


getOutgoingListeners

public OutgoingListener[] getOutgoingListeners()

removeOutgoingListener

public void removeOutgoingListener(OutgoingListener listener)

run

public void run()
Sends messages from the queue. While the queue is not empty, polls message from it and sends it to the remote peer. If the queue is empty for more than 2 minutes, a keep-alive message is sent and the DownloadTask is advertised

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

stopThread

public void stopThread()
Sets the 'run' variable to false, causing the thread to stop on its next loop.