Search in sources :

Example 6 with ScheduledTimerDescriptor

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

the class HazelcastTimerStore method createSchedulesOnServer.

@Override
public void createSchedulesOnServer(EjbDescriptor ejbDescriptor, String server_name) {
    Map<MethodDescriptor, List<ScheduledTimerDescriptor>> schedules = new HashMap<MethodDescriptor, List<ScheduledTimerDescriptor>>();
    for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
        MethodDescriptor method = schd.getTimeoutMethod();
        if (method != null && schd.getPersistent()) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "... processing " + method);
            }
            List<ScheduledTimerDescriptor> list = schedules.get(method);
            if (list == null) {
                list = new ArrayList<ScheduledTimerDescriptor>();
                schedules.put(method, list);
            }
            list.add(schd);
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "EJBTimerService - creating schedules for " + ejbDescriptor.getUniqueId());
    }
    createSchedules(ejbDescriptor.getUniqueId(), ejbDescriptor.getApplication().getUniqueId(), schedules, server_name);
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "EJBTimerService - finished processing schedules for BEAN ID: " + ejbDescriptor.getUniqueId());
    }
}
Also used : HashMap(java.util.HashMap) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 7 with ScheduledTimerDescriptor

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

the class HazelcastTimerStore method recoverAndCreateSchedules.

@Override
protected Map<TimerPrimaryKey, Method> recoverAndCreateSchedules(long containerId, long applicationId, Map<Method, List<ScheduledTimerDescriptor>> schedules, boolean deploy) {
    Map<TimerPrimaryKey, Method> result = new HashMap<TimerPrimaryKey, Method>();
    boolean lostCluster = false;
    Set<HZTimer> activeTimers = new HashSet<>();
    // get all timers for this container
    Collection<TimerPrimaryKey> containerKeys = (Collection<TimerPrimaryKey>) containerCache.get(containerId);
    Collection<TimerPrimaryKey> deadKeys = new HashSet<>();
    if (containerKeys != null) {
        for (TimerPrimaryKey containerKey : containerKeys) {
            HZTimer timer = (HZTimer) pkCache.get(containerKey.timerId);
            if (timer != null && timer.getMemberName().equals(this.serverName)) {
                activeTimers.add(timer);
            } else if (timer == null) {
                deadKeys.add(containerKey);
            }
        }
        if (!deadKeys.isEmpty()) {
            // clean out dead keys
            logger.info("Cleaning out " + deadKeys.size() + " dead timer ids from Container Cache ");
            for (TimerPrimaryKey deadKey : deadKeys) {
                containerKeys.remove(deadKey);
            }
            containerCache.put(containerId, containerKeys);
        }
    } else if (containerKeys == null && deploy == false) {
        // we are in trouble as we are not deploying but our keys are null
        // looks like we lost the whole cluster storage
        // recreate timers
        logger.log(Level.INFO, "Looks like we lost the data grid storage will recreate timers");
        lostCluster = true;
    }
    Set<HZTimer> timers = _restoreTimers(activeTimers);
    if (timers.size() > 0) {
        logger.log(Level.FINE, "Found " + timers.size() + " persistent timers for containerId: " + containerId);
    }
    boolean schedulesExist = (schedules.size() > 0);
    for (HZTimer timer : timers) {
        EJBTimerSchedule ts = timer.getSchedule();
        if (ts != null && ts.isAutomatic() && schedulesExist) {
            Iterator<Map.Entry<Method, List<ScheduledTimerDescriptor>>> schedulesIterator = schedules.entrySet().iterator();
            while (schedulesIterator.hasNext()) {
                Map.Entry<Method, List<ScheduledTimerDescriptor>> entry = schedulesIterator.next();
                Method m = entry.getKey();
                if (m.getName().equals(ts.getTimerMethodName()) && m.getParameterTypes().length == ts.getMethodParamCount()) {
                    result.put(new TimerPrimaryKey(timer.getKey().getTimerId()), m);
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE, "@@@ FOUND existing schedule: " + ts.getScheduleAsString() + " FOR method: " + m);
                    }
                    schedulesIterator.remove();
                }
            }
        }
    }
    try {
        if (!schedules.isEmpty()) {
            createSchedules(containerId, applicationId, schedules, result, serverName, true, (deploy && isDas) || lostCluster);
        }
    } catch (Exception ex) {
        Logger.getLogger(HazelcastTimerStore.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}
Also used : TimerPrimaryKey(com.sun.ejb.containers.TimerPrimaryKey) HashMap(java.util.HashMap) EJBTimerSchedule(com.sun.ejb.containers.EJBTimerSchedule) ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) Method(java.lang.reflect.Method) FinderException(javax.ejb.FinderException) EJBException(javax.ejb.EJBException) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) HashSet(java.util.HashSet)

Example 8 with ScheduledTimerDescriptor

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

the class BeanMethodCalculatorImpl method getTransactionalMethodsFor.

/**
 * @return a collection of MethodDescriptor for all the methods of my
 * ejb which are elligible to have a particular transaction setting.
 */
public Collection getTransactionalMethodsFor(com.sun.enterprise.deployment.EjbDescriptor desc, ClassLoader loader) throws ClassNotFoundException, NoSuchMethodException {
    EjbDescriptor ejbDescriptor = (EjbDescriptor) desc;
    // only set if desc is a stateful session bean.  NOTE that
    // !statefulSessionBean does not imply stateless session bean
    boolean statefulSessionBean = false;
    Vector methods = new Vector();
    if (ejbDescriptor instanceof EjbSessionDescriptor) {
        statefulSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isStateful();
        boolean singletonSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isSingleton();
        // Session Beans
        if (ejbDescriptor.isRemoteInterfacesSupported()) {
            Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBObject.class, sessionBeanMethodsDisallowed);
            Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getRemoteClassName(), disallowedMethods);
            transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
        }
        if (ejbDescriptor.isRemoteBusinessInterfacesSupported()) {
            for (String intfName : ejbDescriptor.getRemoteBusinessClassNames()) {
                Class businessIntf = loader.loadClass(intfName);
                Method[] busIntfMethods = businessIntf.getMethods();
                for (Method next : busIntfMethods) {
                    methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_REMOTE));
                }
            }
        }
        if (ejbDescriptor.isLocalInterfacesSupported()) {
            Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBLocalObject.class, sessionLocalBeanMethodsDisallowed);
            Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getLocalClassName(), disallowedMethods);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
        }
        if (ejbDescriptor.isLocalBusinessInterfacesSupported()) {
            for (String intfName : ejbDescriptor.getLocalBusinessClassNames()) {
                Class businessIntf = loader.loadClass(intfName);
                Method[] busIntfMethods = businessIntf.getMethods();
                for (Method next : busIntfMethods) {
                    methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
                }
            }
        }
        if (ejbDescriptor.isLocalBean()) {
            String intfName = ejbDescriptor.getEjbClassName();
            Class businessIntf = loader.loadClass(intfName);
            Method[] busIntfMethods = businessIntf.getMethods();
            for (Method next : busIntfMethods) {
                methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
            }
        }
        if (ejbDescriptor.hasWebServiceEndpointInterface()) {
            Class webServiceClass = loader.loadClass(ejbDescriptor.getWebServiceEndpointInterfaceName());
            Method[] webMethods = webServiceClass.getMethods();
            for (int i = 0; i < webMethods.length; i++) {
                methods.add(new MethodDescriptor(webMethods[i], MethodDescriptor.EJB_WEB_SERVICE));
            }
        }
        // SFSB and Singleton can have lifecycle callbacks transactional
        if (statefulSessionBean || singletonSessionBean) {
            Set<LifecycleCallbackDescriptor> lcds = ejbDescriptor.getLifecycleCallbackDescriptors();
            for (LifecycleCallbackDescriptor lcd : lcds) {
                try {
                    Method m = lcd.getLifecycleCallbackMethodObject(loader);
                    MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                    methods.add(md);
                } catch (Exception e) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Lifecycle callback processing error", e);
                    }
                }
            }
        }
    } else {
        // entity beans local interfaces
        String homeIntf = ejbDescriptor.getHomeClassName();
        if (homeIntf != null) {
            Class home = loader.loadClass(homeIntf);
            Collection potentials = getTransactionMethodsFor(javax.ejb.EJBHome.class, home);
            transformAndAdd(potentials, MethodDescriptor.EJB_HOME, methods);
            String remoteIntf = ejbDescriptor.getRemoteClassName();
            Class remote = loader.loadClass(remoteIntf);
            potentials = getTransactionMethodsFor(javax.ejb.EJBObject.class, remote);
            transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
        }
        // enity beans remote interfaces
        String localHomeIntf = ejbDescriptor.getLocalHomeClassName();
        if (localHomeIntf != null) {
            Class home = loader.loadClass(localHomeIntf);
            Collection potentials = getTransactionMethodsFor(javax.ejb.EJBLocalHome.class, home);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCALHOME, methods);
            String remoteIntf = ejbDescriptor.getLocalClassName();
            Class remote = loader.loadClass(remoteIntf);
            potentials = getTransactionMethodsFor(javax.ejb.EJBLocalObject.class, remote);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
        }
    }
    if (!statefulSessionBean) {
        if (ejbDescriptor.isTimedObject()) {
            if (ejbDescriptor.getEjbTimeoutMethod() != null) {
                methods.add(ejbDescriptor.getEjbTimeoutMethod());
            }
            for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
                methods.add(schd.getTimeoutMethod());
            }
        }
    }
    return methods;
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) Collection(java.util.Collection) Vector(java.util.Vector) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 9 with ScheduledTimerDescriptor

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

the class EJBTimerService method createSchedules.

/**
 * Create automatic timers defined by the @Schedule annotation on the EJB bean.
 *
 * XXX???
 * If this method is called on a deploy in a clustered deployment, only persistent schedule
 * based timers will be created. And no timers will be scheduled.
 * If it is called from deploy on a non-clustered instance, both
 * persistent and non-persistent timers will be created.
 * Otherwise only non-persistent timers are created by this method.
 */
protected void createSchedules(long containerId, long applicationId, Map<?, List<ScheduledTimerDescriptor>> schedules, Map<TimerPrimaryKey, Method> result, String server_name, boolean startTimers, boolean deploy) throws Exception {
    for (Map.Entry<?, List<ScheduledTimerDescriptor>> entry : schedules.entrySet()) {
        Object key = entry.getKey();
        String mname = null;
        int args_length = 0;
        if (key instanceof Method) {
            mname = ((Method) key).getName();
            args_length = ((Method) key).getParameterTypes().length;
        } else {
            mname = ((MethodDescriptor) key).getName();
            args_length = ((MethodDescriptor) key).getJavaParameterClassNames().length;
        }
        for (ScheduledTimerDescriptor sch : entry.getValue()) {
            boolean persistent = sch.getPersistent();
            if ((persistent && !deploy) || (!persistent && !startTimers)) {
                // non-persistent timers on a clustered deploy
                continue;
            }
            EJBTimerSchedule ts = new EJBTimerSchedule(sch, mname, args_length);
            TimerConfig tc = new TimerConfig();
            String info = sch.getInfo();
            if (info != null && !info.equals("")) {
                tc.setInfo(info);
            }
            tc.setPersistent(persistent);
            TimerPrimaryKey tpk = createTimer(containerId, applicationId, ts, tc, server_name);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "@@@ CREATED new schedule: " + ts.getScheduleAsString() + " FOR method: " + key);
            }
            if (startTimers && result != null) {
                result.put(tpk, (Method) key);
            }
        }
    }
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) TimerConfig(javax.ejb.TimerConfig) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)9 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)7 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)3 Collection (java.util.Collection)2 Map (java.util.Map)2 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)2 Node (org.w3c.dom.Node)2 IMap (com.hazelcast.core.IMap)1 EJBTimerSchedule (com.sun.ejb.containers.EJBTimerSchedule)1 TimerPrimaryKey (com.sun.ejb.containers.TimerPrimaryKey)1 InjectionCapable (com.sun.enterprise.deployment.InjectionCapable)1 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)1 DataSourceDefinitionNode (com.sun.enterprise.deployment.node.DataSourceDefinitionNode)1