All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.naming.remote.client.CacheShutdown Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 35.0.0.Beta1
Show newest version
package org.jboss.naming.remote.client;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * Class which registers a shutdown hook to close any outstanding endpoints and connections.
 *
 * @author Stuart Douglas
 */
public class CacheShutdown implements Runnable {

    private final EndpointCache endpointCache;
    private final NamingStoreCache contextCache;


    public CacheShutdown(final NamingStoreCache contextCache, final EndpointCache endpointCache) {
        this.contextCache = contextCache;
        this.endpointCache = endpointCache;
    }

    public void registerShutdownHandler() {
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                Runtime.getRuntime().addShutdownHook(new Thread(CacheShutdown.this));
                return null;
            }
        });
    }


    public void run() {
        contextCache.shutdown();
        endpointCache.shutdown();
    }
}