Class LocatorLauncher

  • All Implemented Interfaces:
    java.lang.Runnable

    public class LocatorLauncher
    extends AbstractLauncher<java.lang.String>
    The LocatorLauncher class is a launcher for a Geode Locator.
    Since:
    GemFire 7.0
    See Also:
    AbstractLauncher, ServerLauncher
    • Method Detail

      • main

        @Deprecated
        public static void main​(java.lang.String... args)
        Deprecated.
        as of 10.0 Please use com.vmware.gemfire.bootstrap.LocatorLauncher
        Launches a Geode Locator from the command-line configured with the given arguments.
        Parameters:
        args - the command-line arguments used to configure the Geode Locator at runtime.
      • getInstance

        public static LocatorLauncher getInstance()
        Gets the instance of the LocatorLauncher used to launch the Geode Locator, or null if this VM does not have an instance of LocatorLauncher indicating no Geode Locator is running.
        Returns:
        the instance of LocatorLauncher used to launcher a Geode Locator in this VM.
      • getLocatorState

        public static LocatorLauncher.LocatorState getLocatorState()
        Gets the LocatorState for this process or null if this process was not launched using this VM's LocatorLauncher reference.
        Returns:
        the LocatorState for this process or null.
      • statusLocator

        @Deprecated
        public static org.apache.geode.cache.client.internal.locator.LocatorStatusResponse statusLocator​(int port,
                                                                                                         java.net.InetAddress bindAddress)
                                                                                                  throws java.io.IOException
        Deprecated.
        in Geode 1.12. Use statusForLocator() instance method instead. This static method does not use the properties set via the Builder.
        Returns the status of the locator on the given host and port
        Parameters:
        port - the port that the locator is listening on
        bindAddress - the IP address to which the locator's socket binds
        Returns:
        a LocatorStatusResponse representing the status of the locator
        Throws:
        java.io.IOException - if there is a problem interacting with the locator
      • statusForLocator

        public org.apache.geode.cache.client.internal.locator.LocatorStatusResponse statusForLocator​(int port,
                                                                                                     java.net.InetAddress bindAddressArg)
                                                                                              throws java.io.IOException
        Returns the status of the locator on the given host and port. If you have endpoint identification enabled the preferred method is statusForLocator(int, String), which lets you specify the locator's name that the locator has stored in its TLS certificate
        Parameters:
        port - the port that the locator is listening on
        bindAddressArg - the IP address to which the locator's socket binds
        Returns:
        a LocatorStatusResponse representing the status of the locator
        Throws:
        java.io.IOException - if there is a problem interacting with the locator
      • statusForLocator

        public org.apache.geode.cache.client.internal.locator.LocatorStatusResponse statusForLocator​(int port,
                                                                                                     java.lang.String hostname)
                                                                                              throws java.io.IOException
        Returns the status of the locator on the given host and port
        Parameters:
        port - the port that the locator is listening on
        hostname - the host name or ip address that the locator is listening on.
        Returns:
        a LocatorStatusResponse representing the status of the locator
        Throws:
        java.io.IOException - if there is a problem interacting with the locator
      • getCache

        public Cache getCache()
        Gets a reference to the Cache that was created by this LocatorLauncher.
        Returns:
        a reference to the Cache
        See Also:
        Cache
      • getLocator

        public Locator getLocator()
        Gets a reference to the Locator that was created by this LocatorLauncher.
        Returns:
        a reference to the Locator.
        See Also:
        Locator
      • getId

        public java.lang.String getId()
        Gets an identifier that uniquely identifies and represents the Locator associated with this launcher.
        Returns:
        a String value identifier to uniquely identify the Locator and it's launcher.
        See Also:
        getBindAddressAsString(), getPortAsString()
      • isForcing

        public boolean isForcing()
        Determines whether the PID file is allowed to be overwritten when the Locator is started and a PID file already exists in the Locator's specified working directory.
        Returns:
        boolean indicating if force has been enabled.
      • isHelping

        public boolean isHelping()
        Determines whether this launcher will be used to display help information. If so, then none of the standard Locator launcher commands will be used to affect the state of the Locator. A launcher is said to be 'helping' if the user entered the "--help" option (switch) on the command-line.
        Returns:
        a boolean value indicating if this launcher is used for displaying help information.
        See Also:
        LocatorLauncher.Command
      • isRedirectingOutput

        public boolean isRedirectingOutput()
        Determines whether this launcher will redirect output to system logs when starting a new Locator process.
        Returns:
        a boolean value indicating if this launcher will redirect output to system logs when starting a new Locator process
      • getBindAddress

        public java.net.InetAddress getBindAddress()
        Gets the IP address of the NIC to which the Locator has bound itself listening for client requests.
        Returns:
        an InetAddress object representing the configured bind address for the Locator.
        See Also:
        InetAddress
      • getBindAddressAsString

        protected java.lang.String getBindAddressAsString()
        Gets the host, as either hostname or IP address, on which the Locator was bound and running. An attempt is made to get the canonical hostname for IP address to which the Locator was bound for accepting client requests. If the bind address is null or localhost is unknown, then a default String value of "localhost/127.0.0.1" is returned. Note, this information is purely information and should not be used to re-construct state or for other purposes.
        Returns:
        the hostname or IP address of the host running the Locator, based on the bind-address, or 'localhost/127.0.0.1' if the bind address is null and localhost is unknown.
        See Also:
        InetAddress, getBindAddress()
      • getHostnameForClients

        public java.lang.String getHostnameForClients()
        Gets the hostname that clients will use to lookup the running Locator.
        Returns:
        a String indicating the hostname used by clients to lookup the Locator.
      • getLogFileName

        public java.lang.String getLogFileName()
        Gets the name of the log file used to log information about this Locator.
        Specified by:
        getLogFileName in class AbstractLauncher<java.lang.String>
        Returns:
        a String value indicating the name of this Locator's log file.
      • getMemberName

        public java.lang.String getMemberName()
        Gets the name of this member (this Locator) in the Geode distributed system and determined by the 'name' Geode property.
        Overrides:
        getMemberName in class AbstractLauncher<java.lang.String>
        Returns:
        a String indicating the name of the member (this Locator) in the Geode distributed system.
      • getPid

        public java.lang.Integer getPid()
        Gets the user-specified process ID (PID) of the running Locator that LocatorLauncher uses to issue status and stop commands to the Locator.
        Specified by:
        getPid in class AbstractLauncher<java.lang.String>
        Returns:
        an Integer value indicating the process ID (PID) of the running Locator.
      • getPort

        public java.lang.Integer getPort()
        Gets the port number on which the Locator listens for client requests.
        Returns:
        an Integer value indicating the port number on which the Locator is listening for client requests.
      • getPortAsString

        public java.lang.String getPortAsString()
        Gets the port number represented as a String value. If the port number is null, the the default Locator port (10334) is returned;
        Returns:
        the port number as a String value.
        See Also:
        getPort()
      • getProperties

        public java.util.Properties getProperties()
        Gets the Geode Distributed System (cluster) Properties.
        Returns:
        a Properties object containing the configuration settings for the Geode Distributed System (cluster).
        See Also:
        Properties
      • getServiceName

        public java.lang.String getServiceName()
        Gets the name for a Geode Locator.
        Specified by:
        getServiceName in class AbstractLauncher<java.lang.String>
        Returns:
        a String indicating the name for a Geode Locator.
      • getWorkingDirectory

        public java.lang.String getWorkingDirectory()
        Gets the working directory pathname in which the Locator will be run.
        Overrides:
        getWorkingDirectory in class AbstractLauncher<java.lang.String>
        Returns:
        a String value indicating the pathname of the Locator's working directory.
      • help

        public void help​(LocatorLauncher.Command command)
        Displays help for the specified Locator launcher command to standard err. If the Locator launcher command is unspecified, then usage information is displayed instead.
        Parameters:
        command - the Locator launcher command in which to display help information.
        See Also:
        usage()
      • getLocatorPidFile

        protected java.io.File getLocatorPidFile()
        Gets a File reference with the path to the PID file for the Locator.
        Returns:
        a File reference to the path of the Locator's PID file.
      • waitOnLocator

        public LocatorLauncher.LocatorState waitOnLocator()
        Waits on the Locator to stop causing the calling Thread to join with the Locator's location-based services Thread.
        Returns:
        the Locator's status once it stops.
        Throws:
        java.lang.AssertionError - if the Locator has not been started and the reference is null (assertions must be enabled for the error to be thrown).
        See Also:
        failOnStart(Throwable), AbstractLauncher.Status, LocatorLauncher.LocatorState
      • waitOnStatusResponse

        public LocatorLauncher.LocatorState waitOnStatusResponse​(long timeout,
                                                                 long interval,
                                                                 java.util.concurrent.TimeUnit timeUnit)
        Waits for a Locator status request response to be returned up to the specified timeout in the given unit of time. This call will send status requests at fixed intervals in the given unit of time until the timeout expires. If the request to determine the Locator's status is successful, then the Locator is considered to be 'ONLINE'. Otherwise, the Locator is considered to be unresponsive to the status request. However, this does not necessarily imply the Locator start was unsuccessful, only that a response was not received in the given time period. Note, this method does not block or cause the Locator's location-based services (daemon Threads) to continue running in anyway if the main application Thread terminates when running the Locator in-process. If the caller wishes to start a Locator in an asynchronous manner within the application process, then a call should be made to waitOnLocator.
        Parameters:
        timeout - a long value in time unit indicating when the period of time should expire in attempting to determine the Locator's status.
        interval - a long value in time unit for how frequent the requests should be sent to the Locator.
        timeUnit - the unit of time in which the timeout and interval are measured.
        Returns:
        the state of the Locator, which will either be 'ONLINE' or "NOT RESPONDING'. If the status returned is 'NOT RESPONDING', it just means the Locator did not respond to the status request within the given time period. It should not be taken as the Locator failed to start.
        See Also:
        waitOnLocator()
      • status

        public LocatorLauncher.LocatorState status()
        Attempts to determine the state of the Locator. The Locator's status will be in only 1 of 2 possible states, either ONLINE or OFFLINE. This method behaves differently depending on which parameters were specified when the LocatorLauncher was constructed with an instance of Builder. If either the 'dir' or the 'pid' command-line option were specified, then an attempt is made to determine the Locator's status by using the dir or pid to correctly identify the Locator's MemberMXBean registered in the MBeanServer of the Locator's JVM, and invoking the 'status' operation. The same behavior occurs if the caller specified the Locator's Geode member name or ID. However, if 'dir' or 'pid' were not specified, then determining the Locator's status defaults to using the configured bind address and port. If the bind address or port was not specified when using the Builder to construct a LocatorLauncher instance, then the defaults for both bind address and port are used. In either case, an actual TCP/IP request is made to the Locator's ServerSocket to ensure it is listening for client requests. This is true even when the LocatorLauncher is used in-process by calling the API. If the conditions above hold, then the Locator is deemed to be 'ONLINE', otherwise, the Locator is considered 'OFFLINE'.
        Returns:
        the Locator's state.
        See Also:
        start(), stop(), AbstractLauncher.Status, LocatorLauncher.LocatorState
      • isStoppable

        protected boolean isStoppable()
        Determines whether the Locator can be stopped in-process, such as when a Locator is embedded in an application and the LocatorLauncher API is being used.
        Returns:
        a boolean indicating whether the Locator can be stopped in-process (the application's process with an embedded Locator).
      • stop

        public LocatorLauncher.LocatorState stop()
        Stop shuts the running Locator down. Using the API, the Locator is requested to stop by calling the Locator object's 'stop' method. Internally, this method is no different than using the LocatorLauncher class from the command-line or from within Geode shell (Gfsh). In every single case, stop sends a TCP/IP 'shutdown' request on the configured address/port to which the Locator is bound and listening. If the "shutdown" request is successful, then the Locator will be 'STOPPED'. Otherwise, the Locator is considered 'OFFLINE' since the actual state cannot be fully assessed (as in the application process in which the Locator was hosted may still be running and the Locator object may still exist even though it is no longer responding to location-based requests). The later is particularly important in cases where the system resources (such as Sockets) may not have been cleaned up yet. Therefore, by returning a status of 'OFFLINE', the value is meant to reflect this in-deterministic state.
        Returns:
        a LocatorState indicating the state of the Locator after stop has been requested.
        See Also:
        start(), status(), LocatorLauncher.LocatorState, AbstractLauncher.Status.NOT_RESPONDING, AbstractLauncher.Status.STOPPED
      • getBindAddressString

        public java.lang.String getBindAddressString()