org.apache.vinci.transport.context
Class VinciContext

java.lang.Object
  extended by org.apache.vinci.transport.context.VinciContext

public class VinciContext
extends java.lang.Object

This class can be used to globally affect various behaviors of Vinci clients and servers under its control (for example, which VNS to contact). There is one "global" VinciContext that is used by default, though anyone can create an alternate context should multiple sets of defaults be required in a single program. Each VinciContext also serves to cache resolve results for all clients under its control (for a default of 1 minute).

For the most part, Vinci library users won't have to directly deal with this class, since there is a global context used by default which is almost always adequate.

The most common use of this class is to programmatically specify a VNS hostname other than the default (which is the one specified by the Java property VNS_HOST).


Field Summary
static int DEFAULT_VNS_CACHE_SIZE
           
 
Constructor Summary
VinciContext(java.lang.String myhost, int myport)
           
 
Method Summary
 boolean areStaleLookupsAllowed()
          Returns whether clients can use stale resolve cache entries for service location in the event VNS is unreachable.
 void cacheResolveResult(java.lang.String serviceName, ResolveResult r)
          Provide a resolve result to cache.
 void flushAll()
           
 void flushFromCache(java.lang.String serviceName)
          Flush any cache entries pertaining to the specified service.
 ResolveResult getCachedResolveResult(java.lang.String serviceName)
          Get a cached resolve result (if any).
static VinciContext getGlobalContext()
          Get the global VinciContext used by Vinci classes when no context is explicitly specified.
 int getResolveCacheTTL()
          Get the time-to-live of cached service locators (resolve results).
 ResolveResult getStaleCachedResolveResult(java.lang.String serviceName)
          Get a cached resolve result (if any), but allow returning stale cache entries.
 java.lang.String getVNSHost()
          Return the VNS hostname.
 int getVNSPort()
          Return the VNS listener port.
 int getVNSResolveTimeout()
          Get the timeout setting of VNS resolve queries.
 int getVNSServeonTimeout()
          Get the timeout setting of VNS serveon queries.
 boolean isSocketKeepAliveEnabled()
          Returns whether socket keepAlive is enabled.
 VinciFrame rpc(Transportable in, java.lang.String service_name)
          See documentation for VinciClient.rpc().
 VinciFrame rpc(Transportable in, java.lang.String service_name, int timeout)
          See documentation for VinciClient.rpc().
 VinciFrame rpc(Transportable in, java.lang.String service_name, int socket_timeout, int connect_timeout)
          See documentation for VinciClient.rpc().
 Transportable sendAndReceive(Transportable in, java.lang.String service_name, TransportableFactory factory)
          See documentation for VinciClient.sendAndReceive().
 Transportable sendAndReceive(Transportable in, java.lang.String service_name, TransportableFactory factory, int socket_timeout)
          See documentation for VinciClient.sendAndReceive().
 Transportable sendAndReceive(Transportable in, java.lang.String service_name, TransportableFactory factory, int socket_timeout, int connect_timeout)
          See documentation for VinciClient.sendAndReceive().
 void setAllowStaleLookups(boolean b)
          Set whether clients can use stale resolve cache entries for service location in the event VNS is unreachable.
 void setResolveCacheTTL(int millis)
          Set the time-to-live of cached service locators (resolve results).
 void setSocketKeepAliveEnabled(boolean b)
          Set whether socket keepAlive is enabled.
 void setVNSCacheSize(int to)
          Set the size of the VNS cache.
 void setVNSHost(java.lang.String h)
          Set the VNS hostname.
 void setVNSPort(int p)
          Set the VNS port.
 void setVNSResolveTimeout(int millis)
          Set the timeout of VNS resolve queries.
 void setVNSServeonTimeout(int millis)
          Set the timeout of VNS serveon queries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_VNS_CACHE_SIZE

public static final int DEFAULT_VNS_CACHE_SIZE
See Also:
Constant Field Values
Constructor Detail

VinciContext

public VinciContext(java.lang.String myhost,
                    int myport)
Method Detail

setVNSCacheSize

public void setVNSCacheSize(int to)
Set the size of the VNS cache. This method can be invoked at any time, however if the cache size is ever reduced, it might not take effect.

Parameters:
to - The limit on the number of entries that will be maintained in the VNS cache.

getVNSHost

public java.lang.String getVNSHost()
Return the VNS hostname. When the global instance of this class is first loaded, it will set the hostname from the java property VNS_HOST. To set the VNS_HOST using this java property, you must therefore specify the property before the class is ever referenced, e.g. through the command-line property option -DVNS_HOST=[hostname], or by calling System.setProperty("VNS_HOST", [hostname]) before ever invoking any Vinci client code. Otherwise, you can set the hostname using the setVNSHost() method provided by this class.

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.

getVNSPort

public int getVNSPort()
Return the VNS listener port. When the global instance of this class is first loaded, it will attempt to set the port number from the java property VNS_PORT. To set the port using this java property, you must therefore specify the VNS_PORT property before the class is ever referenced, e.g. through the command-line property option -DVNS_PORT=[hostname], or by calling System.setProperty("VNS_PORT", [hostname]) before ever invoking any Vinci client code. Otherwise, the port will default to 9000. You can override this default (or any property-specified value) by calling the setPort() method provided by this class.


setVNSHost

public void setVNSHost(java.lang.String h)
Set the VNS hostname.


setVNSPort

public void setVNSPort(int p)
Set the VNS port.


areStaleLookupsAllowed

public boolean areStaleLookupsAllowed()
Returns whether clients can use stale resolve cache entries for service location in the event VNS is unreachable.


setAllowStaleLookups

public void setAllowStaleLookups(boolean b)
Set whether clients can use stale resolve cache entries for service location in the event VNS is unreachable. Default is true.


getResolveCacheTTL

public int getResolveCacheTTL()
Get the time-to-live of cached service locators (resolve results).


setResolveCacheTTL

public void setResolveCacheTTL(int millis)
Set the time-to-live of cached service locators (resolve results). Default is 1 minute. Set to 0 to disable caching completely.


getVNSResolveTimeout

public int getVNSResolveTimeout()
Get the timeout setting of VNS resolve queries.


setVNSResolveTimeout

public void setVNSResolveTimeout(int millis)
Set the timeout of VNS resolve queries. Default is 20 seconds.


getVNSServeonTimeout

public int getVNSServeonTimeout()
Get the timeout setting of VNS serveon queries.


setVNSServeonTimeout

public void setVNSServeonTimeout(int millis)
Set the timeout of VNS serveon queries. Default is 60 seconds.


isSocketKeepAliveEnabled

public boolean isSocketKeepAliveEnabled()
Returns whether socket keepAlive is enabled.

See Also:
Socket.setKeepAlive(boolean)

setSocketKeepAliveEnabled

public void setSocketKeepAliveEnabled(boolean b)
Set whether socket keepAlive is enabled. Default is true.

See Also:
Socket.setKeepAlive(boolean)

getGlobalContext

public static VinciContext getGlobalContext()
Get the global VinciContext used by Vinci classes when no context is explicitly specified.


getCachedResolveResult

public ResolveResult getCachedResolveResult(java.lang.String serviceName)
Get a cached resolve result (if any).

Returns:
the cached resolve result, or null if none is cached.

getStaleCachedResolveResult

public ResolveResult getStaleCachedResolveResult(java.lang.String serviceName)
Get a cached resolve result (if any), but allow returning stale cache entries.

Returns:
the cached resolve result, or null if none is cached.

cacheResolveResult

public void cacheResolveResult(java.lang.String serviceName,
                               ResolveResult r)
Provide a resolve result to cache.


flushFromCache

public void flushFromCache(java.lang.String serviceName)
Flush any cache entries pertaining to the specified service.


flushAll

public void flushAll()

sendAndReceive

public Transportable sendAndReceive(Transportable in,
                                    java.lang.String service_name,
                                    TransportableFactory factory)
                             throws java.io.IOException,
                                    ServiceException,
                                    ServiceDownException,
                                    VNSException
See documentation for VinciClient.sendAndReceive().

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.
java.io.IOException
ServiceException
ServiceDownException
VNSException
See Also:
VinciClient

sendAndReceive

public Transportable sendAndReceive(Transportable in,
                                    java.lang.String service_name,
                                    TransportableFactory factory,
                                    int socket_timeout)
                             throws java.io.IOException,
                                    ServiceException
See documentation for VinciClient.sendAndReceive().

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.
java.io.IOException
ServiceException
See Also:
VinciClient

sendAndReceive

public Transportable sendAndReceive(Transportable in,
                                    java.lang.String service_name,
                                    TransportableFactory factory,
                                    int socket_timeout,
                                    int connect_timeout)
                             throws java.io.IOException,
                                    ServiceException
See documentation for VinciClient.sendAndReceive(). WARNING: This method relies on JDK-1.4 specific functions. USE IT ONLY if you don't need to maintain JDK1.3 compatability.

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.
java.io.IOException
ServiceException
See Also:
VinciClient

rpc

public VinciFrame rpc(Transportable in,
                      java.lang.String service_name)
               throws java.io.IOException,
                      ServiceException,
                      ServiceDownException,
                      VNSException
See documentation for VinciClient.rpc().

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.
java.io.IOException
ServiceException
ServiceDownException
VNSException
See Also:
VinciClient

rpc

public VinciFrame rpc(Transportable in,
                      java.lang.String service_name,
                      int timeout)
               throws java.io.IOException,
                      ServiceException,
                      ServiceDownException,
                      VNSException
See documentation for VinciClient.rpc().

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.
java.io.IOException
ServiceException
ServiceDownException
VNSException
See Also:
VinciClient

rpc

public VinciFrame rpc(Transportable in,
                      java.lang.String service_name,
                      int socket_timeout,
                      int connect_timeout)
               throws java.io.IOException,
                      ServiceException,
                      ServiceDownException,
                      VNSException
See documentation for VinciClient.rpc(). WARNING: This method relies on JDK-1.4 specific functions. USE IT ONLY if you don't need to maintain JDK1.3 compatability.

Throws:
java.lang.IllegalStateException - if the VNS host has not been specified.
java.io.IOException
ServiceException
ServiceDownException
VNSException
See Also:
VinciClient


Copyright © 2012. All Rights Reserved.