List of usage examples for javax.ejb Timer cancel
public void cancel() throws java.lang.IllegalStateException, javax.ejb.NoSuchObjectLocalException, javax.ejb.EJBException;
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
@Override @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void reloadCaCertificateCacheAndSetTimeout() { if (log.isTraceEnabled()) { log.trace(">timeOutReloadCaCertificateCache"); }//ww w . j av a2 s .c om // Cancel any waiting timers of this type @SuppressWarnings("unchecked") final Collection<Timer> timers = timerService.getTimers(); for (final Timer timer : timers) { if (timer.getInfo() instanceof Integer) { final int currentTimerId = ((Integer) timer.getInfo()).intValue(); if (currentTimerId == TIMERID_CACERTIFICATECACHE) { timer.cancel(); } } } try { certificateStoreSession.reloadCaCertificateCache(); } finally { // Schedule a new timer of this type final long interval = OcspConfiguration.getSigningCertsValidTimeInMilliseconds(); if (interval > 0) { timerService.createTimer(interval, Integer.valueOf(TIMERID_CACERTIFICATECACHE)); } } }
From source file:org.cesecore.certificates.ocsp.OcspResponseGeneratorSessionBean.java
/** * This method cancels all timers associated with this bean. *//*w ww.j a v a2s .co m*/ // We don't want the appserver to persist/update the timer in the same transaction if they are stored in different non XA DataSources. This method // should not be run from within a transaction. private void cancelTimers(final int id) { if (log.isTraceEnabled()) { log.trace(">cancelTimers"); } @SuppressWarnings("unchecked") final Collection<Timer> timers = timerService.getTimers(); for (final Timer timer : timers) { final int currentTimerId = ((Integer) timer.getInfo()).intValue(); if (currentTimerId == id) { timer.cancel(); } } if (log.isTraceEnabled()) { log.trace("<cancelTimers, timers canceled: " + timers.size()); } }
From source file:org.ejbca.core.ejb.ocsp.OcspKeyRenewalSessionBean.java
/** * This method cancels all timers associated with this bean. *//*from w w w .java 2s . c o m*/ private void cancelTimers() { Collection<Timer> timers = timerService.getTimers(); for (Timer timer : timers) { try { timer.cancel(); } catch (NoSuchObjectLocalException e) { if (log.isDebugEnabled()) { log.debug("Timer was already expired or canceled: " + timer.getInfo()); } } } }
From source file:org.ejbca.core.ejb.services.ServiceSessionBean.java
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @Override//from www . j a v a 2 s. c o m public void unload() { log.debug("Unloading all timers."); // Get all services for (Timer timer : (Collection<Timer>) timerService.getTimers()) { try { timer.cancel(); } catch (Exception e) { /* * EJB 2.1 only?: We need to catch this because Weblogic 10 * throws an exception if we have not scheduled this timer, so * we don't have anything to cancel. Only weblogic though... */ log.info("Caught exception canceling timer: " + e.getMessage()); } } }
From source file:org.ejbca.core.ejb.services.ServiceSessionBean.java
/** * Cancels all existing timeouts for this id. * /* w w w .ja v a 2 s . c o m*/ * @param id the id of the timer */ // We don't want the appserver to persist/update the timer in the same transaction if they are stored in different non XA DataSources. This method // should not be run from within a transaction. @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) @Override public void cancelTimer(Integer id) { if (log.isDebugEnabled()) { log.debug("cancelTimer: " + id); } for (Timer next : (Collection<Timer>) timerService.getTimers()) { try { if (id.equals(next.getInfo())) { next.cancel(); break; } } catch (Exception e) { /* * EJB 2.1 only?: We need to catch this because Weblogic 10 * throws an exception if we have not scheduled this timer, so * we don't have anything to cancel. Only weblogic though... */ log.error("Caught exception canceling timer: " + e.getMessage(), e); } } }
From source file:org.meveo.service.job.JobInstanceService.java
public void remove(JobInstance entity) {// FIXME: throws BusinessException{ log.info("remove jobInstance {}, id={}", entity.getJobTemplate(), entity.getId()); if (entity.getId() == null) { log.info("removing jobInstance entity with null id, something is wrong"); } else if (jobTimers.containsKey(entity.getId())) { try {/*from w w w . j av a 2s . c om*/ Timer timer = jobTimers.get(entity.getId()); timer.cancel(); } catch (Exception ex) { log.info("cannot cancel timer " + ex); } jobTimers.remove(entity.getId()); } else { log.info("jobInstance timer not found, cannot remove it"); } super.remove(entity); }
From source file:org.meveo.service.job.JobInstanceService.java
private void scheduleUnscheduleJob(JobInstance jobInstance) { try {/* ww w. ja v a2 s. c o m*/ if (!jobEntries.containsKey(jobInstance.getJobCategoryEnum())) { log.error("Not registered job category {} for jobInstance {}", jobInstance.getJobCategoryEnum(), jobInstance.getCode()); throw new RuntimeException("Not registered job category " + jobInstance.getJobCategoryEnum()); } HashMap<String, String> jobs = jobEntries.get(jobInstance.getJobCategoryEnum()); if (!jobs.containsKey(jobInstance.getJobTemplate())) { log.error("cannot find job {} for jobInstance {}", jobInstance.getJobTemplate(), jobInstance.getCode()); throw new RuntimeException("cannot find job " + jobInstance.getJobTemplate()); } if (jobTimers.containsKey(jobInstance.getId())) { try { Timer timer = jobTimers.get(jobInstance.getId()); timer.cancel(); jobTimers.remove(jobInstance.getId()); log.info("Cancelled timer {}, id={}", jobInstance.getJobTemplate(), jobInstance.getId()); } catch (Exception ex) { log.error("Failed to cancel timer {}, id={}", jobInstance.getJobTemplate(), jobInstance.getId(), ex); } } if (jobInstance.isActive() && jobInstance.getTimerEntity() != null) { InitialContext ic = new InitialContext(); Job job = (Job) ic.lookup(jobs.get(jobInstance.getJobTemplate())); log.info("Scheduling job {} : timer {}", job, jobInstance.getId()); jobTimers.put(jobInstance.getId(), job.createTimer(jobInstance.getTimerEntity().getScheduleExpression(), jobInstance)); } else { log.debug("Job {} is inactive or has no timer and will not be scheduled", jobInstance.getCode()); } } catch (NamingException e) { log.error("Failed to schedule job", e); } }
From source file:org.rhq.enterprise.server.cloud.instance.CacheConsistencyManagerBean.java
@SuppressWarnings("unchecked") public void scheduleServerCacheReloader() { /* each time the webapp is reloaded, it would create * duplicate events if we don't cancel the existing ones */// w ww . j a va2 s. c om Collection<Timer> timers = timerService.getTimers(); for (Timer existingTimer : timers) { log.debug("Found timer - attempting to cancel: " + existingTimer.toString()); try { existingTimer.cancel(); } catch (Exception e) { log.warn("Failed in attempting to cancel timer: " + existingTimer.toString()); } } // single-action timer that will trigger in 30 seconds timerService.createTimer(30000, TIMER_DATA); }
From source file:org.rhq.enterprise.server.cloud.instance.ServerManagerBean.java
@SuppressWarnings("unchecked") public void scheduleServerHeartbeat() { /* each time the webapp is reloaded, it would create * duplicate events if we don't cancel the existing ones *//*from w ww.j a va 2 s .c o m*/ Collection<Timer> timers = timerService.getTimers(); for (Timer existingTimer : timers) { log.debug("Found timer - attempting to cancel: " + existingTimer.toString()); try { existingTimer.cancel(); } catch (Exception e) { log.warn("Failed in attempting to cancel timer: " + existingTimer.toString()); } } // single-action timer that will trigger in 30 seconds timerService.createTimer(30000, TIMER_DATA); }
From source file:org.rhq.enterprise.server.storage.StorageClientManager.java
public void scheduleStorageSessionMaintenance() { // each time the webapp is reloaded, we don't want to create duplicate jobs Collection<Timer> timers = timerService.getTimers(); for (Timer existingTimer : timers) { if (LOG.isDebugEnabled()) { LOG.debug("Found timer - attempting to cancel: " + existingTimer.toString()); }/*from ww w. j a v a 2s . co m*/ try { existingTimer.cancel(); } catch (Exception e) { LOG.warn("Failed in attempting to cancel timer: " + existingTimer.toString()); } } // timer that will trigger every 90 seconds after an initial wait of 30 seconds timerService.createIntervalTimer(30000L, 90000L, new TimerConfig(null, false)); }