use of org.apache.geode.cache.execute.internal.FunctionServiceManager in project geode by apache.
the class InternalDistributedSystem method disconnect.
/**
* Disconnects this VM from the distributed system. Shuts down the distribution manager.
*
* @param preparingForReconnect true if called by a reconnect operation
* @param reason the reason the disconnect is being performed
* @param keepAlive true if user requested durable subscriptions are to be retained at server.
*/
protected void disconnect(boolean preparingForReconnect, String reason, boolean keepAlive) {
boolean isShutdownHook = (shutdownHook != null) && (Thread.currentThread() == shutdownHook);
if (!preparingForReconnect) {
// logger.info("disconnecting IDS@"+System.identityHashCode(this));
synchronized (reconnectListeners) {
reconnectListeners.clear();
}
cancelReconnect();
}
final boolean isDebugEnabled = logger.isDebugEnabled();
try {
HashSet shutdownListeners = null;
try {
if (isDebugEnabled) {
logger.debug("DistributedSystem.disconnect invoked on {}", this);
}
synchronized (GemFireCacheImpl.class) {
// bug 36955, 37014: don't use a disconnect listener on the cache;
// it takes too long.
//
// However, make sure cache is completely closed before starting
// the distributed system close.
InternalCache currentCache = GemFireCacheImpl.getInstance();
if (currentCache != null && !currentCache.isClosed()) {
// bug #42663 - this must be set while
disconnectListenerThread.set(Boolean.TRUE);
// closing the cache
try {
// fix for 42150
currentCache.close(reason, dm.getRootCause(), keepAlive, true);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable e) {
SystemFailure.checkFailure();
// Whenever you catch Error or Throwable, you must also
// check for fatal JVM error (see above). However, there is
logger.warn(LocalizedMessage.create(LocalizedStrings.InternalDistributedSystem_EXCEPTION_TRYING_TO_CLOSE_CACHE), e);
} finally {
disconnectListenerThread.set(Boolean.FALSE);
}
}
// marked as shutting down
synchronized (this) {
if (this.isDisconnecting) {
// It's already started, but don't return
// to the caller until it has completed.
waitDisconnected();
return;
}
// isDisconnecting
this.isDisconnecting = true;
if (!preparingForReconnect) {
// move cancelReconnect above this synchronized block fix for bug 35202
if (this.reconnectDS != null) {
// break recursion
if (isDebugEnabled) {
logger.debug("disconnecting reconnected DS: {}", this.reconnectDS);
}
InternalDistributedSystem r = this.reconnectDS;
this.reconnectDS = null;
r.disconnect(false, null, false);
}
}
// !reconnect
}
// synchronized (this)
}
if (!isShutdownHook) {
shutdownListeners = doDisconnects(attemptingToReconnect, reason);
}
if (!this.attemptingToReconnect) {
if (this.logWriterAppender != null) {
LogWriterAppenders.stop(LogWriterAppenders.Identifier.MAIN);
}
if (this.securityLogWriterAppender != null) {
// LOG:SECURITY: old code did NOT invoke this
LogWriterAppenders.stop(LogWriterAppenders.Identifier.SECURITY);
}
}
AlertAppender.getInstance().shuttingDown();
} finally {
// be ABSOLUTELY CERTAIN that dm closed
try {
// Do the bulk of the close...
this.dm.close();
// is enabled, loss of the locator doesn't cause the DM to croak
if (this.startedLocator != null) {
this.startedLocator.stop(forcedDisconnect, preparingForReconnect, false);
this.startedLocator = null;
}
} finally {
// the DM is closed :-(
if (!preparingForReconnect) {
SystemTimer.cancelSwarm(this);
}
}
// finally timer cancelled
}
if (!isShutdownHook) {
doShutdownListeners(shutdownListeners);
}
// closing the Aggregate stats
if (functionServiceStats != null) {
functionServiceStats.close();
}
// closing individual function stats
for (FunctionStats functionstats : functionExecutionStatsMap.values()) {
functionstats.close();
}
(new FunctionServiceManager()).unregisterAllFunctions();
if (this.sampler != null) {
this.sampler.stop();
this.sampler = null;
}
if (!this.attemptingToReconnect) {
if (this.logWriterAppender != null) {
LogWriterAppenders.destroy(LogWriterAppenders.Identifier.MAIN);
}
if (this.securityLogWriterAppender != null) {
LogWriterAppenders.destroy(LogWriterAppenders.Identifier.SECURITY);
}
}
// NOTE: no logging after this point :-)
// bug35388 - logwriters accumulate, causing mem
LoggingThreadGroup.cleanUpThreadGroups();
// leak
EventID.unsetDS();
} finally {
try {
if (getOffHeapStore() != null) {
getOffHeapStore().close();
}
} finally {
try {
removeSystem(this);
// Close the config object
this.config.close();
} finally {
// Finally, mark ourselves as disconnected
setDisconnected();
SystemFailure.stopThreads();
}
}
}
}
Aggregations