javax.annotation.PreDestroy Java Examples

The following examples show how to use javax.annotation.PreDestroy. 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: EurekaStore.java    From qconfig with MIT License 6 votes vote down vote up
/**
 * Handles Eureka cleanup, including shutting down all monitors and yielding all EIPs.
 *
 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
 */
@PreDestroy
public void destroy() {
    try {
        logger.info("{} Shutting down Eureka Server..", new Date().toString());
        ServletContext sc = context.getServletContext();
        sc.removeAttribute(EurekaServerContext.class.getName());

        DiscoveryManager.getInstance().shutdownComponent();
        destroyEurekaServerContext();
        destroyEurekaEnvironment();

    } catch (Throwable e) {
        logger.error("Error shutting down eureka", e);
    }
    logger.info("{} Eureka Service is now shutdown...", new Date().toString());
}
 
Example #2
Source File: DatasourceFactory.java    From micronaut-sql with Apache License 2.0 6 votes vote down vote up
@Override
@PreDestroy
public void close() {
    for (PoolDataSource dataSource : dataSources) {
        try {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Closing connection pool named: {}", dataSource.getConnectionPoolName());
            }
            UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager().destroyConnectionPool(dataSource.getConnectionPoolName());
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Error closing data source [" + dataSource + "]: " + e.getMessage(), e);
            }
        }
    }
}
 
Example #3
Source File: LifecycleRegistryTest.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@Test
public void test_is_predestroy_is_executed() throws Exception {
    final LifecycleRegistry registry = new LifecycleRegistry();

    final CountDownLatch latch = new CountDownLatch(1);
    class PredestroyClass {
        @PreDestroy
        public void preDestroy() {
            latch.countDown();
        }
    }

    registry.addPreDestroyMethod(PredestroyClass.class.getMethod("preDestroy"), new PredestroyClass());
    registry.executePreDestroy();

    assertEquals(true, latch.await(1, TimeUnit.SECONDS));
}
 
Example #4
Source File: SqlTaskManager.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
@PreDestroy
public void close()
{
    boolean taskCanceled = false;
    for (SqlTask task : tasks.asMap().values()) {
        if (task.getTaskStatus().getState().isDone()) {
            continue;
        }
        task.failed(new PrestoException(SERVER_SHUTTING_DOWN, format("Server is shutting down. Task %s has been canceled", task.getTaskId())));
        taskCanceled = true;
    }
    if (taskCanceled) {
        try {
            TimeUnit.SECONDS.sleep(5);
        }
        catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    taskNotificationExecutor.shutdownNow();
}
 
Example #5
Source File: ExecutorScheduler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void stop() {
   try {
      timer.shutdownNow();
      timer.awaitTermination(30, TimeUnit.SECONDS);
   }
   catch(Exception e) {
      logger.warn("Failed clean shutdown", e);
   }
}
 
Example #6
Source File: DatasourceFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
@Override
@PreDestroy
public void close() {
    for (org.apache.tomcat.jdbc.pool.DataSource dataSource : dataSources) {
        try {
            dataSource.close();
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Error closing data source [" + dataSource + "]: " + e.getMessage(), e);
            }
        }
    }
}
 
Example #7
Source File: NettyServerManager.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
@PreDestroy
public void stop() {
    offline();
    nettyServerForUi.stop();
    nettyServerForAgent.stop();
    zkClient.close();
}
 
Example #8
Source File: DockerFiles.java    From presto with Apache License 2.0 5 votes vote down vote up
@PreDestroy
@Override
public synchronized void close()
        throws IOException
{
    if (closed) {
        return;
    }
    if (dockerFilesHostPath != null) {
        deleteRecursively(dockerFilesHostPath, ALLOW_INSECURE);
        dockerFilesHostPath = null;
    }
    closed = true;
}
 
Example #9
Source File: DtsRemotingServer.java    From dts with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void stop() {
    if (this.channelKeeping != null) {
        this.channelKeeping.stop();
    }
    if (this.remotingServer != null) {
        this.remotingServer.shutdown();
    }
}
 
Example #10
Source File: RedisJedisManager.java    From presto with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void tearDown()
{
    for (Map.Entry<HostAddress, JedisPool> entry : jedisPoolCache.asMap().entrySet()) {
        try {
            entry.getValue().destroy();
        }
        catch (Exception e) {
            log.warn(e, "While destroying JedisPool %s:", entry.getKey());
        }
    }
}
 
Example #11
Source File: ZigbeeController.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
/**
 * Disconnect the controller from the agent router.
 */
@PreDestroy
public void stop() {
    if (port != null) {
        router.disconnect(port);
        port = null;
    }
}
 
Example #12
Source File: CommonAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testPostConstructAndPreDestroyWithManualConfiguration() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
	bpp.setInitAnnotationType(PostConstruct.class);
	bpp.setDestroyAnnotationType(PreDestroy.class);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));

	AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
	assertTrue(bean.initCalled);
	bf.destroySingletons();
	assertTrue(bean.destroyCalled);
}
 
Example #13
Source File: CommandService.java    From mcspring-boot with MIT License 5 votes vote down vote up
@PreDestroy
void destroy() {
    try {
        List<CommandSpec> commandSpecs = getCommands();
        commandSpecs.forEach(this::unregisterCommand);
    } catch (Throwable t) {
        log.debug("Failed to unregister commands natively", t);
    }
}
 
Example #14
Source File: CommonAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@PreDestroy
private void destroy() {
	if (this.destroyCalled) {
		throw new IllegalStateException("Already called");
	}
	this.destroyCalled = true;
}
 
Example #15
Source File: HttpHealthCheckServer.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
/**
 * Signals the server to shut down and blocks until shutdown is complete.
 *
 * @throws Exception
 */
@PreDestroy
public void shutdown() throws Exception {
   Channel channel = this.channel;
   if (channel != null) {
      ChannelFuture closeFuture = channel.close();
      closeFuture.sync();
      this.channel = null;
   }
}
 
Example #16
Source File: ServiceInvocationEventProcessor.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void preDestroy() {
    log.info("try to destroy {} ", ServiceInvocationEventProcessor.class.getSimpleName());
    if (masterExecutor != null) {
        masterExecutor.shutdown();
    }

    if (slaveExecutor != null) {
        slaveExecutor.shutdown();
    }
}
 
Example #17
Source File: HttpSmartyStreetsModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void destroy() throws IOException
{
   logger.debug("Closing the HttpClient, HttpClientConnectionManager, and all open connections");

   httpClient.close();
}
 
Example #18
Source File: PushyApnsSender.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void shutdown() {
    try {
        logger.info("Shutting down APNS provider.");
        apnsClient.close().await();
    } catch (InterruptedException e) {
        logger.warn("APNS provider failed to shut down gracefully.", e);
    }
}
 
Example #19
Source File: HttpRemoteTaskFactory.java    From presto with Apache License 2.0 5 votes vote down vote up
@PreDestroy
public void stop()
{
    coreExecutor.shutdownNow();
    updateScheduledExecutor.shutdownNow();
    errorScheduledExecutor.shutdownNow();
}
 
Example #20
Source File: CommonAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testPostConstructAndPreDestroyWithManualConfiguration() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	InitDestroyAnnotationBeanPostProcessor bpp = new InitDestroyAnnotationBeanPostProcessor();
	bpp.setInitAnnotationType(PostConstruct.class);
	bpp.setDestroyAnnotationType(PreDestroy.class);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));

	AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
	assertTrue(bean.initCalled);
	bf.destroySingletons();
	assertTrue(bean.destroyCalled);
}
 
Example #21
Source File: JasyncPostgreSQLClientFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
@Override
@PreDestroy
public void close() {
    if (this.connection != null && this.connection.isConnected()) {
        this.connection.disconnect();
    }
}
 
Example #22
Source File: QueueServiceImpl.java    From pmq with Apache License 2.0 5 votes vote down vote up
@PreDestroy
private void close() {
	try {
		executor.shutdown();
		isRunning = false;
	} catch (Exception e) {
	}
}
 
Example #23
Source File: JavaConcurrentLockFactory.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@PreDestroy
public void destroy(){
    if(null!=scheduledExecutor&&!scheduledExecutor.isTerminated()){
        scheduledExecutor.shutdown();
    }
}
 
Example #24
Source File: MessageCleanService.java    From pmq with Apache License 2.0 4 votes vote down vote up
@PreDestroy
public void stopPortal() {
	super.stopPortal();
}
 
Example #25
Source File: SingletonResolver.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void dispose() {
    invokeMethod(findAnnotatedMethod(singleton.getClass(),PreDestroy.class),singleton);
}
 
Example #26
Source File: OrcStorageManager.java    From presto with Apache License 2.0 4 votes vote down vote up
@PreDestroy
public void shutdown()
{
    deletionExecutor.shutdownNow();
    commitExecutor.shutdown();
}
 
Example #27
Source File: NotifyMessageCleanService.java    From pmq with Apache License 2.0 4 votes vote down vote up
@PreDestroy
public void stopPortal() {
	super.stopPortal();
}
 
Example #28
Source File: AutoProxyLazyInitTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@PreDestroy
public void destroy() {
}
 
Example #29
Source File: KinesisTableDescriptionSupplier.java    From presto with Apache License 2.0 4 votes vote down vote up
/**
 * Shutdown any periodic update jobs.
 */
@PreDestroy
public void shutdown()
{
    this.s3TableConfigClient.run();
}
 
Example #30
Source File: Spr3775InitDestroyLifecycleTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@PreDestroy
public void destroy() throws Exception {
	this.destroyMethods.add("destroy");
}