Search in sources :

Example 36 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class BasicSharedServiceTest method createSharedServices.

private void createSharedServices() {
    System.out.println("################### Trying to Create Shared Service #######################");
    ServiceLocator habitat = Globals.getDefaultHabitat();
    org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
    ActionReport report = habitat.getService(ActionReport.class);
    org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("create-shared-service", report);
    ParameterMap parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "JavaEE");
    parameterMap.add("characteristics", "service-type=JavaEE");
    parameterMap.add("configuration", "min.clustersize=2:max.clustersize=4");
    parameterMap.add("DEFAULT", "my-shared-gf-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-gf-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    // Create shared service of type Database
    // asadmin create-shared-service --characteristics service-type=Database --configuration database.name=my-shared-db-service --servicetype Database my-shared-db-service
    parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "Database");
    parameterMap.add("characteristics", "service-type=Database");
    parameterMap.add("configuration", "database.name=my-shared-db-service");
    parameterMap.add("DEFAULT", "my-shared-db-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-db-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    // Create shared service of type LB
    // asadmin create-shared-service --characteristics service-type=LB --configuration http-port=50080:https-port=50081:ssl-enabled=true --servicetype LB my-shared-lb-service
    parameterMap = new ParameterMap();
    parameterMap.add("servicetype", "LB");
    parameterMap.add("characteristics", "service-type=LB");
    parameterMap.add("configuration", "http-port=50080:https-port=50081:ssl-enabled=true");
    parameterMap.add("DEFAULT", "my-shared-lb-service");
    invocation.parameters(parameterMap).execute();
    System.out.println("Created shared service 'my-shared-lb-service' :" + !report.hasFailures());
    Assert.assertFalse(report.hasFailures());
    // List the services and check the status of both the services - it should be 'RUNNING'
    invocation = commandRunner.getCommandInvocation("list-services", report);
    parameterMap = new ParameterMap();
    parameterMap.add("scope", "shared");
    parameterMap.add("output", "service-name,state");
    invocation.parameters(parameterMap).execute();
    boolean sharedServiceStarted = false;
    List<Map<String, String>> list = (List<Map<String, String>>) report.getExtraProperties().get("list");
    for (Map<String, String> map : list) {
        sharedServiceStarted = false;
        String state = map.get("STATE");
        if ("RUNNING".equalsIgnoreCase(state)) {
            sharedServiceStarted = true;
        } else {
            break;
        }
    }
    // check if the shared services are started.
    Assert.assertTrue(sharedServiceStarted);
// Try starting an uncreated service. Should fail
/* parameterMap=new ParameterMap();
        parameterMap.add("DEFAULT","Uncreated-shared-db-service");
        invocation.parameters(parameterMap).execute();

        System.out.println("Started uncreated db shared service"+!report.hasFailures());
        //Assert.assertTrue(report.hasFailures());*/
}
Also used : ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) List(java.util.List) CommandRunner(org.glassfish.embeddable.CommandRunner) ParameterMap(org.glassfish.api.admin.ParameterMap) Map(java.util.Map)

Example 37 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class WeldUtils method hasCDIEnablingAnnotations.

/**
 * Determine whether there are any beans annotated with annotations that should enable CDI
 * processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 * @param paths   The paths to check for annotated beans
 *
 * @return true, if there is at least one bean annotated with a qualified annotation in the specified paths
 */
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths) {
    List<String> result = new ArrayList<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at) && type.wasDefinedIn(paths)) {
                        if (!result.contains(at.getName())) {
                            result.add(at.getName());
                        }
                    }
                }
            }
        }
    }
    return !(result.isEmpty());
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) ArrayList(java.util.ArrayList) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType)

Example 38 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class WeldUtils method getCDIAnnotatedClassNames.

/**
 * Get the names of any classes that are annotated with bean-defining annotations, which should
 * enable CDI processing even in the absence of a beans.xml descriptor.
 *
 * @param context The DeploymentContext
 *
 * @return A collection of class names; The collection could be empty if none are found.
 */
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context) {
    Set<String> result = new HashSet<String>();
    Types types = getTypes(context);
    if (types != null) {
        Iterator<Type> typesIter = types.getAllTypes().iterator();
        while (typesIter.hasNext()) {
            Type type = typesIter.next();
            if (!(type instanceof AnnotationType)) {
                Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
                while (annotations.hasNext()) {
                    AnnotationModel am = annotations.next();
                    AnnotationType at = am.getType();
                    if (isCDIEnablingAnnotation(at)) {
                        if (!result.contains(at.getName())) {
                            result.add(type.getName());
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : Types(org.glassfish.hk2.classmodel.reflect.Types) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) Type(org.glassfish.hk2.classmodel.reflect.Type) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) AnnotationType(org.glassfish.hk2.classmodel.reflect.AnnotationType) HashSet(java.util.HashSet)

Example 39 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class ActiveJmsResourceAdapter method isASRmiRegistryPortAvailable.

private boolean isASRmiRegistryPortAvailable(JmsRaUtil jmsraUtil) {
    if (_logger.isLoggable(Level.FINE))
        logFine("isASRmiRegistryPortAvailable - JMSService Type:" + jmsraUtil.getJMSServiceType());
    // AS RMI Registry. So the check below is not necessary.
    if (jmsraUtil.getJMSServiceType().equals(REMOTE) || jmsraUtil.getJMSServiceType().equals(LOCAL)) {
        return false;
    }
    try {
        JmxConnector jmxConnector = getJmxConnector();
        if (!"true".equals(jmxConnector.getEnabled()))
            return false;
        if ("true".equals(jmxConnector.getSecurityEnabled()))
            return false;
        // Attempt to detect JMXStartupService for RMI registry
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Detecting JMXStartupService...");
        }
        JMXStartupService jmxservice = Globals.get(JMXStartupService.class);
        if (jmxservice == null)
            return false;
        jmxservice.waitUntilJMXConnectorStarted();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Found JMXStartupService");
        }
        String name = "rmi://" + getConfiguredRmiRegistryHost() + ":" + getConfiguredRmiRegistryPort() + "/jmxrmi";
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Attempting to list " + name);
        }
        Naming.list(name);
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("List on " + name + " succeeded");
        }
        // return configured port only if RMI registry is available
        return true;
    } catch (Exception e) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Failed to detect JMX RMI Registry: " + e.getMessage());
        }
        return false;
    }
}
Also used : JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) JMXStartupService(org.glassfish.admin.mbeanserver.JMXStartupService) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 40 with Type

use of org.glassfish.hk2.classmodel.reflect.Type in project Payara by payara.

the class ExistingDomainTest method Test.

@Test
public void Test() {
    ServiceLocator habitat = server.getHabitat();
    System.out.println("Process type is " + habitat.<ProcessEnvironment>getService(ProcessEnvironment.class).getProcessType());
    for (Sniffer s : habitat.<Sniffer>getAllServices(Sniffer.class)) {
        System.out.println("Got sniffer " + s.getModuleType());
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Sniffer(org.glassfish.api.container.Sniffer) Test(org.junit.Test)

Aggregations

ServiceLocator (org.glassfish.hk2.api.ServiceLocator)18 ActionReport (org.glassfish.api.ActionReport)13 MultiException (org.glassfish.hk2.api.MultiException)13 ParameterMap (org.glassfish.api.admin.ParameterMap)12 List (java.util.List)10 Map (java.util.Map)10 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)7 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Sniffer (org.glassfish.api.container.Sniffer)6 CommandRunner (org.glassfish.embeddable.CommandRunner)6 File (java.io.File)5 Types (org.glassfish.hk2.classmodel.reflect.Types)5 PropertyVetoException (java.beans.PropertyVetoException)4 Method (java.lang.reflect.Method)4 Type (java.lang.reflect.Type)4 JsonString (javax.json.JsonString)4 PrivilegedActionException (java.security.PrivilegedActionException)3