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

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

There is a newer version: 2.0.5.Final
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();
    }
}