Search in sources :

Example 41 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class LazyEnlistableResourceManagerImpl method lazyEnlist.

/**
 * This is called by the PoolManager (in turn by the LazyEnlistableConnectionManager)
 * when a lazy enlistment is sought.
 * @param mc ManagedConnection
 * @throws ResourceException
 */
public void lazyEnlist(ManagedConnection mc) throws ResourceException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("Entering lazyEnlist");
    }
    // J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
    JavaEETransactionManager tm = ConnectorRuntime.getRuntime().getTransactionManager();
    Transaction tran = null;
    try {
        tran = tm.getTransaction();
        if (tran == null) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine(" Transaction null - not enlisting ");
            }
            return;
        }
    } catch (SystemException se) {
        ResourceException re = new ResourceException(se.getMessage());
        re.initCause(se);
        throw re;
    }
    // List invList = Switch.getSwitch().getInvocationManager().getAllInvocations();
    List invList = ConnectorRuntime.getRuntime().getInvocationManager().getAllInvocations();
    ResourceHandle h = null;
    for (int j = invList.size(); j > 0; j--) {
        ComponentInvocation inv = (ComponentInvocation) invList.get(j - 1);
        Object comp = inv.getInstance();
        List l = tm.getResourceList(comp, inv);
        ListIterator it = l.listIterator();
        while (it.hasNext()) {
            ResourceHandle hand = (ResourceHandle) it.next();
            ManagedConnection toEnlist = (ManagedConnection) hand.getResource();
            if (mc.equals(toEnlist)) {
                h = hand;
                break;
            }
        }
    }
    // The other case might or might not work
    if (h != null && h.getResourceState().isUnenlisted()) {
        try {
            // Enable the suspended lazyenlistment so as to enlist the resource.
            h.setEnlistmentSuspended(false);
            tm.enlistResource(tran, h);
            // Suspend it back
            h.setEnlistmentSuspended(true);
        } catch (Exception e) {
            // In the rare cases where enlistResource throws exception, we
            // should report the resource to the pool as bad
            PoolManager mgr = ConnectorRuntime.getRuntime().getPoolManager();
            mgr.putbackBadResourceToPool(h);
            _logger.log(Level.WARNING, "poolmgr.err_enlisting_res_in_getconn", h.getResourceSpec().getPoolInfo());
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("rm.enlistResource threw Exception. Evicting resource from pool");
            }
            // and rethrow the exception
            throw new ResourceException(e);
        }
    }
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) ListIterator(java.util.ListIterator) PoolManager(com.sun.enterprise.resource.pool.PoolManager) PoolingException(com.sun.appserv.connectors.internal.api.PoolingException) ResourceException(javax.resource.ResourceException) ResourceHandle(com.sun.enterprise.resource.ResourceHandle) ResourceException(javax.resource.ResourceException) List(java.util.List) ManagedConnection(javax.resource.spi.ManagedConnection)

Example 42 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class InjectionManagerImpl method injectInstance.

public void injectInstance(Object instance, String componentId, boolean invokePostConstruct) throws InjectionException {
    ComponentInvocation invocation = invocationMgr.getCurrentInvocation();
    if (invocation == null) {
        throw new InjectionException(localStrings.getLocalString("injection-manager.null-invocation-context", "Null invocation context"));
    }
    JndiNameEnvironment componentEnvironment = compEnvManager.getJndiNameEnvironment(componentId);
    if (componentEnvironment == null) {
        throw new InjectionException(localStrings.getLocalString("injection-manager.no-descriptor-registered-for-component", "No descriptor registered for componentId: {0}", componentId));
    }
    inject(instance.getClass(), instance, componentEnvironment, componentId, invokePostConstruct);
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) JndiNameEnvironment(com.sun.enterprise.deployment.JndiNameEnvironment) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 43 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class GlassfishNamingManagerImpl method getComponentId.

/**
 * Get the component id from the Invocation Manager.
 *
 * @return the component id as a string.
 */
private String getComponentId() throws NamingException {
    String id;
    ComponentInvocation ci;
    if (invMgr == null) {
        ci = habitat.<InvocationManager>getService(InvocationManager.class).getCurrentInvocation();
    } else {
        ci = invMgr.getCurrentInvocation();
    }
    if (ci == null) {
        throw new NamingException("Invocation exception: Got null ComponentInvocation ");
    }
    try {
        id = ci.getComponentId();
        if (id == null) {
            throw new NamingException("Invocation exception: ComponentId is null");
        }
    } catch (Throwable th) {
        NamingException ine = new NamingException("Invocation exception: " + th);
        ine.initCause(th);
        throw ine;
    }
    return id;
}
Also used : ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) NamingException(javax.naming.NamingException)

Example 44 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class AppTest method testEmptyJavaCompEnv.

@Test
public void testEmptyJavaCompEnv() {
    GlassfishNamingManagerImpl nm = null;
    InvocationManager im = new InvocationManagerImpl();
    ComponentInvocation inv = null;
    try {
        InitialContext ic = newInitialContext();
        triggerLoadingNamedProxies(ic);
        nm = new GlassfishNamingManagerImpl(ic);
        nm.setInvocationManager(im);
        inv = new ComponentInvocation("comp1", ComponentInvocation.ComponentInvocationType.EJB_INVOCATION, null, null, null);
        im.preInvoke(inv);
        nm.bindToComponentNamespace("app1", "mod1", "comp1", false, new ArrayList<Binding>());
        Context ctx = (Context) ic.lookup("java:comp/env");
        System.out.println("**lookup(java:comp/env) ==> " + ctx);
    } catch (javax.naming.NamingException nnfEx) {
        nnfEx.printStackTrace();
        assert (false);
    }
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding) InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) InvocationManagerImpl(org.glassfish.api.invocation.InvocationManagerImpl) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext)

Example 45 with ComponentInvocation

use of org.glassfish.api.invocation.ComponentInvocation in project Payara by payara.

the class AppTest method testNonCachingNamingObjectFactory.

@Test
public void testNonCachingNamingObjectFactory() {
    GlassfishNamingManagerImpl nm = null;
    InvocationManager im = new InvocationManagerImpl();
    ComponentInvocation inv = null;
    try {
        InitialContext ic = newInitialContext();
        triggerLoadingNamedProxies(ic);
        nm = new GlassfishNamingManagerImpl(ic);
        nm.setInvocationManager(im);
        List<Binding> bindings = new ArrayList<Binding>();
        NamingObjectFactory intFactory = new NamingObjectFactory() {

            private int counter = 1;

            public boolean isCreateResultCacheable() {
                return false;
            }

            public Object create(Context ic) {
                return new Integer(++counter);
            }

            public String toString() {
                return "Huh? ";
            }
        };
        bindings.add(new Binding("conf/area", intFactory));
        bindings.add(new Binding("conf/location", "Santa Clara"));
        nm.bindToComponentNamespace("app1", "mod1", "comp1", false, bindings);
        inv = new ComponentInvocation("comp1", ComponentInvocation.ComponentInvocationType.EJB_INVOCATION, null, null, null);
        im.preInvoke(inv);
        System.out.println("**lookup(java:comp/env/conf/area) ==> " + ic.lookup("java:comp/env/conf/area"));
        System.out.println("**lookup(java:comp/env/conf/location) ==> " + ic.lookup("java:comp/env/conf/location"));
        NamingObjectFactory floatFactory = new NamingObjectFactory() {

            private int counter = 1;

            public boolean isCreateResultCacheable() {
                return false;
            }

            public Object create(Context ic) {
                return Float.valueOf(("7" + (++counter)) + "." + 2323);
            }

            public String toString() {
                return "Huh? ";
            }
        };
        List<Binding> bindings2 = new ArrayList<Binding>();
        bindings2.add(new Binding("conf/area", floatFactory));
        bindings2.add(new Binding("conf/location", "Santa Clara[14]"));
        nm.bindToComponentNamespace("app1", "mod1", "comp2", false, bindings2);
        inv = new ComponentInvocation("comp2", ComponentInvocation.ComponentInvocationType.EJB_INVOCATION, null, null, null);
        im.preInvoke(inv);
        System.out.println("**lookup(java:comp/env/conf/area) ==> " + ic.lookup("java:comp/env/conf/area"));
        System.out.println("**lookup(java:comp/env/conf/location) ==> " + ic.lookup("java:comp/env/conf/location"));
        assert (true);
    } catch (InvocationException inEx) {
        inEx.printStackTrace();
        assert (false);
    } catch (Exception ex) {
        ex.printStackTrace();
        assert (false);
    } finally {
        try {
            im.postInvoke(inv);
            nm.unbindComponentObjects("comp1");
        } catch (InvocationException inEx) {
        } catch (Exception ex) {
        }
    }
}
Also used : JNDIBinding(org.glassfish.api.naming.JNDIBinding) InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) ArrayList(java.util.ArrayList) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) InvocationException(org.glassfish.api.invocation.InvocationException) InvocationManagerImpl(org.glassfish.api.invocation.InvocationManagerImpl) InvocationException(org.glassfish.api.invocation.InvocationException) NamingObjectFactory(com.sun.enterprise.naming.spi.NamingObjectFactory)

Aggregations

ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)67 InvocationManager (org.glassfish.api.invocation.InvocationManager)13 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)8 EjbInvocation (com.sun.ejb.EjbInvocation)7 InvocationException (org.glassfish.api.invocation.InvocationException)7 SecurityContext (com.sun.enterprise.security.SecurityContext)6 WebModule (com.sun.enterprise.web.WebModule)6 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)5 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)5 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)4 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)4 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)4 RemoteException (java.rmi.RemoteException)4 EJBInvocation (org.glassfish.ejb.api.EJBInvocation)4 ArrayList (java.util.ArrayList)3 NamingException (javax.naming.NamingException)3 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)3 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)3