Search in sources :

Example 96 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.

the class AbstractEjbHandler method doTimedObjectProcessing.

/**
 * Process TimedObject and @Timeout annotation.  It's better to do it
 * when processing the initial bean type since Timeout method is a
 * business method that should be included in any tx processing defaulting
 * that takes place.
 */
private void doTimedObjectProcessing(Class ejbClass, EjbDescriptor ejbDesc) {
    // Timeout methods can be declared on the bean class or any
    // super-class and can be public, protected, private, or
    // package access.  There can be at most one timeout method for
    // the entire bean class hierarchy, so we start from the bean
    // class and go up, stopping when we find the first one.
    MethodDescriptor timeoutMethodDesc = null;
    Class nextClass = ejbClass;
    while ((nextClass != Object.class) && (nextClass != null) && (timeoutMethodDesc == null)) {
        Method[] methods = nextClass.getDeclaredMethods();
        for (Method m : methods) {
            if ((m.getAnnotation(Timeout.class) != null)) {
                timeoutMethodDesc = new MethodDescriptor(m, MethodDescriptor.TIMER_METHOD);
                break;
            }
        }
        nextClass = nextClass.getSuperclass();
    }
    if ((timeoutMethodDesc == null) && javax.ejb.TimedObject.class.isAssignableFrom(ejbClass)) {
        // If the class implements the TimedObject interface, it must
        // be ejbTimeout.
        timeoutMethodDesc = new MethodDescriptor("ejbTimeout", "@Timeout method", new String[] { "javax.ejb.Timer" }, MethodDescriptor.TIMER_METHOD);
    }
    if (timeoutMethodDesc != null) {
        ejbDesc.setEjbTimeoutMethod(timeoutMethodDesc);
    }
    return;
}
Also used : Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 97 with MethodDescriptor

use of com.sun.enterprise.deployment.MethodDescriptor 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

MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)97 Method (java.lang.reflect.Method)37 Iterator (java.util.Iterator)25 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)23 Set (java.util.Set)18 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)17 Enumeration (java.util.Enumeration)16 ArrayList (java.util.ArrayList)12 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)11 MethodPermission (com.sun.enterprise.deployment.MethodPermission)10 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)10 Result (com.sun.enterprise.tools.verifier.Result)9 HashSet (java.util.HashSet)9 Vector (java.util.Vector)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)7 MethodNode (com.sun.enterprise.deployment.node.MethodNode)6 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 ScheduledTimerDescriptor (org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor)6