com.nhncorp.neptune.common.ipc
Class NClient

java.lang.Object
  extended by com.nhncorp.neptune.common.ipc.NClient

public class NClient
extends java.lang.Object

A client for an IPC service. IPC calls take a single NWritable as a parameter, and return a NWritable as their value. A service runs on a port and is defined by a parameter class and a value class.

Author:
Doug Cutting
See Also:
NServer

Field Summary
static org.apache.commons.logging.Log LOG
           
 java.util.Random random
           
static int READ_TIMEOUT
           
 
Constructor Summary
NClient(java.lang.Class<?> valueClass, NConfiguration conf)
          Construct an IPC client with the default SocketFactory
NClient(java.lang.Class valueClass, NConfiguration conf, javax.net.SocketFactory factory)
          Construct an IPC client whose values are of the given NWritable class.
 
Method Summary
 NWritable[] call(NWritable[] params, java.net.InetSocketAddress[] addresses)
          Makes a set of calls in parallel.
 NWritable call(NWritable param, java.net.InetSocketAddress address)
          Make a call, passing param, to the IPC server running at address, returning the value.
 void onewayCall(NWritable param, java.net.InetSocketAddress address)
           
 void setTimeout(int timeout)
          Sets the timeout used for network i/o.
 void stop()
          Stop all threads related to this client.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_TIMEOUT

public static int READ_TIMEOUT

LOG

public static final org.apache.commons.logging.Log LOG

random

public java.util.Random random
Constructor Detail

NClient

public NClient(java.lang.Class valueClass,
               NConfiguration conf,
               javax.net.SocketFactory factory)
Construct an IPC client whose values are of the given NWritable class.


NClient

public NClient(java.lang.Class<?> valueClass,
               NConfiguration conf)
Construct an IPC client with the default SocketFactory

Parameters:
valueClass -
conf -
Method Detail

stop

public void stop()
Stop all threads related to this client. No further calls may be made using this client.


setTimeout

public void setTimeout(int timeout)
Sets the timeout used for network i/o.


call

public NWritable call(NWritable param,
                      java.net.InetSocketAddress address)
               throws java.lang.InterruptedException,
                      java.io.IOException
Make a call, passing param, to the IPC server running at address, returning the value. Throws exceptions if there are network problems or if the remote code threw an exception.

Throws:
java.lang.InterruptedException
java.io.IOException

onewayCall

public void onewayCall(NWritable param,
                       java.net.InetSocketAddress address)
                throws java.lang.InterruptedException,
                       java.io.IOException
Throws:
java.lang.InterruptedException
java.io.IOException

call

public NWritable[] call(NWritable[] params,
                        java.net.InetSocketAddress[] addresses)
                 throws java.io.IOException
Makes a set of calls in parallel. Each parameter is sent to the corresponding address. When all values are available, or have timed out or errored, the collected results are returned in an array. The array contains nulls for calls that timed out or errored.

Throws:
java.io.IOException