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());
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations