Java Code Examples for javax.annotation.PreDestroy

The following are top voted examples for showing how to use javax.annotation.PreDestroy. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Spring-Security-Third-Edition   File: DataSourceConfig.java   View source code 6 votes vote down vote up
/**
     * DataSource PreDestroy call-back
     * @throws SQLException
     */
    @PreDestroy()
    public void dataSourceDestroy() throws SQLException {

//        SQLException sqlException = null;
//
//        try {
//            applicationContext.getBean(DataSource.class)
//                    .getConnection()
//                    .close();
//        } catch (SQLException e){
//            sqlException = e;
//            e.printStackTrace();
//        }

        if (database != null) {
            database.shutdown();
        }

//        if(sqlException != null){
//            throw sqlException;
//        }
    }
 
Example 2
Project: OpenJSharp   File: WSEndpointImpl.java   View source code 6 votes vote down vote up
public synchronized void dispose() {
    if (disposed) {
        return;
    }
    disposed = true;

    masterTubeline.preDestroy();

    for (Handler handler : binding.getHandlerChain()) {
        for (Method method : handler.getClass().getMethods()) {
            if (method.getAnnotation(PreDestroy.class) == null) {
                continue;
            }
            try {
                method.invoke(handler);
            } catch (Exception e) {
                logger.log(Level.WARNING, HandlerMessages.HANDLER_PREDESTROY_IGNORE(e.getMessage()), e);
            }
            break;
        }
    }
    closeManagedObjectManager();
    LazyMOMProvider.INSTANCE.unregisterEndpoint(this);
}
 
Example 3
Project: spring-boot-data-source-decorator   File: P6SpyConfiguration.java   View source code 6 votes vote down vote up
@PreDestroy
public void destroy() {
    P6SpyProperties p6spy = dataSourceDecoratorProperties.getP6spy();
    if (!initialP6SpyOptions.containsKey("modulelist")) {
        System.clearProperty("p6spy.config.modulelist");
    }
    if (!initialP6SpyOptions.containsKey("logMessageFormat")) {
        if (p6spy.getLogFormat() != null) {
            System.clearProperty("p6spy.config.logMessageFormat");
            System.clearProperty("p6spy.config.customLogMessageFormat");
        }
        else if (p6spy.isMultiline()) {
            System.clearProperty("p6spy.config.logMessageFormat");
        }
    }
    if (!initialP6SpyOptions.containsKey("appender")) {
        System.clearProperty("p6spy.config.appender");
    }
    if (!initialP6SpyOptions.containsKey("logfile")) {
        System.clearProperty("p6spy.config.logfile");
    }
    P6ModuleManager.getInstance().reload();
}
 
Example 4
Project: id_center   File: ZKSnowflakeIDGenerator.java   View source code 5 votes vote down vote up
/**
 * Spring容器关闭前先停止ID生成器的工作,并关闭ZK管理器
 */
@Override
@PreDestroy
public void close() throws IOException {
    log.info("close zkManager before shutdown...");
    suspend();
    CloseableUtils.closeQuietly(zkManager);
}
 
Example 5
Project: Spring-Security-Third-Edition   File: DataSourceConfig.java   View source code 5 votes vote down vote up
/**
 * DataSource PreDestroy call-back
 * @throws SQLException
 */
@PreDestroy()
public void dataSourceDestroy() throws SQLException {

    if (database != null) {
        database.shutdown();
    }
}
 
Example 6
Project: easyhbase   File: CollectorMetric.java   View source code 5 votes vote down vote up
@PreDestroy
private void shutdown() {
    if (reporter == null) {
        return;
    }
    reporter.stop();
    reporter = null;
}
 
Example 7
Project: testee.fi   File: PostgresConnectionFactory.java   View source code 5 votes vote down vote up
@PreDestroy
public void release() {
    databases.values().forEach(dbName -> {
        try {
            dropDB(dbName);
        } catch (final RuntimeException e) {
            // Don't stop dropping DBs if one of them fails. Notify the user, though.
            LOG.error("Failed to cleanup PostgreSQL database {}", dbName, e);
        }
    });
}
 
Example 8
Project: testee.fi   File: H2PostgresConnectionFactory.java   View source code 5 votes vote down vote up
@PreDestroy
public void release() {
    dbNames.forEach(dbName -> execute(
            () -> {
                LOG.debug("Cleaning up H2 database: {}", dbName);
                connect(dbName, 0).close();
                return null;
            },
            e -> "Failed to close H2 database"
    ));
}
 
Example 9
Project: testee.fi   File: TransactionalContext.java   View source code 5 votes vote down vote up
@PreDestroy
public void shutdown() {
    LOG.debug("Shutting down transactional context");
    if (ejbContainer != null) {
        ejbContainer.shutdown();
    }
    if (realm != null) {
        realm.shutdown();
    }
}
 
Example 10
Project: Spring-Security-Third-Edition   File: DataSourceConfig.java   View source code 5 votes vote down vote up
/**
 * DataSource PreDestroy call-back
 * @throws SQLException
 */
@PreDestroy()
public void dataSourceDestroy() throws SQLException {
    if (database != null) {
        database.shutdown();
    }
}
 
Example 11
Project: springboot-shiro-cas-mybatis   File: SimpleHttpClientFactoryBean.java   View source code 5 votes vote down vote up
/**
 * Destroy.
 */
@PreDestroy
public void destroy() {
    if (this.executorService != null) {
        this.executorService.shutdownNow();
        this.executorService = null;
    }
}
 
Example 12
Project: Biliomi   File: SocketSession.java   View source code 5 votes vote down vote up
@Override
@PreDestroy
public void stop() {
  if (clientWebSocket != null && clientWebSocket.isOpen()) {
    clientWebSocket.disconnect();
  }
}
 
Example 13
Project: xm-ms-timeline   File: TimelineApp.java   View source code 5 votes vote down vote up
@PreDestroy
public void destroyApplication() {
    log.info("\n----------------------------------------------------------\n\t"
            + "Application {} is closing"
            + "\n----------------------------------------------------------",
        env.getProperty("spring.application.name"));
}
 
Example 14
Project: cas-server-4.2.1   File: CouchbaseServiceRegistryDao.java   View source code 5 votes vote down vote up
/**
 * Stops the couchbase client and cancels the initialization task if uncompleted.
 */
@PreDestroy
public void destroy() {
    try {
        couchbase.shutdown();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 15
Project: cas-5.1.0   File: MemCacheTicketRegistry.java   View source code 5 votes vote down vote up
/**
 * Destroy the client and shut down.
 */
@PreDestroy
public void destroy() {
    if (this.client == null) {
        return;
    }
    this.client.shutdown();
}
 
Example 16
Project: cas-5.1.0   File: InMemoryTestLdapDirectoryServer.java   View source code 5 votes vote down vote up
@Override
@PreDestroy
public void close() {
    LOGGER.debug("Shutting down LDAP server...");
    this.directoryServer.closeAllConnections(true);
    this.directoryServer.shutDown(true);
    LOGGER.debug("Shut down LDAP server.");
}
 
Example 17
Project: cas-server-4.2.1   File: SimpleHttpClientFactoryBean.java   View source code 5 votes vote down vote up
/**
 * Destroy.
 */
@PreDestroy
public void destroy() {
    if (this.executorService != null) {
        this.executorService.shutdownNow();
        this.executorService = null;
    }
}
 
Example 18
Project: loom   File: BaseAdapter.java   View source code 5 votes vote down vote up
@Override
@PreDestroy
public void onUnload() {
    // close down thread
    synchronized (this) {
        open = false;
        notifyAll();
    }
}
 
Example 19
Project: cas-server-4.2.1   File: PoolingLdaptiveResourceCRLFetcher.java   View source code 5 votes vote down vote up
/**
 * Close connection pull and shut down the executor.
 */
@PreDestroy
public void destroy() {
    logger.debug("Shutting down connection pools...");
    for (final PooledConnectionFactory factory : connectionPoolMap.values()) {
        factory.getConnectionPool().close();
    }
}
 
Example 20
Project: iothub   File: MqttTransportService.java   View source code 5 votes vote down vote up
@PreDestroy
public void shutdown() throws InterruptedException {
  log.info("Stopping MQTT transport!");
  try {
    serverChannel.close().sync();
  } finally {
    bossGroup.shutdownGracefully();
    workerGroup.shutdownGracefully();
  }
  log.info("MQTT transport stopped!");
}
 
Example 21
Project: buenojo   File: CacheConfiguration.java   View source code 5 votes vote down vote up
@PreDestroy
public void destroy() {
    log.info("Remove Cache Manager metrics");
    SortedSet<String> names = metricRegistry.getNames();
    names.forEach(metricRegistry::remove);
    log.info("Closing Cache Manager");
    cacheManager.shutdown();
}
 
Example 22
Project: Your-Microservice   File: YourMicroserviceToken_nimbus_Impl.java   View source code 5 votes vote down vote up
/**
 * Pre-Destroy TearDown of Container.
 * Here we Destroy our SecretKey and JWS Signer.
 */
@PreDestroy
public void shutdown() {
    /**
     * Shutdown Component
     */
    LOGGER.info("{}YourMicroserviceToken Component Shutdown commencing...",
            LOGGING_HEADER);
    secretKey = null;
    jwsSigner = null;
    LOGGER.info("{}YourMicroserviceToken Component Shutdown Completed, ready for Bean Removal.",
            LOGGING_HEADER);
}
 
Example 23
Project: kubernetes-client   File: PortForwarder.java   View source code 5 votes vote down vote up
@PreDestroy
public void done() {

    Thread t = connectionHandler;
    if (t != null)
        t.interrupt();
}
 
Example 24
Project: beadledom   File: LifecycleProvisionListener.java   View source code 5 votes vote down vote up
private <T> List<InvokableLifecycleMethod> findPreDestroyMethods(T injectee, Class<?> type) {
  List<InvokableLifecycleMethod> preDestroyMethods = new ArrayList<InvokableLifecycleMethod>();
  for (Method method : getAllMethods(type)) {
    if (method.isAnnotationPresent(PreDestroy.class)) {
      preDestroyMethods.add(new InvokableLifecycleMethodImpl(injectee, method, PreDestroy.class));
    }
  }

  return preDestroyMethods;
}
 
Example 25
Project: simple-hostel-management   File: SystemTrayComponent.java   View source code 5 votes vote down vote up
/**
 * This method will be called when Spring app is destroyed
 */
@PreDestroy
public void removeSystemTray() {
    if (trayIcon != null) {
        final SystemTray tray = SystemTray.getSystemTray();
        tray.remove(trayIcon);
    }
}
 
Example 26
Project: xsharing-services-router   File: BatchManagerBean.java   View source code 5 votes vote down vote up
@PreDestroy
public void destroy() {
    JobOperator jo = BatchRuntime.getJobOperator();
    stashList.stream()
             .map(HashMap::keySet)
             .flatMap(Collection::stream) // join multiple sets together
             .forEach(jo::stop); // signal every job that we are going down and they should stop
}
 
Example 27
Project: Spring-Security-Third-Edition   File: DataSourceConfig.java   View source code 5 votes vote down vote up
/**
 * DataSource PreDestroy call-back
 * @throws SQLException
 */
@PreDestroy()
public void dataSourceDestroy() throws SQLException {
    if (database != null) {
        database.shutdown();
    }
}
 
Example 28
Project: GoPush   File: MonitorDataCenterService.java   View source code 4 votes vote down vote up
@PreDestroy
public void destory() {
    monitorDataCenterPool.clear();
    zkUtils.destory();
}
 
Example 29
Project: iothub   File: CoapTransportService.java   View source code 4 votes vote down vote up
@PreDestroy
public void shutdown() {
  log.info("Stopping CoAP transport!");
  this.server.destroy();
  log.info("CoAP transport stopped!");
}
 
Example 30
Project: jdg-lab   File: CacheResources.java   View source code 4 votes vote down vote up
@PreDestroy
private void cleanup() {
    if (cacheManager != null)
        cacheManager.stop();
}
 
Example 31
Project: iotplatform   File: CoapTransportService.java   View source code 4 votes vote down vote up
@PreDestroy
public void shutdown() {
  log.info("Stopping CoAP transport!");
  this.server.destroy();
  log.info("CoAP transport stopped!");
}
 
Example 32
Project: tomcat7   File: TesterServletWithLifeCycleMethods.java   View source code 4 votes vote down vote up
@PreDestroy
protected void preDestroy() {
    result = "preDestroy()";
}
 
Example 33
Project: accs-javaee8   File: Broadcaster.java   View source code 4 votes vote down vote up
@PreDestroy
public void free(){
    broadcaster.close();
    System.out.println("broadcaster closed");
}
 
Example 34
Project: iot-edge-greengrass   File: DefaultFileTailService.java   View source code 4 votes vote down vote up
@PreDestroy
public void preDestroy() {
    if (brokers != null) {
        brokers.forEach(FileMonitor::stop);
    }
}
 
Example 35
Project: scalable-coffee-shop   File: BaristaUpdateConsumer.java   View source code 4 votes vote down vote up
@PreDestroy
public void close() {
    eventConsumer.stop();
}
 
Example 36
Project: maildump   File: SmtpServerLauncher.java   View source code 4 votes vote down vote up
@PreDestroy
public void stop() {
	log.info("****** Stopping SMTP Server for domain " + smtpServer.getHostName() + " on port "
			+ smtpServer.getPort());
	smtpServer.stop();
}
 
Example 37
Project: Code4Health-Platform   File: CacheConfiguration.java   View source code 4 votes vote down vote up
@PreDestroy
public void destroy() {
    log.info("Closing Cache Manager");
    Hazelcast.shutdownAll();
}
 
Example 38
Project: flow-platform   File: AppConfig.java   View source code 4 votes vote down vote up
@PreDestroy
protected void destroy() throws IOException {
    FileUtils.deleteDirectory(folder.toFile());
}
 
Example 39
Project: iotplatform   File: MsgProducer.java   View source code 4 votes vote down vote up
@PreDestroy
public void destroy() {
  log.info("Stopping Kafka Producer....");
  try {
    this.producer.close();
  } catch (Exception e) {
    log.error("Failed to close producer during destroy()", e);
    throw new RuntimeException(e);
  }
  log.info("Kafka Producer is stopped now....");
}
 
Example 40
Project: dust-api   File: SlackIntegration.java   View source code 4 votes vote down vote up
@PreDestroy
public void destroy() {
    rtmClient.close();
    LOGGER.info("Closed RTM client.");
}