com.fuse.net
Class FUSEConnectionManager

java.lang.Object
  extended by java.lang.Thread
      extended by com.fuse.net.FUSEConnectionManager
All Implemented Interfaces:
java.lang.Runnable

public class FUSEConnectionManager
extends java.lang.Thread

FUSEConnectionManager acts as a FUSEConnection pool. FUSEConnections are responsible of notifying the ConnectionManager when they get closed and can be returned to the pool.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.Vector availableConnections
           
protected  java.util.Vector busyConnections
           
protected  boolean closed
           
protected  FUSEConnectionFactory factory
           
protected  int maxConnections
           
protected  int MAXIMUM_ALLOWED_DELAY_BETWEEN_MSGS
           
protected  int total
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FUSEConnectionManager(int maxConnections, FUSEConnectionFactory factory)
          Constructor
 
Method Summary
 void broadcastToAll(java.lang.String type, java.lang.String data)
          Broadcasts message to all connections
 void broadcastToUsers(java.util.Vector users, java.lang.String type, java.lang.String data)
          Broadcasts message to a list of users
 void close()
           
 java.util.Vector getBusyConnections()
           
 int getMaxConnections()
           
 int getNumOfActiveConnections()
           
 int getTotalOfHandledConnections()
          Returns the number of handled connections during connection managers life time
 FUSEClientConnection getUserConnection(java.lang.String username)
          Returns connection for given username or NULL if not found
 void open()
           
 void releaseConnection(FUSEClientConnection conn)
          Called by a closed Connection
 void run()
           
 
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

availableConnections

protected java.util.Vector availableConnections

busyConnections

protected java.util.Vector busyConnections

maxConnections

protected int maxConnections

total

protected int total

MAXIMUM_ALLOWED_DELAY_BETWEEN_MSGS

protected final int MAXIMUM_ALLOWED_DELAY_BETWEEN_MSGS
See Also:
Constant Field Values

closed

protected boolean closed

factory

protected FUSEConnectionFactory factory
Constructor Detail

FUSEConnectionManager

public FUSEConnectionManager(int maxConnections,
                             FUSEConnectionFactory factory)
Constructor

Parameters:
maxConnections - max number of simultaneous connections
factory - factory object which constructs new network connection handlers
Method Detail

close

public void close()

open

public void open()

getTotalOfHandledConnections

public int getTotalOfHandledConnections()
Returns the number of handled connections during connection managers life time


run

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

broadcastToAll

public void broadcastToAll(java.lang.String type,
                           java.lang.String data)
Broadcasts message to all connections

Parameters:
type - type for data (such as "CHAT")
data - the actual data

broadcastToUsers

public void broadcastToUsers(java.util.Vector users,
                             java.lang.String type,
                             java.lang.String data)
Broadcasts message to a list of users

Parameters:
users - Vector of user names
type - type for data (such as "WHISPER")
data - the actual data

getUserConnection

public FUSEClientConnection getUserConnection(java.lang.String username)
Returns connection for given username or NULL if not found


releaseConnection

public void releaseConnection(FUSEClientConnection conn)
Called by a closed Connection


getBusyConnections

public java.util.Vector getBusyConnections()

getMaxConnections

public int getMaxConnections()

getNumOfActiveConnections

public int getNumOfActiveConnections()