org.sapia.ubik.net.mplex
Class SocketQueue
java.lang.Object
org.sapia.ubik.net.mplex.SocketQueue
public class SocketQueue
- extends java.lang.Object
This class implements a simple asynchronous, thread safe, FIFO queue of
Socket objects. A producer actor can add a new socket to the
queue by calling the add(Socket) method. A consumer actor can
retrieve the next available socket from the queue using the getSocket()
method.
Upon creation a SocketQueue is considered active or open; therefore
producers and consumers can use the queue. When the queue is no longer necessary
the close() method will put the queue in a closed state where:
- All the pending
Socket objects in the queue will be removed
from the queue and then explicitly closed.
- All the consumers that are blocked on the
getSocket() method
will return with a SocketException.
- Any future call to the
add(Socket) or getSocket()
method will result in a SocketException.
- Author:
- Jean-Cedric Desrochers
- Copyright:
- Copyright © 2002-2004
Sapia Open Source Software. All Rights Reserved.
- License:
- Read the license.txt file of the jar or visit the
license page
at the Sapia OSS web site
|
Constructor Summary |
SocketQueue()
Creates a new SocketQueue instance. |
|
Method Summary |
void |
add(java.net.Socket aSocket)
Asynchronously add the socket passed in to the internal queue. |
void |
close()
Close this queue. |
java.io.IOException |
getException()
Returns the current exception of this queue. |
java.net.Socket |
getSocket()
Returns the next available socket. |
void |
setException(java.io.IOException anException)
Sets the exception to this queue. |
int |
size()
Returns the number of socket pending in the internal queue. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SocketQueue
public SocketQueue()
- Creates a new SocketQueue instance.
add
public void add(java.net.Socket aSocket)
throws java.net.SocketException
- Asynchronously add the socket passed in to the internal queue.
- Parameters:
aSocket - The socket to add.
- Throws:
java.net.SocketException
getSocket
public java.net.Socket getSocket()
throws java.io.IOException
- Returns the next available socket. This method will block until
a socket is available.
- Returns:
- The next available socket.
- Throws:
java.io.IOException
close
public void close()
- Close this queue.
setException
public void setException(java.io.IOException anException)
- Sets the exception to this queue.
- Parameters:
anException - The exception to send to the client.
getException
public java.io.IOException getException()
- Returns the current exception of this queue.
- Returns:
- The current exception of this queue.
size
public int size()
- Returns the number of socket pending in the internal queue.
- Returns:
- The number of socket pending in the internal queue.
Copyright © 2010 Sapia OSS. All Rights Reserved.