Package org.globus.ftp.dc
Class SocketPool
- java.lang.Object
-
- org.globus.ftp.dc.SocketPool
-
public class SocketPool extends java.lang.ObjectRepresents a set of open sockets that are being cached for subsequent transfers. CheckIn() a socket to add it to the pool. Other threads can use it. CheckOut() a socket to mark it busy; it will remain in the pool but noone else can check it out. Finally, you can remove a socket from the pool, in which case the pool will remove it from all its references.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashtableallSocketsprotected java.util.HashtablebusySocketsprotected java.util.HashtablefreeSockets
-
Constructor Summary
Constructors Constructor Description SocketPool()Constructor for SocketPool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(SocketBox sb)add socketBox to the pool.voidapplyToAll(SocketOperator op)Apply the suplied callback to all socketBoxes.voidcheckIn(SocketBox sb)Before calling this method, the socket needs to be first add()ed to the pool and checked out.SocketBoxcheckOut()checks out the next free socket and returns it, or returns null if there aren't any.intcount()intcountBusy()intcountFree()voidflush()Forcibly close all sockets, and remove them from the pool.booleanhasFree()voidremove(SocketBox sb)remove socketBox from the pool, remove all references to it
-
-
-
Method Detail
-
add
public void add(SocketBox sb)
add socketBox to the pool. Depending on its state, it will be added to free or busy sockets.
-
remove
public void remove(SocketBox sb)
remove socketBox from the pool, remove all references to it
-
checkOut
public SocketBox checkOut()
checks out the next free socket and returns it, or returns null if there aren't any. Before calling this method, the socket needs to be first add()ed to the pool.
-
checkIn
public void checkIn(SocketBox sb)
Before calling this method, the socket needs to be first add()ed to the pool and checked out. Note: checking in a socket that is not reusable will cause its removal from the pool.
-
count
public int count()
- Returns:
- number of all cached sockets
-
countFree
public int countFree()
- Returns:
- number of free sockets
-
countBusy
public int countBusy()
- Returns:
- number of busy sockets
-
hasFree
public boolean hasFree()
- Returns:
- true if there is at least 1 free socket
-
applyToAll
public void applyToAll(SocketOperator op) throws java.lang.Exception
Apply the suplied callback to all socketBoxes.- Throws:
java.lang.Exception
-
flush
public void flush() throws java.io.IOExceptionForcibly close all sockets, and remove them from the pool.- Throws:
java.io.IOException
-
-