GemFire 7.0.1

com.gemstone.gemfire.distributed
Class LocatorLauncher

java.lang.Object
  extended by com.gemstone.gemfire.distributed.AbstractLauncher<String>
      extended by com.gemstone.gemfire.distributed.LocatorLauncher
All Implemented Interfaces:
Identifiable<String>, Serializable, Runnable

public final class LocatorLauncher
extends AbstractLauncher<String>

The LocatorLauncher class is a launcher for a GemFire Locator.

Since:
7.0
See Also:
AbstractLauncher, Serialized Form

Nested Class Summary
static class LocatorLauncher.Builder
          Following the Builder design pattern, the LocatorLauncher Builder is used to configure and create a properly initialized instance of the LocatorLauncher class for running the Locator and performing other Locator operations.
static class LocatorLauncher.Command
          An enumerated type representing valid commands to the Locator launcher.
static class LocatorLauncher.LocatorState
          The LocatorState is an immutable type representing the state of the specified Locator at any given moment in time.
 
Nested classes/interfaces inherited from class com.gemstone.gemfire.distributed.AbstractLauncher
AbstractLauncher.ServiceState<T extends Comparable<T>>, AbstractLauncher.Status
 
Field Summary
static boolean DEFAULT_ENABLE_PEER_LOCATION
           
static boolean DEFAULT_ENABLE_SERVER_LOCATION
           
static String DEFAULT_LOCATOR_PID_FILE
           
static Integer DEFAULT_LOCATOR_PORT
           
 
Fields inherited from class com.gemstone.gemfire.distributed.AbstractLauncher
DEFAULT_WORKING_DIRECTORY, SIGNAL_HANLDER_REGISTRATION_SYSTEM_PROPERTY
 
Method Summary
 InetAddress getBindAddress()
          Gets the IP address of the NIC to which the Locator has bound itself listening for client requests.
 LocatorLauncher.Command getCommand()
          Get the Locator launcher command used to invoke the Locator.
 String getHostnameForClients()
          Gets the hostname that clients will use to lookup the running Locator.
 String getId()
          Gets an identifier that uniquely identifies and represents the Locator associated with this launcher.
static LocatorLauncher getInstance()
          Gets the instance of the LocatorLauncher used to launch the GemFire Locator, or null if this VM does not have an instance of LocatorLauncher indicating no GemFire Locator is running.
static LocatorLauncher.LocatorState getLocatorState()
          Gets the LocatorState for this process or null if this process was not launched using this VM's LocatorLauncher reference.
 String getLogFileName()
          Gets the name of the log file used to log information about this Locator.
 String getMemberName()
          Gets the name of this member (this Locator) in the GemFire distributed system and determined by the 'name' GemFire property.
 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.
 Integer getPort()
          Gets the port number on which the Locator listens for client requests.
 String getPortAsString()
          Gets the port number represented as a String value.
 String getServiceName()
          Gets the name for a GemFire Locator.
 String getWorkingDirectory()
          Gets the working directory pathname in which the Locator will be run.
 void help(LocatorLauncher.Command command)
          Displays help for the specified Locator launcher command to standard err.
 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.
 boolean isHelping()
          Determines whether this launcher will be used to display help information.
 boolean isRedirectingOutput()
          Determines whether this launcher will redirect output to system logs when starting a new Locator process.
static void main(String... args)
          Launches a GemFire Locator from the command-line configured with the given arguments.
 void run()
          The Runnable method used to launch the Locator with the specified command.
 LocatorLauncher.LocatorState start()
          Starts a Locator running on the specified port and bind address, as determined by getPort and getBindAddress respectively, defaulting to 10334 and 'localhost' if not specified, with both peer and server location enabled.
 LocatorLauncher.LocatorState status()
          Attempts to determine the state of the Locator.
 LocatorLauncher.LocatorState stop()
          Stop shuts the running Locator down.
 void usage()
          Displays usage information on the proper invocation of the LocatorLauncher from the command-line to standard err.
 LocatorLauncher.LocatorState waitOnLocator()
          Waits on the Locator to stop causing the calling Thread to join with the Locator's location-based services Thread.
 LocatorLauncher.LocatorState waitOnStatusResponse(long timeout, long interval, TimeUnit timeUnit)
          Waits for a Locator status request response to be returned up to the specified timeout in the given unit of time.
 
Methods inherited from class com.gemstone.gemfire.distributed.AbstractLauncher
getMember, getMemberId, isDebugging, isRunning, setDebug, version
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCATOR_PORT

public static final Integer DEFAULT_LOCATOR_PORT

DEFAULT_ENABLE_PEER_LOCATION

public static final boolean DEFAULT_ENABLE_PEER_LOCATION
See Also:
Constant Field Values

DEFAULT_ENABLE_SERVER_LOCATION

public static final boolean DEFAULT_ENABLE_SERVER_LOCATION
See Also:
Constant Field Values

DEFAULT_LOCATOR_PID_FILE

public static final String DEFAULT_LOCATOR_PID_FILE
See Also:
Constant Field Values
Method Detail

main

public static void main(String... args)
Launches a GemFire Locator from the command-line configured with the given arguments.

Parameters:
args - the command-line arguments used to configure the GemFire Locator at runtime.

getInstance

public static LocatorLauncher getInstance()
Gets the instance of the LocatorLauncher used to launch the GemFire Locator, or null if this VM does not have an instance of LocatorLauncher indicating no GemFire Locator is running.

Returns:
the instance of LocatorLauncher used to launcher a GemFire 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.

getId

public final 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()

getCommand

public LocatorLauncher.Command getCommand()
Get the Locator launcher command used to invoke the Locator.

Returns:
the Locator launcher command used to invoke the Locator.
See Also:
LocatorLauncher.Command

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

getHostnameForClients

public 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 String getLogFileName()
Gets the name of the log file used to log information about this Locator.

Specified by:
getLogFileName in class AbstractLauncher<String>
Returns:
a String value indicating the name of this Locator's log file.

getMemberName

public String getMemberName()
Gets the name of this member (this Locator) in the GemFire distributed system and determined by the 'name' GemFire property.

Specified by:
getMemberName in class AbstractLauncher<String>
Returns:
a String indicating the name of the member (this Locator) in the GemFire distributed system.

getPid

public 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<String>
Returns:
an Integer value indicating the process ID (PID) of the running Locator.

getPort

public 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 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()

getServiceName

public String getServiceName()
Gets the name for a GemFire Locator.

Specified by:
getServiceName in class AbstractLauncher<String>
Returns:
a String indicating the name for a GemFire Locator.

getWorkingDirectory

public String getWorkingDirectory()
Gets the working directory pathname in which the Locator will be run.

Overrides:
getWorkingDirectory in class AbstractLauncher<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()

usage

public void usage()
Displays usage information on the proper invocation of the LocatorLauncher from the command-line to standard err.

See Also:
help(com.gemstone.gemfire.distributed.LocatorLauncher.Command)

run

public void run()
The Runnable method used to launch the Locator with the specified command. If 'start' has been issued, then run will block as expected for the Locator to stop. The 'start' command is implemented with a call to start() followed by a call to waitOnLocator().

See Also:
Runnable, LocatorLauncher.Command, start(), waitOnLocator(), status(), stop(), AbstractLauncher.version(), help(com.gemstone.gemfire.distributed.LocatorLauncher.Command), usage()

start

public LocatorLauncher.LocatorState start()
Starts a Locator running on the specified port and bind address, as determined by getPort and getBindAddress respectively, defaulting to 10334 and 'localhost' if not specified, with both peer and server location enabled.

'start' is an asynchronous invocation of the Locator. As such, this method makes no guarantees whether the Locator's location services (peer and server) are actually running before it returns. The Locator's location-based services are initiated in separate, daemon Threads and depends on the relative timing and scheduling of those Threads by the JVM. If the application using this API wishes for the Locator to continue running after normal application processing completes, then one must call waitOnLocator.

Given the nature of start, the Locator's status will be in either 1 of 2 possible states. If the 'request' to start the Locator proceeds without exception, the status will be 'STARTED'. However, if any exception is encountered during the normal startup sequence, then a RuntimeException is thrown and the status is set to 'STOPPED'.

Returns:
a LocatorState to reflect the state of the Locator after start.
Throws:
RuntimeException - if the Locator failed to start for any reason.
IllegalStateException - if the Locator is already running.
See Also:
failOnStart(Throwable), getBindAddress(), AbstractLauncher.getDistributedSystemProperties(), isForcing(), AbstractLauncher.getLogFile(), getLocatorPidFile(), getPort(), status(), stop(), waitOnLocator(), waitOnStatusResponse(long, long, java.util.concurrent.TimeUnit), LocatorLauncher.LocatorState, AbstractLauncher.Status.NOT_RESPONDING, AbstractLauncher.Status.ONLINE, AbstractLauncher.Status.STARTING

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:
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,
                                                         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 GemFire 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

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 GemFire 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

GemFire 7.0.1

Copyright © 1997-2013 VMware, Inc. All rights reserved.