use of org.apache.geode.internal.process.FileAlreadyExistsException in project geode by apache.
the class ServerLauncher method start.
/**
* Invokes the 'start' command and operation to startup a GemFire server (a cache server). Note,
* this method will cause the JVM to block upon server start, providing the calling Thread is a
* non-daemon Thread.
*
* @see #run()
*/
public ServerState start() {
if (isStartable()) {
INSTANCE.compareAndSet(null, this);
try {
process = new ControllableProcess(this.controlHandler, new File(getWorkingDirectory()), ProcessType.SERVER, isForcing());
if (!isDisableDefaultServer()) {
assertPortAvailable(getServerBindAddress(), getServerPort());
}
SystemFailure.setExitOK(true);
ProcessLauncherContext.set(isRedirectingOutput(), getOverriddenDefaults(), new StartupStatusListener() {
@Override
public void setStatus(final String statusMessage) {
debug("Callback setStatus(String) called with message (%1$s)...", statusMessage);
ServerLauncher.this.statusMessage = statusMessage;
}
});
try {
final Properties gemfireProperties = getDistributedSystemProperties(getProperties());
this.cache = createCache(gemfireProperties);
// Set the resource manager options
if (this.criticalHeapPercentage != null) {
this.cache.getResourceManager().setCriticalHeapPercentage(getCriticalHeapPercentage());
}
if (this.evictionHeapPercentage != null) {
this.cache.getResourceManager().setEvictionHeapPercentage(getEvictionHeapPercentage());
}
if (this.criticalOffHeapPercentage != null) {
this.cache.getResourceManager().setCriticalOffHeapPercentage(getCriticalOffHeapPercentage());
}
if (this.evictionOffHeapPercentage != null) {
this.cache.getResourceManager().setEvictionOffHeapPercentage(getEvictionOffHeapPercentage());
}
this.cache.setIsServer(true);
startCacheServer(this.cache);
assignBuckets(this.cache);
rebalance(this.cache);
} finally {
ProcessLauncherContext.remove();
}
debug("Running Server on (%1$s) in (%2$s) as (%2$s)...", getId(), getWorkingDirectory(), getMember());
this.running.set(true);
return new ServerState(this, Status.ONLINE);
} catch (AuthenticationRequiredException e) {
failOnStart(e);
throw new AuthenticationRequiredException("user/password required. Please start your server with --user and --password. " + e.getMessage());
} catch (GemFireSecurityException e) {
failOnStart(e);
throw new GemFireSecurityException(e.getMessage());
} catch (IOException e) {
failOnStart(e);
throw new RuntimeException(LocalizedStrings.Launcher_Command_START_IO_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId(), e.getMessage()), e);
} catch (FileAlreadyExistsException e) {
failOnStart(e);
throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_FILE_ALREADY_EXISTS_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()), e);
} catch (PidUnavailableException e) {
failOnStart(e);
throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_UNAVAILABLE_ERROR_MESSAGE.toLocalizedString(getServiceName(), getId(), getWorkingDirectory(), e.getMessage()), e);
} catch (ClusterConfigurationNotAvailableException e) {
failOnStart(e);
throw e;
} catch (RuntimeException e) {
failOnStart(e);
throw e;
} catch (Exception e) {
failOnStart(e);
throw new RuntimeException(e);
} catch (Error e) {
failOnStart(e);
throw e;
} finally {
this.starting.set(false);
}
} else {
throw new IllegalStateException(LocalizedStrings.Launcher_Command_START_SERVICE_ALREADY_RUNNING_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()));
}
}
use of org.apache.geode.internal.process.FileAlreadyExistsException in project geode by apache.
the class LocatorLauncher method 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 <code>waitOnLocator</code>.
*
* 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'.
*
* @return a LocatorState to reflect the state of the Locator after start.
* @throws RuntimeException if the Locator failed to start for any reason.
* @throws IllegalStateException if the Locator is already running.
* @see #failOnStart(Throwable)
* @see #getBindAddress()
* @see #getDistributedSystemProperties()
* @see #isForcing()
* @see #getLogFile()
* @see #getLocatorPidFile
* @see #getPort()
* @see #status()
* @see #stop()
* @see #waitOnLocator()
* @see #waitOnStatusResponse(long, long, java.util.concurrent.TimeUnit)
* @see org.apache.geode.distributed.LocatorLauncher.LocatorState
* @see org.apache.geode.distributed.AbstractLauncher.Status#NOT_RESPONDING
* @see org.apache.geode.distributed.AbstractLauncher.Status#ONLINE
* @see org.apache.geode.distributed.AbstractLauncher.Status#STARTING
*/
@SuppressWarnings("deprecation")
public LocatorState start() {
if (isStartable()) {
INSTANCE.compareAndSet(null, this);
try {
this.process = new ControllableProcess(this.controlHandler, new File(getWorkingDirectory()), ProcessType.LOCATOR, isForcing());
assertPortAvailable(getBindAddress(), getPort());
ProcessLauncherContext.set(isRedirectingOutput(), getOverriddenDefaults(), new StartupStatusListener() {
@Override
public void setStatus(final String statusMessage) {
LocatorLauncher.this.statusMessage = statusMessage;
}
});
// TODO : remove the extra param for loadFromSharedConfigDir
try {
this.locator = InternalLocator.startLocator(getPort(), getLogFile(), null, null, null, getBindAddress(), true, getDistributedSystemProperties(), getHostnameForClients());
} finally {
ProcessLauncherContext.remove();
}
debug("Running Locator on (%1$s) in (%2$s) as (%2$s)...", getId(), getWorkingDirectory(), getMember());
running.set(true);
return new LocatorState(this, Status.ONLINE);
} catch (IOException e) {
failOnStart(e);
throw new RuntimeException(LocalizedStrings.Launcher_Command_START_IO_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId(), e.getMessage()), e);
} catch (FileAlreadyExistsException e) {
failOnStart(e);
throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_FILE_ALREADY_EXISTS_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()), e);
} catch (PidUnavailableException e) {
failOnStart(e);
throw new RuntimeException(LocalizedStrings.Launcher_Command_START_PID_UNAVAILABLE_ERROR_MESSAGE.toLocalizedString(getServiceName(), getId(), getWorkingDirectory(), e.getMessage()), e);
} catch (Error e) {
failOnStart(e);
throw e;
} catch (RuntimeException e) {
failOnStart(e);
throw e;
} catch (Exception e) {
failOnStart(e);
throw new RuntimeException(e);
} finally {
this.starting.set(false);
}
} else {
throw new IllegalStateException(LocalizedStrings.Launcher_Command_START_SERVICE_ALREADY_RUNNING_ERROR_MESSAGE.toLocalizedString(getServiceName(), getWorkingDirectory(), getId()));
}
}
Aggregations