Search in sources :

Example 76 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class CacheProperties method loadProperties.

private void loadProperties(EjbContainer ejbContainer, EjbDescriptor ejbDesc, BeanCacheDescriptor beanCacheDes) {
    numberOfVictimsToSelect = Integer.parseInt(ejbContainer.getCacheResizeQuantity());
    maxCacheSize = Integer.parseInt(ejbContainer.getMaxCacheSize());
    cacheIdleTimeoutInSeconds = Integer.parseInt(ejbContainer.getCacheIdleTimeoutInSeconds());
    removalTimeoutInSeconds = Integer.parseInt(ejbContainer.getRemovalTimeoutInSeconds());
    victimSelectionPolicy = ejbContainer.getVictimSelectionPolicy();
    // specified in sun-ejb-jar.xml, that has highest precedence.
    if (ejbDesc instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        if (sessionDesc.hasStatefulTimeout()) {
            long value = sessionDesc.getStatefulTimeoutValue();
            TimeUnit unit = sessionDesc.getStatefulTimeoutUnit();
            value = TimeUnit.SECONDS.convert(value, unit);
            if (value < 0) {
                this.removalTimeoutInSeconds = -1;
                this.cacheIdleTimeoutInSeconds = -1;
            } else if (value == 0) {
                this.removalTimeoutInSeconds = 1;
                this.cacheIdleTimeoutInSeconds = 2;
            } else {
                this.removalTimeoutInSeconds = (int) value;
                this.cacheIdleTimeoutInSeconds = (int) (value + 1);
            }
        }
        /* lifespan of an idle sfsb is time-in-cache + time-on-disk, with cacheIdleTimeoutInSeconds setting
               for the 1st interval and removalTimeoutInSeconds for the 2nd. So if you add them, the sfsb will stay
               in the cache to the max possible interval, and because it'll be never written to disk,
               there will be nothing to remove from there.
               
               set cacheIdleTimeoutInSeconds and maxCacheSize will cause cache never overflow, and sfsb just be
               removed from cache when cacheIdleTimeoutInSeconds arrives */
        if (sessionDesc.isStateful() && !sessionDesc.isPassivationCapable()) {
            cacheIdleTimeoutInSeconds = cacheIdleTimeoutInSeconds + removalTimeoutInSeconds;
            maxCacheSize = -1;
        }
    }
    if (beanCacheDes != null) {
        int temp = 0;
        if ((temp = beanCacheDes.getResizeQuantity()) != -1) {
            this.numberOfVictimsToSelect = temp;
        }
        if ((temp = beanCacheDes.getMaxCacheSize()) != -1) {
            this.maxCacheSize = temp;
        }
        if ((temp = beanCacheDes.getCacheIdleTimeoutInSeconds()) != -1) {
            this.cacheIdleTimeoutInSeconds = temp;
        }
        if ((temp = beanCacheDes.getRemovalTimeoutInSeconds()) != -1) {
            this.removalTimeoutInSeconds = temp;
        }
        if ((beanCacheDes.getVictimSelectionPolicy()) != null) {
            this.victimSelectionPolicy = beanCacheDes.getVictimSelectionPolicy();
        }
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 77 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class SafeProperties method setHomeTargetMethodInfo.

private void setHomeTargetMethodInfo(InvocationInfo invInfo, boolean isLocal) throws EJBException {
    Class homeIntfClazz = isLocal ? javax.ejb.EJBLocalHome.class : javax.ejb.EJBHome.class;
    Class methodClass = invInfo.method.getDeclaringClass();
    Class[] paramTypes = invInfo.method.getParameterTypes();
    String methodName = invInfo.method.getName();
    try {
        Method m = homeIntfClazz.getMethod(methodName, paramTypes);
        // Attempt to override Home/LocalHome method.  Print warning
        // but don't treat it as a fatal error. At runtime,
        // the EJBHome/EJBLocalHome method will be called.
        String[] params = { m.toString(), invInfo.method.toString() };
        _logger.log(Level.WARNING, ILLEGAL_EJB_INTERFACE_OVERRIDE, params);
        invInfo.ejbIntfOverride = true;
        return;
    } catch (NoSuchMethodException nsme) {
    }
    try {
        if (invInfo.startsWithCreate) {
            String extraCreateChars = methodName.substring("create".length());
            invInfo.targetMethod1 = ejbClass.getMethod("ejbCreate" + extraCreateChars, paramTypes);
            adjustHomeTargetMethodInfo(invInfo, methodName, paramTypes);
        } else if (invInfo.startsWithFind) {
            String extraFinderChars = methodName.substring("find".length());
            invInfo.targetMethod1 = ejbClass.getMethod("ejbFind" + extraFinderChars, paramTypes);
        } else {
            // HOME method
            String upperCasedName = methodName.substring(0, 1).toUpperCase(Locale.US) + methodName.substring(1);
            invInfo.targetMethod1 = ejbClass.getMethod("ejbHome" + upperCasedName, paramTypes);
        }
    } catch (NoSuchMethodException nsme) {
        if ((methodClass == localBusinessHomeIntf) || (methodClass == remoteBusinessHomeIntf) || (methodClass == ejbOptionalLocalBusinessHomeIntf || (methodClass == GenericEJBHome.class))) {
        // Not an error.  This is the case where the EJB 3.0
        // client view is being used and there is no corresponding
        // create/init method.
        } else if (isStatelessSession || isSingleton) {
        // Ignore.  Not an error.
        // EJB 3.0 Stateless session ejbCreate/PostConstruct
        // is decoupled from RemoteHome/LocalHome create().
        } else {
            Method initMethod = null;
            if (isSession) {
                EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDescriptor;
                for (EjbInitInfo next : sessionDesc.getInitMethods()) {
                    MethodDescriptor beanMethod = next.getBeanMethod();
                    Method m = beanMethod.getMethod(sessionDesc);
                    if (next.getCreateMethod().getName().equals(methodName) && TypeUtil.sameParamTypes(m, invInfo.method)) {
                        initMethod = m;
                        break;
                    }
                }
            }
            if (initMethod != null) {
                invInfo.targetMethod1 = initMethod;
            } else {
                Object[] params = { logParams[0], (isLocal ? "LocalHome" : "Home"), invInfo.method.toString() };
                _logger.log(Level.WARNING, BEAN_CLASS_METHOD_NOT_FOUND, params);
                // Treat this as a warning instead of a fatal error.
                // That matches the behavior of the generated code.
                // Mark the target methods as null.  If this method is
                // invoked at runtime it will be result in an exception
                // from the invocation handlers.
                invInfo.targetMethod1 = null;
                invInfo.targetMethod2 = null;
            }
        }
    }
}
Also used : Method(java.lang.reflect.Method) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) com.sun.ejb(com.sun.ejb) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 78 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class ExpiredSessionsRemovalTask method buildComponents.

public void buildComponents(byte[] ipAddress, int port, DeploymentContext dc) throws Exception {
    if (availabilityService != null) {
        this.HAEnabled = Boolean.valueOf(availabilityService.getAvailabilityEnabled());
        _logger.log(Level.FINE, SFSB_BUILDER_TOP_LEVEL_AVAILABILITY_SERVICE_ENABLED, this.HAEnabled);
        if ((this.HAEnabled) && (ejbAvailability != null)) {
            this.HAEnabled = Boolean.valueOf(ejbAvailability.getAvailabilityEnabled());
            _logger.log(Level.FINE, SFSB_BUILDER_EJB_AVAILABILITY_SERVICE_ENABLED, this.HAEnabled);
        }
        boolean appLevelHAEnabled = false;
        try {
            if (HAEnabled) {
                if (dc != null) {
                    DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
                    if (params != null) {
                        appLevelHAEnabled = params.availabilityenabled;
                        asyncReplication = params.asyncreplication;
                    }
                }
                _logger.log(Level.FINE, SFSB_BUILDER_GLOBAL_AND_APP_AVAILABILITY_ENABLED, new Object[] { this.HAEnabled, appLevelHAEnabled });
            }
        } catch (Exception ex) {
            _logger.log(Level.WARNING, SFSB_BUILDER_DETERMINE_AVAILABILITY_EXCEPTION, ex);
            appLevelHAEnabled = false;
        }
        HAEnabled = HAEnabled && appLevelHAEnabled;
        _logger.log(Level.FINE, SFSB_BUILDER_RESOLVED_AVAILABILITY_ENABLED, this.HAEnabled);
    }
    EjbSessionDescriptor sessionDescriptor = (EjbSessionDescriptor) ejbDescriptor;
    // When passivation is disabled, we should also forbid ha.
    if (!sessionDescriptor.isPassivationCapable() && HAEnabled) {
        if (_logger.isLoggable(Level.WARNING)) {
            _logger.log(Level.WARNING, SFSB_HA_DISABLED_BY_PASSIVATION_SETTING, ejbDescriptor.getEjbClassName());
        }
        HAEnabled = false;
    }
    buildCheckpointPolicy(this.HAEnabled);
    buildSFSBUUIDUtil(ipAddress, port);
    // First build BackingStore before Cache is built
    if (sessionDescriptor.isPassivationCapable()) {
        buildStoreManager();
    } else {
        if (_logger.isLoggable(TRACE_LEVEL)) {
            _logger.log(TRACE_LEVEL, "Stateful session bean passivation is disabled, so do not create store manger");
        }
    }
    buildCache();
    scheduleTimerTasks(sfsbContainer);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException)

Aggregations

EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)78 Result (com.sun.enterprise.tools.verifier.Result)28 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)28 Method (java.lang.reflect.Method)25 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)23 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)18 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)7 Iterator (java.util.Iterator)6 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)6 Set (java.util.Set)5 EJBException (javax.ejb.EJBException)4 Container (com.sun.ejb.Container)3 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)3 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)3 NoSuchEJBException (javax.ejb.NoSuchEJBException)3