Example usage for org.springframework.context SmartLifecycle stop

List of usage examples for org.springframework.context SmartLifecycle stop

Introduction

In this page you can find the example usage for org.springframework.context SmartLifecycle stop.

Prototype

void stop();

Source Link

Document

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

Usage

From source file:org.springframework.integration.support.SmartLifecycleRoleController.java

/**
 * Stop all registered {@link SmartLifecycle}s in the role.
 * @param role the role./*from  w  w  w.j  ava 2 s  .  c o  m*/
 */
public void stopLifecyclesInRole(String role) {
    if (this.lazyLifecycles.size() > 0) {
        addLazyLifecycles();
    }
    List<SmartLifecycle> lifecycles = this.lifecycles.get(role);
    if (lifecycles != null) {
        lifecycles = new ArrayList<SmartLifecycle>(lifecycles);
        Collections.sort(lifecycles,
                (o1, o2) -> o1.getPhase() < o2.getPhase() ? 1 : o1.getPhase() > o2.getPhase() ? -1 : 0);
        if (logger.isDebugEnabled()) {
            logger.debug("Stopping " + lifecycles + " in role " + role);
        }
        for (SmartLifecycle lifecycle : lifecycles) {
            try {
                lifecycle.stop();
            } catch (Exception e) {
                logger.error("Failed to stop " + lifecycle + " in role " + role, e);
            }
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("No components in role " + role + ". Nothing to stop");
        }
    }
}