one.world.io
Class NetworkIO.Client

java.lang.Object
  |
  +--one.world.util.AbstractHandler
        |
        +--one.world.io.NetworkIO.Client
All Implemented Interfaces:
EventHandler, Serializable
Enclosing class:
NetworkIO

protected class NetworkIO.Client
extends AbstractHandler

A reliable network I/O client. Implements structured I/O over a TCP client socket, providing reliable, in-order delivery. Handles SimpleInputRequests and SimpleOutputRequests.

Network I/O clients generally should be obtained via a binding request to the environment's request handler.

Note that any exception on the underlying object stream or socket will cause the resource to be revoked.

Internal fields and methods are protected so that a subclass can access or override any method, for instance to build an encrypted network I/O client.

See Also:
SioResource, BindingRequest, Environment, Serialized Form

Inner Class Summary
protected  class NetworkIO.Client.Listener
          Listens for data arriving from the network.
protected  class NetworkIO.Client.RevokationHandler
          The revokation handler.
 
Field Summary
protected  ObjectInputStream inputStream
          The object input stream for receiving tuples.
protected  boolean isRevoked
          Indicates whether the resource has been revoked.
protected  EventHandler leaseHandler
          The lease manager to use for requesting leases.
protected  Object lock
          The lock object.
protected  ObjectOutputStream outputStream
          The object output stream for sending tuples.
protected  EventHandler requester
          The original requester of the resource.
protected  SioResource sioResource
          The SioResource (for debugging only).
protected  Socket socket
          The socket.
 
Constructor Summary
protected NetworkIO.Client(EventHandler requester, SioResource sioResource, Socket socket, EventHandler leaseHandler, NestedConcurrencyDomain cDomain)
          Create a new reliable network channel using the specified socket, in the specified environment.
 
Method Summary
 boolean handle1(Event event)
          Handles SimpleInputRequest and SimpleOutputRequest events.
protected  void put(SimpleOutputRequest request)
          Handles a put request by writing the tuple to the network channel.
protected  void requestTermination()
          Request that the nested concurrency domain be revoked.
protected  void revoke()
          Revokes the network I/O client resource.
protected  void revoke1()
          Revokes the network I/O client resource.
protected  void terminate()
          Terminates the nested concurrency domain.
 String toString()
          Returns a string representation of this network I/O client.
 
Methods inherited from class one.world.util.AbstractHandler
handle, isNotValid, respond, respond, respond, respond, respond, respond
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

requester

protected EventHandler requester
The original requester of the resource.

sioResource

protected final SioResource sioResource
The SioResource (for debugging only).

leaseHandler

protected EventHandler leaseHandler
The lease manager to use for requesting leases.

socket

protected Socket socket
The socket.

outputStream

protected ObjectOutputStream outputStream
The object output stream for sending tuples.

inputStream

protected volatile ObjectInputStream inputStream
The object input stream for receiving tuples. We do NOT wrap this stream in a lock because it is only read from in the NetworkIO.Client.Listener thread. Furthermore, we must be able to interrupt this thread by closing the socket.

lock

protected Object lock
The lock object.

isRevoked

protected volatile boolean isRevoked
Indicates whether the resource has been revoked. This should only be set by the revoke() method, but subclasses may need to read it to decide whether the resource is active.
Constructor Detail

NetworkIO.Client

protected NetworkIO.Client(EventHandler requester,
                           SioResource sioResource,
                           Socket socket,
                           EventHandler leaseHandler,
                           NestedConcurrencyDomain cDomain)
                    throws IOException
Create a new reliable network channel using the specified socket, in the specified environment. A thread is created to listen on the socket.
Parameters:
requester - The source of the original resource request.
sioResource - The SIO resource descriptor.
socket - The TCP socket to use for the channel.
leaseHandler - The lease manager used to acquire leases.
cDomain - The nested concurrency domain for the client.
Throws:
IOException - Signals an error in configuring the socket or obtaining the I/O streams.
Method Detail

handle1

public boolean handle1(Event event)
Handles SimpleInputRequest and SimpleOutputRequest events. A SimpleOutputRequest results in the tuple being sent over the network channel. SimpleInputRequests will wait for results until the timeout expires.

Also handles LeaseEvent.CANCELED events by revoking the resource.

Overrides:
handle1 in class AbstractHandler
Parameters:
event - The event to handle.

put

protected void put(SimpleOutputRequest request)
Handles a put request by writing the tuple to the network channel.

An I/O exception indicates that the output stream, outputStream, has been closed. This is an abnormal condition. An error is logged and the resource is revoked.

Parameters:
request - The output request.

revoke

protected void revoke()
Revokes the network I/O client resource. Thread safe.

If the system is shutting down, actually revokes the resource. Otherwise, queues a RevokeEvent in the nested concurrency domain.


revoke1

protected void revoke1()
Revokes the network I/O client resource. Not thread safe; writes to and closes the socket without a lock. This method must be executed either from the nested concurrency domain thread or during system shutdown

Clean-up includes interrupting and nullifying the listener thread, and closing and nullifying the streams and socket. May be called repeatedly without ill effects.


requestTermination

protected void requestTermination()
Request that the nested concurrency domain be revoked. We do this using an event because we are currently running from the nested concurrency domain, and the termination must happen within the environment's concurrency domain to avoid deadlock.

terminate

protected void terminate()
Terminates the nested concurrency domain. This should run in the main environment's concurrency domain; i.e., outside the nested concurrency domain.

toString

public String toString()
Returns a string representation of this network I/O client.
Overrides:
toString in class Object


(C) Copyright 2001 UW CSE