Java Code Examples for org.jboss.msc.service.StopContext#asynchronous()

The following examples show how to use org.jboss.msc.service.StopContext#asynchronous() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HostControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public synchronized void stop(final StopContext context) {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                scheduledExecutorService.shutdown();
            } finally {
                scheduledExecutorService = null;
                context.complete();
            }
        }
    };
    try {
        executorInjector.getValue().execute(r);
    } catch (RejectedExecutionException e) {
        r.run();
    } finally {
        context.asynchronous();
    }
}
 
Example 2
Source File: RemoteDomainConnectionService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public synchronized void stop(final StopContext context) {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                StreamUtils.safeClose(connection);
                responseAttachmentSupport.shutdown();
            } finally {
                context.complete();
            }
        }
    };
    try {
        executor.execute(r);
    } catch (RejectedExecutionException e) {
        r.run();
    } finally {
        context.asynchronous();
    }
}
 
Example 3
Source File: DiscoveryService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public synchronized void stop(final StopContext context) {
    final Runnable task = new Runnable() {
        @Override
        public void run() {
            try {
                if (isMasterDomainController && (discoveryOptions != null)) {
                    for (DiscoveryOption discoveryOption : discoveryOptions) {
                        discoveryOption.cleanUp();
                    }
                }
            } finally {
                context.complete();
            }
        }
    };
    try {
        executorService.getValue().execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
 
Example 4
Source File: LdapCacheService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void stop(final StopContext context) {
    try {
        context.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    ldapSearchCacheConsumer.accept(null);
                    cacheImplementation.clearAll();
                    cacheImplementation = null;
                    if (executorService != null) {
                        // FIXME context.execute() should not be used for blocking tasks. Inject a scheduled executor
                        // and get rid of this
                        executorService.shutdown();
                        executorService = null;
                    }
                } finally {
                    context.complete();
                }
            }
        });
    } finally {
        context.asynchronous();
    }
}
 
Example 5
Source File: HostControllerConnectionService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public synchronized void stop(final StopContext stopContext) {
    final ExecutorService executorService = executorSupplier.get();
    final Runnable task = new Runnable() {
        @Override
        public void run() {
            try {
                responseAttachmentSupport.shutdown();
            } finally {
                StreamUtils.safeClose(client);
                client = null;
                stopContext.complete();
            }
        }
    };
    try {
        executorService.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        stopContext.asynchronous();
    }
}
 
Example 6
Source File: DeploymentMountProvider.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void stop(final StopContext context) {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                deploymentMountProviderConsumer.accept(null);
                VFSUtils.safeClose(tempFileProvider);
            } finally {
                try {
                    ScheduledExecutorService ses = scheduledExecutorService;
                    scheduledExecutorService = null;
                    if (ses != null) {
                        ses.shutdown();
                    }
                    ServerLogger.ROOT_LOGGER.debugf("%s stopped", DeploymentMountProvider.class.getSimpleName());
                } finally {
                    context.complete();
                }
            }
        }
    };
    final ExecutorService executorService = executorSupplier.get();
    try {
        try {
            executorService.execute(r);
        } catch (RejectedExecutionException e) {
            r.run();
        }
    } finally {
        context.asynchronous();
    }
}
 
Example 7
Source File: QueuelessThreadPoolService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void stop(final StopContext context) {
    final ManagedQueuelessExecutorService executor;
    synchronized (this) {
        executor = this.executor;
        this.executor = null;
    }
    context.asynchronous();
    executor.internalShutdown();
    executor.addShutdownListener(StopContextEventListener.getInstance(), context);
}
 
Example 8
Source File: ProcessApplicationDeploymentService.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void stop(final StopContext context) {
  context.asynchronous();
  executorInjector.getValue().submit(new Runnable() {
    public void run() {
      try {
        performUndeployment();
      } finally {
        context.complete();
      }
    }
  });
}
 
Example 9
Source File: BoundedQueueThreadPoolService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void stop(final StopContext context) {
    final ManagedQueueExecutorService executor;
    synchronized (this) {
        executor = this.executor;
        this.executor = null;
    }
    context.asynchronous();
    executor.internalShutdown();
    executor.addShutdownListener(StopContextEventListener.getInstance(), context);
}
 
Example 10
Source File: ScheduledThreadPoolService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void stop(final StopContext context) {
    final ManagedScheduledExecutorService executor;
    synchronized (this) {
        executor = this.executor;
        this.context = context;
        this.executor = null;
    }
    context.asynchronous();
    executor.internalShutdown();
}
 
Example 11
Source File: EnhancedQueueExecutorService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void stop(final StopContext context) {
    final ManagedEnhancedQueueExecutor executor;
    synchronized (this) {
        executor = this.executor;
        this.executor = null;
    }
    context.asynchronous();
    executor.internalShutdown();
    executor.addShutdownListener(StopContextEventListener.getInstance(), context);
}
 
Example 12
Source File: ProcessApplicationDeploymentService.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void stop(final StopContext context) {
  context.asynchronous();
  executorInjector.getValue().submit(new Runnable() {
    public void run() {
      try {
        performUndeployment();
      } finally {
        context.complete();
      }
    }
  });
}
 
Example 13
Source File: ServerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public synchronized void stop(final StopContext context) {

    if (executorService != null) {
        context.asynchronous();
        Thread executorShutdown = new Thread(new Runnable() {
            @Override
            public void run() {
                boolean interrupted = false;
                try {
                    executorService.shutdown();
                    // Hack. Give in progress tasks a brief period to complete before we
                    // interrupt threads via shutdownNow
                    executorService.awaitTermination(100, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    interrupted = true;
                } finally {
                    try {
                        List<Runnable> tasks = executorService.shutdownNow();
                        executorService = null;
                        if (!interrupted) {
                            for (Runnable task : tasks) {
                                ServerLogger.AS_ROOT_LOGGER.debugf("%s -- Discarding unexecuted task %s", getClass().getSimpleName(), task);
                            }
                        }
                    } finally {
                        context.complete();
                    }
                }
            }
        }, "ServerExecutorService Shutdown Thread");
        executorShutdown.start();
    }
}
 
Example 14
Source File: ManagementWorkerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void stop(StopContext context) {
    this.stopContext = context;
    context.asynchronous();
    worker.shutdown();
    worker = null;
}
 
Example 15
Source File: AbstractModelControllerOperationHandlerFactoryService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public synchronized void stop(final StopContext stopContext) {
    serviceConsumer.accept(null);
    final ExecutorService executorService = executorSupplier.get();
    final Runnable task = new Runnable() {
        @Override
        public void run() {
            try {
                responseAttachmentSupport.shutdown();
                // Shut down new requests to the client request executor,
                // but don't mess with currently running tasks
                clientRequestExecutor.shutdown();
            } finally {
                stopContext.complete();
            }
        }
    };
    try {
        executorService.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        stopContext.asynchronous();
    }

}
 
Example 16
Source File: AbstractControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void stop(final StopContext context) {
    capabilityRegistry.clear();
    capabilityRegistry.publish();
    ServiceNameFactory.clearCache();
    controller = null;
    stabilityMonitor = null;
    processState.setStopping();
    Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                stopAsynchronous(context);
            } finally {
                try {
                    authorizer.shutdown();
                } finally {
                    context.complete();
                }
            }
        }
    };
    final ExecutorService executorService = this.executorService != null ? this.executorService.get() : null;
    try {
        if (executorService != null) {
            try {
                executorService.execute(r);
            } catch (RejectedExecutionException e) {
                r.run();
            }
        } else {
            Thread executorShutdown = new Thread(r, getClass().getSimpleName() + " Shutdown Thread");
            executorShutdown.start();
        }
    } finally {
        processState.setStopped();
        context.asynchronous();
    }
}
 
Example 17
Source File: EndpointService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** {@inheritDoc} */
public void stop(final StopContext context) {
    context.asynchronous();
    endpointConsumer.accept(null);
    final Endpoint endpoint = this.endpoint;
    this.endpoint = null;
    try {
        endpoint.closeAsync();
    } finally {
        endpoint.addCloseHandler((closed, exception) -> {
            context.complete();
        });
    }
}
 
Example 18
Source File: ServerInventoryService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Stops all servers.
 *
 * {@inheritDoc}
 */
@Override
public synchronized void stop(final StopContext context) {
    final boolean shutdownServers = runningModeControl.getRestartMode() == RestartMode.SERVERS;
    if (shutdownServers) {
        Runnable task = new Runnable() {
            @Override
            public void run() {
                try {
                    serverInventory.shutdown(true, -1, true); // TODO graceful shutdown
                    serverInventory = null;
                    // client.getValue().setServerInventory(null);
                } finally {
                    serverCallback.getValue().setCallbackHandler(null);
                    context.complete();
                }
            }
        };
        try {
            executorService.getValue().execute(task);
        } catch (RejectedExecutionException e) {
            task.run();
        } finally {
            context.asynchronous();
        }
    } else {
        // We have to set the shutdown flag in any case
        serverInventory.shutdown(false, -1, true);
        serverInventory = null;
    }
}
 
Example 19
Source File: HostControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public synchronized void stop(final StopContext context) {
    Thread executorShutdown = new Thread(new Runnable() {
        @Override
        public void run() {
            boolean interrupted = false;
            try {
                executorService.shutdown();
                executorService.awaitTermination(100, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                interrupted = true;
            } finally {
                try {
                    List<Runnable> tasks = executorService.shutdownNow();
                    executorService = null;
                    if (!interrupted) {
                        for (Runnable task : tasks) {
                            HostControllerLogger.ROOT_LOGGER.debugf("%s -- Discarding unexecuted task %s", getClass().getSimpleName(), task);
                        }
                    }
                } finally {
                    context.complete();
                }
            }
        }
    }, "HostController ExecutorService Shutdown Thread");
    executorShutdown.start();
    context.asynchronous();
}
 
Example 20
Source File: LdapConnectionManagerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void stop(final StopContext context) {
    try {
        context.execute(new Runnable() {
            @Override
            public void run() {
                connectionManagerRegistry.removeLdapConnectionManagerService(name);
                ldapConnectionManagerConsumer.accept(null);
                context.complete();
            }
        });
    } finally {
        context.asynchronous();
    }
}