jBittorrentAPI
Class ConnectionListener

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

public class ConnectionListener
extends java.lang.Thread

Thread that can listen for remote peers connection tries to this client


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean acceptConnection
           
private  int connectedPort
           
private  javax.swing.event.EventListenerList listeners
           
private  int maxPort
           
private  int minPort
           
private  java.net.ServerSocket ss
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConnectionListener()
           
ConnectionListener(int minPort, int maxPort)
           
 
Method Summary
 void addConListenerInterface(ConListenerInterface listener)
           
 boolean connect()
          Try to create a server socket for remote peers to connect on within current port range
 boolean connect(int minPort, int maxPort)
          Try to create a server socket for remote peers to connect on within the specified port range
protected  void fireConnectionAccepted(java.net.Socket s)
          Method used to send message to all object currently listening on this thread when a new connection has been accepted.
 ConListenerInterface[] getConListenerInterfaces()
           
 int getConnectedPort()
          Returns the port this client is listening on
 int getMaxPort()
          Returns the maximal port number this client will try to listen on
 int getMinPort()
          Returns the minimal port number this client will try to listen on
 void removeConListenerInterface(ConListenerInterface listener)
           
 void run()
           
 void setAccept(boolean accept)
          Decides if the client should accept or not future connection
 void setMaxPort(int maxPort)
          Sets the minimal port number this client will try to listen on
 void setMinPort(int minPort)
          Sets the minimal port number this client will try to listen on
 
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

acceptConnection

private boolean acceptConnection

connectedPort

private int connectedPort

listeners

private final javax.swing.event.EventListenerList listeners

maxPort

private int maxPort

minPort

private int minPort

ss

private java.net.ServerSocket ss
Constructor Detail

ConnectionListener

public ConnectionListener()

ConnectionListener

public ConnectionListener(int minPort,
                          int maxPort)
Method Detail

addConListenerInterface

public void addConListenerInterface(ConListenerInterface listener)

connect

public boolean connect()
Try to create a server socket for remote peers to connect on within current port range

Returns:
boolean

connect

public boolean connect(int minPort,
                       int maxPort)
Try to create a server socket for remote peers to connect on within the specified port range

Parameters:
minPort - The minimal port number this client should listen on
maxPort - The maximal port number this client should listen on
Returns:
boolean

fireConnectionAccepted

protected void fireConnectionAccepted(java.net.Socket s)
Method used to send message to all object currently listening on this thread when a new connection has been accepted. It provides the socket the connection is bound to.

Parameters:
s - Socket

getConListenerInterfaces

public ConListenerInterface[] getConListenerInterfaces()

getConnectedPort

public int getConnectedPort()
Returns the port this client is listening on

Returns:
int

getMaxPort

public int getMaxPort()
Returns the maximal port number this client will try to listen on

Returns:
int

getMinPort

public int getMinPort()
Returns the minimal port number this client will try to listen on

Returns:
int

removeConListenerInterface

public void removeConListenerInterface(ConListenerInterface listener)

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setAccept

public void setAccept(boolean accept)
Decides if the client should accept or not future connection

Parameters:
accept - true if it should accept, false otherwise

setMaxPort

public void setMaxPort(int maxPort)
Sets the minimal port number this client will try to listen on

Parameters:
maxPort - int

setMinPort

public void setMinPort(int minPort)
Sets the minimal port number this client will try to listen on

Parameters:
minPort - int