Class VinciContext
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether clients can use stale resolve cache entries for service location in the event VNS is unreachable.void
cacheResolveResult
(String serviceName, ResolveResult r) Provide a resolve result to cache.void
flushAll()
void
flushFromCache
(String serviceName) Flush any cache entries pertaining to the specified service.getCachedResolveResult
(String serviceName) Get a cached resolve result (if any).static VinciContext
Get the global VinciContext used by Vinci classes when no context is explicitly specified.int
Get the time-to-live of cached service locators (resolve results).getStaleCachedResolveResult
(String serviceName) Get a cached resolve result (if any), but allow returning stale cache entries.Return the VNS hostname.int
Return the VNS listener port.int
Get the timeout setting of VNS resolve queries.int
Get the timeout setting of VNS serveon queries.boolean
Returns whether socket keepAlive is enabled.rpc
(Transportable in, String service_name) See documentation for VinciClient.rpc().rpc
(Transportable in, String service_name, int timeout) See documentation for VinciClient.rpc().rpc
(Transportable in, String service_name, int socket_timeout, int connect_timeout) See documentation for VinciClient.rpc().sendAndReceive
(Transportable in, String service_name, TransportableFactory factory) See documentation for VinciClient.sendAndReceive().sendAndReceive
(Transportable in, String service_name, TransportableFactory factory, int socket_timeout) See documentation for VinciClient.sendAndReceive().sendAndReceive
(Transportable in, 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
(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.
-
Field Details
-
DEFAULT_VNS_CACHE_SIZE
public static final int DEFAULT_VNS_CACHE_SIZE- See Also:
-
-
Constructor Details
-
VinciContext
- Parameters:
myhost
- -myport
- -
-
-
Method Details
-
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
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.- Returns:
- -
- Throws:
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.- Returns:
- -
-
setVNSHost
Set the VNS hostname.- Parameters:
h
- -
-
setVNSPort
public void setVNSPort(int p) Set the VNS port.- Parameters:
p
- -
-
areStaleLookupsAllowed
public boolean areStaleLookupsAllowed()Returns whether clients can use stale resolve cache entries for service location in the event VNS is unreachable.- Returns:
- -
-
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.- Parameters:
b
- -
-
getResolveCacheTTL
public int getResolveCacheTTL()Get the time-to-live of cached service locators (resolve results).- Returns:
- -
-
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.- Parameters:
millis
- -
-
getVNSResolveTimeout
public int getVNSResolveTimeout()Get the timeout setting of VNS resolve queries.- Returns:
- -
-
setVNSResolveTimeout
public void setVNSResolveTimeout(int millis) Set the timeout of VNS resolve queries. Default is 20 seconds.- Parameters:
millis
- -
-
getVNSServeonTimeout
public int getVNSServeonTimeout()Get the timeout setting of VNS serveon queries.- Returns:
- -
-
setVNSServeonTimeout
public void setVNSServeonTimeout(int millis) Set the timeout of VNS serveon queries. Default is 60 seconds.- Parameters:
millis
- -
-
isSocketKeepAliveEnabled
public boolean isSocketKeepAliveEnabled()Returns whether socket keepAlive is enabled.- Returns:
- -
- See Also:
-
setSocketKeepAliveEnabled
public void setSocketKeepAliveEnabled(boolean b) Set whether socket keepAlive is enabled. Default is true.- Parameters:
b
- -- See Also:
-
getGlobalContext
Get the global VinciContext used by Vinci classes when no context is explicitly specified.- Returns:
- -
-
getCachedResolveResult
Get a cached resolve result (if any).- Parameters:
serviceName
- -- Returns:
- the cached resolve result, or null if none is cached.
-
getStaleCachedResolveResult
Get a cached resolve result (if any), but allow returning stale cache entries.- Parameters:
serviceName
- -- Returns:
- the cached resolve result, or null if none is cached.
-
cacheResolveResult
Provide a resolve result to cache.- Parameters:
serviceName
- -r
- -
-
flushFromCache
Flush any cache entries pertaining to the specified service.- Parameters:
serviceName
- -
-
flushAll
public void flushAll() -
sendAndReceive
public Transportable sendAndReceive(Transportable in, String service_name, TransportableFactory factory) throws IOException, ServiceException, ServiceDownException, VNSException See documentation for VinciClient.sendAndReceive().- Parameters:
in
- -service_name
- -factory
- -- Returns:
- -
- Throws:
IOException
- -ServiceException
- -ServiceDownException
- -VNSException
- -IllegalStateException
- if the VNS host has not been specified.- See Also:
-
sendAndReceive
public Transportable sendAndReceive(Transportable in, String service_name, TransportableFactory factory, int socket_timeout) throws IOException, ServiceException See documentation for VinciClient.sendAndReceive().- Parameters:
in
- -service_name
- -factory
- -socket_timeout
- -- Returns:
- -
- Throws:
IOException
- -ServiceException
- -IllegalStateException
- if the VNS host has not been specified.- See Also:
-
sendAndReceive
public Transportable sendAndReceive(Transportable in, String service_name, TransportableFactory factory, int socket_timeout, int connect_timeout) throws 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.- Parameters:
in
- -service_name
- -factory
- -socket_timeout
- -connect_timeout
- -- Returns:
- -
- Throws:
IOException
- -ServiceException
- -IllegalStateException
- if the VNS host has not been specified.- See Also:
-
rpc
public VinciFrame rpc(Transportable in, String service_name) throws IOException, ServiceException, ServiceDownException, VNSException See documentation for VinciClient.rpc().- Parameters:
in
- -service_name
- -- Returns:
- -
- Throws:
IOException
- -ServiceException
- -ServiceDownException
- -VNSException
- -IllegalStateException
- if the VNS host has not been specified.- See Also:
-
rpc
public VinciFrame rpc(Transportable in, String service_name, int timeout) throws IOException, ServiceException, ServiceDownException, VNSException See documentation for VinciClient.rpc().- Parameters:
in
- -service_name
- -timeout
- -- Returns:
- -
- Throws:
IOException
- -ServiceException
- -ServiceDownException
- -VNSException
- -IllegalStateException
- if the VNS host has not been specified.- See Also:
-
rpc
public VinciFrame rpc(Transportable in, String service_name, int socket_timeout, int connect_timeout) throws 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.- Parameters:
in
- -service_name
- -socket_timeout
- -connect_timeout
- -- Returns:
- -
- Throws:
IOException
- -ServiceException
- -ServiceDownException
- -VNSException
- -IllegalStateException
- if the VNS host has not been specified.- See Also:
-