Class 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 Detail

      • VNS_HOST_PROPERTY

        private static final java.lang.String VNS_HOST_PROPERTY
        See Also:
        Constant Field Values
      • VNS_HOST_PROPERTY_2

        private static final java.lang.String VNS_HOST_PROPERTY_2
        See Also:
        Constant Field Values
      • VNS_PORT_PROPERTY

        private static final java.lang.String VNS_PORT_PROPERTY
        See Also:
        Constant Field Values
      • VNS_PORT_PROPERTY_2

        private static final java.lang.String VNS_PORT_PROPERTY_2
        See Also:
        Constant Field Values
      • DEFAULT_RESOLVE_TIMEOUT

        private static final int DEFAULT_RESOLVE_TIMEOUT
        See Also:
        Constant Field Values
      • DEFAULT_SERVEON_TIMEOUT

        private static final int DEFAULT_SERVEON_TIMEOUT
        See Also:
        Constant Field Values
      • vnsResolveTimeout

        private int vnsResolveTimeout
      • vnsServeonTimeout

        private int vnsServeonTimeout
      • ttlMillis

        private int ttlMillis
      • allowStaleLookups

        private boolean allowStaleLookups
      • vnsCacheSize

        private int vnsCacheSize
      • host

        private java.lang.String host
      • port

        private int port
      • socketKeepAliveEnabled

        private boolean socketKeepAliveEnabled
      • vnsCache

        private java.util.LinkedHashMap vnsCache
    • Constructor Detail

      • VinciContext

        public VinciContext​(java.lang.String myhost,
                            int myport)
        Parameters:
        myhost - -
        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.
        Returns:
        -
        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.
        Returns:
        -
      • setVNSHost

        public void setVNSHost​(java.lang.String h)
        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:
        Socket.setKeepAlive(boolean)
      • setSocketKeepAliveEnabled

        public void setSocketKeepAliveEnabled​(boolean b)
        Set whether socket keepAlive is enabled. Default is true.
        Parameters:
        b - -
        See Also:
        Socket.setKeepAlive(boolean)
      • getGlobalContext

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

        public ResolveResult getCachedResolveResult​(java.lang.String serviceName)
        Get a cached resolve result (if any).
        Parameters:
        serviceName - -
        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.
        Parameters:
        serviceName - -
        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.
        Parameters:
        serviceName - -
        r - -
      • flushFromCache

        public void flushFromCache​(java.lang.String serviceName)
        Flush any cache entries pertaining to the specified service.
        Parameters:
        serviceName - -
      • flushAll

        public void flushAll()
      • 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().
        Parameters:
        in - -
        service_name - -
        factory - -
        socket_timeout - -
        Returns:
        -
        Throws:
        java.io.IOException - -
        ServiceException - -
        java.lang.IllegalStateException - if the VNS host has not been specified.
        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.
        Parameters:
        in - -
        service_name - -
        factory - -
        socket_timeout - -
        connect_timeout - -
        Returns:
        -
        Throws:
        java.io.IOException - -
        ServiceException - -
        java.lang.IllegalStateException - if the VNS host has not been specified.
        See Also:
        VinciClient