Search in sources :

Example 11 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class CommandResourceMetaData method processConfigBeans.

private static void processConfigBeans(ServiceLocator serviceLocator) {
    List<ActiveDescriptor<?>> allDescriptors = serviceLocator.getDescriptors(BuilderHelper.createContractFilter(ConfigInjector.class.getName()));
    HashSet<String> alreadyChecked = new HashSet<String>();
    for (ActiveDescriptor<?> ad : allDescriptors) {
        List<String> targets = ad.getMetadata().get("target");
        if (targets == null)
            continue;
        for (String t : targets) {
            if (alreadyChecked.contains(t))
                continue;
            alreadyChecked.add(t);
            try {
                Class<?> tclass = Class.forName(t);
                if (tclass != null && ConfigBeanProxy.class.isAssignableFrom(tclass)) {
                    String beanName = tclass.getSimpleName();
                    for (Method m : tclass.getMethods()) {
                        if (m.isAnnotationPresent(Create.class)) {
                            addCreateMethod(beanName, m, m.getAnnotation(Create.class));
                        } else if (m.isAnnotationPresent(Delete.class)) {
                            addDeleteMethod(beanName, m, m.getAnnotation(Delete.class));
                        }
                    }
                }
            } catch (ClassNotFoundException cnfe) {
                continue;
            }
        }
    }
}
Also used : Delete(org.glassfish.config.support.Delete) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Method(java.lang.reflect.Method) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Create(org.glassfish.config.support.Create) HashSet(java.util.HashSet)

Example 12 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class CDIExtension method afterBeanDiscovery.

/**
 * This method will ensure that the file which indicates that the
 * application has shut down properly has been removed and then
 * adds the HK2 service to the system
 *
 * @param beforeBeanDiscovery
 */
@SuppressWarnings("unused")
private void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery) {
    ServiceLocator locator = getServiceLocator();
    if (locator == null)
        return;
    HK2ExtensionVerifier verifier = locator.getService(HK2ExtensionVerifier.class);
    verifier.afterBeanDiscoveryCalled();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator)

Example 13 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class CDIExtension method beforeBeanDiscovery.

/**
 * This method will ensure that the file which indicates that the
 * application has shut down properly has been removed and then
 * adds the HK2 service to the system
 *
 * @param beforeBeanDiscovery
 */
@SuppressWarnings("unused")
private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery) {
    File destructoFile = createDestructionFileObject();
    if (destructoFile == null)
        return;
    if (destructoFile.exists()) {
        if (destructoFile.delete() == false)
            return;
    }
    ServiceLocator locator = getServiceLocator();
    if (locator == null)
        return;
    Descriptor d = BuilderHelper.link(HK2ExtensionVerifier.class).in(Singleton.class.getName()).andLoadWith(new HK2LoaderImpl()).build();
    // Just having the service present is enough for the first callback
    ServiceLocatorUtilities.addOneDescriptor(locator, d);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Singleton(javax.inject.Singleton) Descriptor(org.glassfish.hk2.api.Descriptor) File(java.io.File)

Example 14 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class ExistingConfigurationTest method setupServer.

@Test
public void setupServer() throws Exception {
    Server server = null;
    Port port = null;
    File f = EmbeddedServerUtils.getServerLocation();
    try {
        EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
        efsb.installRoot(f);
        // find the domain root.
        f = EmbeddedServerUtils.getDomainLocation(f);
        f = new File(f, "config");
        f = new File(f, "domain.xml");
        Assert.assertTrue(f.exists());
        efsb.configurationFile(f, true);
        server = EmbeddedServerUtils.createServer(efsb.build());
        ServiceLocator habitat = server.getHabitat();
        Collection<ServiceHandle<?>> vss = habitat.getAllServiceHandles(com.sun.enterprise.config.serverbeans.VirtualServer.class);
        Assert.assertTrue(vss.size() > 0);
        for (ServiceHandle<?> vs : vss) {
            Object virtualServer = vs.getService();
            Method m = virtualServer.getClass().getMethod("getId");
            Assert.assertNotNull("Object returned does not implement getId, is it a virtual server ?", m);
            String id = (String) m.invoke(virtualServer);
            System.out.println("Virtual Server " + id);
            Assert.assertNotNull("Got a null virtual server ID", id);
        }
        Collection<ServiceHandle<?>> nls = habitat.getAllServiceHandles(org.glassfish.grizzly.config.dom.NetworkListener.class);
        Assert.assertTrue(nls.size() > 1);
        for (ServiceHandle<?> nl : nls) {
            Object networkListener = nl.getService();
            Method m = networkListener.getClass().getMethod("getPort");
            Assert.assertNotNull("Object returned does not implement getPort, is it a networkListener ?", m);
            String p = (String) m.invoke(networkListener);
            System.out.println("Network Listener " + p);
            Assert.assertNotNull("Got a null networkListener port", p);
        }
        server.start();
        port = server.createPort(8758);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        if (port != null) {
            port.close();
        }
        EmbeddedServerUtils.shutdownServer(server);
    }
}
Also used : Method(java.lang.reflect.Method) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) File(java.io.File) Test(org.junit.Test)

Example 15 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class ExistingDomainTest method Test.

@Test
public void Test() throws Exception {
    ServiceLocator habitat = server.getHabitat();
    System.out.println("Process type is " + habitat.<ProcessEnvironment>getService(ProcessEnvironment.class).getProcessType());
    Collection<ServiceHandle<?>> listeners = habitat.getAllServiceHandles(org.glassfish.grizzly.config.dom.NetworkListener.class);
    Assert.assertTrue(listeners.size() > 1);
    for (ServiceHandle<?> s : listeners) {
        Object networkListener = s.getService();
        Method m = networkListener.getClass().getMethod("getPort");
        Assert.assertNotNull("Object returned does not implement getPort, is it a networkListener ?", m);
        String port = (String) m.invoke(networkListener);
        System.out.println("Network Listener " + port);
        Assert.assertNotNull("Got a null networkListener port", port);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

MultiException (org.glassfish.hk2.api.MultiException)18 Method (java.lang.reflect.Method)16 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)8 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)8 PrivilegedActionException (java.security.PrivilegedActionException)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)6 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)6 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)6 File (java.io.File)5 HashMap (java.util.HashMap)5 ConfigModel (org.jvnet.hk2.config.ConfigModel)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Attribute (org.jvnet.hk2.config.Attribute)4 PropertyVetoException (java.beans.PropertyVetoException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashSet (java.util.HashSet)3