Java Code Examples for org.springframework.beans.factory.DisposableBean

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Gemini-Blueprint, under directory /core/src/main/java/org/eclipse/gemini/blueprint/compendium/internal/cm/.

Source file: ManagedFactoryDisposableInvoker.java

  19 
vote

/** 
 * Constructs a new <code>ManagedFactoryDisposableAdapter</code> instance.
 * @param methodName destruction method name
 */
public ManagedFactoryDisposableInvoker(Class<?> beanClass,String methodName){
  this.isDisposable=DisposableBean.class.isAssignableFrom(beanClass);
  if (StringUtils.hasText(methodName)) {
    this.customSpringMethod=detectCustomSpringMethod(beanClass,methodName);
    if (customSpringMethod != null) {
      Class<?>[] types=customSpringMethod.getParameterTypes();
      this.customSpringMethodArgs=((types.length == 1 && types[0].equals(boolean.class)) ? new Object[]{Boolean.TRUE} : null);
    }
 else {
      this.customSpringMethodArgs=null;
    }
    this.customOsgiDestructionMethod=detectCustomOsgiMethod(beanClass,methodName);
  }
 else {
    this.customSpringMethod=null;
    this.customSpringMethodArgs=null;
    this.customOsgiDestructionMethod=null;
  }
}
 

Example 2

From project Gemini-Blueprint, under directory /core/src/main/java/org/eclipse/gemini/blueprint/compendium/internal/cm/.

Source file: ManagedFactoryDisposableInvoker.java

  19 
vote

public void destroy(String beanName,Object beanInstance,DestructionCodes code){
  if (isDisposable) {
    if (log.isDebugEnabled()) {
      log.debug("Invoking destroy() on bean with name '" + beanName + "'");
    }
    try {
      ((DisposableBean)beanInstance).destroy();
    }
 catch (    Throwable ex) {
      String msg="Invocation of destroy method failed on bean with name '" + beanName + "'";
      if (log.isDebugEnabled()) {
        log.warn(msg,ex);
      }
 else {
        log.warn(msg + ": " + ex);
      }
    }
  }
  invokeCustomMethod(beanName,beanInstance);
  invokeCustomMethod(beanName,beanInstance,code);
}
 

Example 3

From project Gemini-Blueprint, under directory /extender/src/main/java/org/eclipse/gemini/blueprint/extender/internal/support/.

Source file: ExtenderConfiguration.java

  19 
vote

/** 
 * {@inheritDoc}Cleanup the configuration items.
 */
public void destroy(){
synchronized (lock) {
    if (isMulticasterManagedInternally) {
      eventMulticaster.removeAllListeners();
      eventMulticaster=null;
    }
    if (extenderConfiguration != null) {
      extenderConfiguration.close();
      extenderConfiguration=null;
    }
    if (forceThreadShutdown) {
      if (isTaskExecutorManagedInternally) {
        log.warn("Forcing the (internally created) taskExecutor to stop...");
        ThreadGroup th=((SimpleAsyncTaskExecutor)taskExecutor).getThreadGroup();
        if (!th.isDestroyed()) {
          th.interrupt();
        }
      }
      taskExecutor=null;
    }
    if (isShutdownTaskExecutorManagedInternally) {
      try {
        ((DisposableBean)shutdownTaskExecutor).destroy();
      }
 catch (      Exception ex) {
        log.debug("Received exception while shutting down shutdown task executor",ex);
      }
      shutdownTaskExecutor=null;
    }
  }
}
 

Example 4

From project Gemini-Blueprint, under directory /extender/src/main/java/org/eclipse/gemini/blueprint/extender/internal/util/concurrent/.

Source file: RunnableTimedExecution.java

  19 
vote

public static boolean execute(Runnable task,long waitTime,TaskExecutor taskExecutor){
  Assert.notNull(task);
  Counter counter=new Counter("counter for task: " + task);
  Runnable wrapper=new MonitoredRunnable(task,counter);
  boolean internallyManaged=false;
  if (taskExecutor == null) {
    taskExecutor=new SimpleTaskExecutor();
    internallyManaged=true;
  }
  counter.increment();
  taskExecutor.execute(wrapper);
  if (counter.waitForZero(waitTime)) {
    log.error(task + " did not finish in " + waitTime+ "ms; consider taking a snapshot and then shutdown the VM in case the thread still hangs");
    if (internallyManaged) {
      try {
        ((DisposableBean)taskExecutor).destroy();
      }
 catch (      Exception e) {
        log.error("Exception thrown while destroying internally managed thread executor",e);
      }
    }
    return true;
  }
  return false;
}
 

Example 5

From project jagger, under directory /chassis/core/src/main/java/com/griddynamics/jagger/kernel/.

Source file: SimpleKernel.java

  19 
vote

@Override public void terminate(){
  log.debug("termination signal received!");
  if (context instanceof DisposableBean) {
    try {
      ((DisposableBean)context).destroy();
    }
 catch (    Exception e) {
      log.error("Error during context termination: {}",e.getMessage(),e);
    }
  }
  for (long i=lock.getCount(); i > 0; i--)   lock.countDown();
}
 

Example 6

From project servicemix-archetypes, under directory /servicemix-embedded-simple/src/main/resources/archetype-resources/src/main/java/.

Source file: Main.java

  19 
vote

/** 
 * @param args
 */
public static void main(String[] args){
  try {
    final ApplicationContext context=new ClassPathXmlApplicationContext("servicemix.xml");
    SpringJBIContainer container=(SpringJBIContainer)context.getBean("jbi");
    container.onShutDown(new Runnable(){
      public void run(){
        if (context instanceof DisposableBean) {
          try {
            ((DisposableBean)context).destroy();
          }
 catch (          Exception e) {
            System.out.println("Caught: " + e);
            e.printStackTrace();
          }
        }
      }
    }
);
  }
 catch (  Exception e) {
    System.out.println("Caught: " + e);
    e.printStackTrace();
  }
}
 

Example 7

From project spring-data-keyvalue, under directory /spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/.

Source file: RedisMessageListenerContainer.java

  19 
vote

@Override public void destroy() throws Exception {
  initialized=false;
  stop();
  if (manageExecutor) {
    if (taskExecutor instanceof DisposableBean) {
      ((DisposableBean)taskExecutor).destroy();
      if (logger.isDebugEnabled()) {
        logger.debug("Stopped internally-managed task executor");
      }
    }
  }
}
 

Example 8

From project spring-data-keyvalue, under directory /spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/.

Source file: ConnectionFactoryTracker.java

  19 
vote

public static void cleanUp(){
  if (connFactories != null) {
    for (    RedisConnectionFactory connectionFactory : connFactories) {
      try {
        ((DisposableBean)connectionFactory).destroy();
      }
 catch (      Exception ex) {
        System.err.println("Cannot clean factory " + connectionFactory + ex);
      }
    }
  }
}
 

Example 9

From project spring-data-redis, under directory /src/main/java/org/springframework/data/redis/listener/.

Source file: RedisMessageListenerContainer.java

  19 
vote

public void destroy() throws Exception {
  initialized=false;
  stop();
  if (manageExecutor) {
    if (taskExecutor instanceof DisposableBean) {
      ((DisposableBean)taskExecutor).destroy();
      if (logger.isDebugEnabled()) {
        logger.debug("Stopped internally-managed task executor");
      }
    }
  }
}
 

Example 10

From project spring-data-redis, under directory /src/test/java/org/springframework/data/redis/.

Source file: ConnectionFactoryTracker.java

  19 
vote

public static void cleanUp(){
  if (connFactories != null) {
    for (    RedisConnectionFactory connectionFactory : connFactories) {
      try {
        ((DisposableBean)connectionFactory).destroy();
      }
 catch (      Exception ex) {
        System.err.println("Cannot clean factory " + connectionFactory + ex);
      }
    }
  }
}
 

Example 11

From project spring-gemfire, under directory /src/main/java/org/springframework/data/gemfire/listener/.

Source file: ContinuousQueryListenerContainer.java

  19 
vote

public void destroy() throws Exception {
  initialized=false;
  stop();
  closeQueries();
  if (manageExecutor) {
    if (taskExecutor instanceof DisposableBean) {
      ((DisposableBean)taskExecutor).destroy();
      if (logger.isDebugEnabled()) {
        logger.debug("Stopped internally-managed task executor");
      }
    }
  }
}
 

Example 12

From project vraptor, under directory /vraptor-core/src/main/java/br/com/caelum/vraptor/ioc/spring/.

Source file: SpringBasedContainer.java

  19 
vote

public void stop(){
  parentContext.stop();
  if (parentContext instanceof DisposableBean) {
    try {
      ((DisposableBean)parentContext).destroy();
    }
 catch (    Exception e) {
      logger.error("Error when destroying application context",e);
    }
  }
}