Example usage for java.lang Class getDeclaredConstructor

List of usage examples for java.lang Class getDeclaredConstructor

Introduction

In this page you can find the example usage for java.lang Class getDeclaredConstructor.

Prototype

@CallerSensitive
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
        throws NoSuchMethodException, SecurityException 

Source Link

Document

Returns a Constructor object that reflects the specified constructor of the class or interface represented by this Class object.

Usage

From source file:de.innovationgate.wgpublisher.WGACore.java

public void initClusterService(WGAConfiguration oldConfig) {
    if (oldConfig == null
            || !getWgaConfiguration().getClusterConfiguration().equals(oldConfig.getClusterConfiguration())) {
        logCategoryInfo("Cluster Service", 1);
        if (_clusterService != null) {
            try {
                getLog().info("Shutting down current cluster service instance to apply config changes.");
                _clusterService.shutdown();
                _clusterService = null;/*from  w w w . j ava  2  s.com*/
            } catch (Throwable e) {
                getLog().error("Failed to shutdown cluster service instance '"
                        + _clusterService.getClass().getName() + "'", e);
            }
        }

        // choose cluster service
        String implClass = getWgaConfiguration().getClusterConfiguration().getImplClassName();
        if (implClass != null && getWgaConfiguration().getClusterConfiguration().isEnabled()) {
            try {
                Class<ClusterService> clusterServiceImplClass = (Class<ClusterService>) getLibraryLoader()
                        .loadClass(implClass);
                Constructor<ClusterService> c = clusterServiceImplClass.getDeclaredConstructor(WGACore.class);
                _clusterService = c.newInstance(this);
            } catch (Throwable e) {
                getLog().error("Failed to create cluster service instance of type '" + implClass + "'", e);
            }
        }

        // nothing configured or impl class not found - fallback to single node cluster
        if (_clusterService == null) {
            _clusterService = new SingleNodeClusterService(this);
        }

        try {
            getLog().info(
                    "Starting cluster service implementation '" + _clusterService.getClass().getName() + "'");
            _clusterService.startup();
        } catch (Throwable e) {
            getLog().error("Startup of cluster service implementation '" + _clusterService.getClass().getName()
                    + "' failed.", e);
            // fallback to single node cluster if possible
            if (!_clusterService.getClass().equals(SingleNodeClusterService.class)) {
                getLog().info("Falling back to default implementation '"
                        + SingleNodeClusterService.class.getName() + "'");
                try {
                    _clusterService = new SingleNodeClusterService(this);
                    _clusterService.startup();
                } catch (Throwable e1) {
                    getLog().error("Startup of cluster service implementation '"
                            + _clusterService.getClass().getName() + "' failed.", e1);
                }
            }
        }
    }
}