danger.net
Class IPCServerSocket

java.lang.Object
  extended by danger.net.IPCServerSocket


public final class IPCServerSocket
extends Object

The server side of an IPC socket. The public methods mimic the methods from java.io.ServerSocket.


Constructor Summary
IPCServerSocket(String name, IPCServerSocket.CloseListener closeListener)
          Construct an instance.
 
Method Summary
 IPCSocket accept()
          Accept a connection.
 void close()
          Close this instance.
 IPCServerSocket.Connector getConnector()
          Get the associated Connector.
 String getName()
          Get the name associated with this instance.
 int getSoTimeout()
          Get the timeout of this instance.
 boolean isClosed()
          Return whether or not this instance is closed.
 void setSoTimeout(int timeout)
          Set the timeout of this instance.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IPCServerSocket

public IPCServerSocket(String name,
                       IPCServerSocket.CloseListener closeListener)
Construct an instance.

Parameters:
name - non-null; the name the instance is bound to
closeListener - null-ok; object to notify when this instance is closed
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getName

public String getName()
Get the name associated with this instance.

Returns:
non-null; the name

getConnector

public IPCServerSocket.Connector getConnector()
Get the associated Connector. For security reasons, this method works exactly once: the entity that creates this instance should call this method to retrieve the connector, and then only that entity has the power to cause a connection to happen. Once that happens, then this instance may be handed out freely, knowing that it can only be used to accept--not instigate--connections.

Returns:
non-null; the associated connector
Throws:
RuntimeException - thrown if this method has already been called

accept

public IPCSocket accept()
                 throws IOException
Accept a connection. This will block until a connection is established or until the timeout occurs. If the timeout occurs, then this method throws InterruptedIOException.

Returns:
non-null; a socket representing the newly-established connection
Throws:
IOException - thrown if there's trouble

close

public void close()
           throws IOException
Close this instance.

Throws:
IOException - thrown if there's trouble

isClosed

public boolean isClosed()
Return whether or not this instance is closed.

Returns:
true iff this instance is closed

setSoTimeout

public void setSoTimeout(int timeout)
                  throws SocketException
Set the timeout of this instance. The timeout must be non-negative, and it is a number of milliseconds to wait at most in a call to accept(). If it is passed as 0, then it indicates that accept calls should block indefinitely.

Parameters:
timeout - >= 0; the new timeout value, in milliseconds
Throws:
SocketException - thrown if there's trouble
See Also:
getSoTimeout()

getSoTimeout

public int getSoTimeout()
                 throws IOException
Get the timeout of this instance.

Returns:
>= 0; the timeout value, in milliseconds
Throws:
IOException - thrown if there's trouble
See Also:
setSoTimeout(int)