List of usage examples for javax.ejb Timer getInfo
public Serializable getInfo() throws java.lang.IllegalStateException, javax.ejb.NoSuchObjectLocalException, javax.ejb.EJBException;
From source file:com.hiperium.bo.control.impl.TaskBOImpl.java
/** * /*w w w. j ava 2 s . co m*/ * @param taskId * @return */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) private Timer findTimer(Long taskId) { this.log.debug("findTimer - START"); Timer timer = null; Collection<Timer> timers = this.timerService.getTimers(); if (timers != null) { for (Iterator<Timer> iterator = timers.iterator(); iterator.hasNext();) { Timer t = iterator.next(); try { if (taskId.equals((Long) t.getInfo())) { timer = t; } } catch (Exception e) { this.log.debug("ERROR: " + e.getMessage()); } } } this.log.debug("findTimer - END"); return timer; }
From source file:edu.harvard.iq.dataverse.harvest.client.HarvesterServiceBean.java
public List<HarvestTimerInfo> getHarvestTimers() { ArrayList<HarvestTimerInfo> timers = new ArrayList<>(); for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) { Timer timer = (Timer) it.next(); if (timer.getInfo() instanceof HarvestTimerInfo) { HarvestTimerInfo info = (HarvestTimerInfo) timer.getInfo(); timers.add(info);//from w w w. jav a 2 s .c om } } return timers; }
From source file:io.hops.hopsworks.dela.DelaSetupWorker.java
@Timeout @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) private void timeout(Timer timer) { LOGGER.log(Level.INFO, "{0} - state:{1} timeout:{2}", new Object[] { DelaException.Source.HOPS_SITE, state, timer.getInfo().toString() }); switch (state) { case SETUP://from w w w . j a v a2 s .co m setup(timer); break; case DELA_VERSION: delaVersion(timer); break; case DELA_CONTACT: delaContact(timer); break; case REGISTER: hopsSiteRegister(timer); break; case HEAVY_PING: heavyPing(timer); break; case PING: ping(timer); break; default: throw new IllegalStateException("unknown state"); } }
From source file:edu.harvard.iq.dvn.core.harvest.HarvesterServiceBean.java
public List<HarvestTimerInfo> getHarvestTimers() { ArrayList timers = new ArrayList<HarvestTimerInfo>(); // Clear dataverse timer, if one exists for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) { Timer timer = (Timer) it.next(); if (timer.getInfo() instanceof HarvestTimerInfo) { HarvestTimerInfo info = (HarvestTimerInfo) timer.getInfo(); timers.add(info);// w ww .j a v a 2 s .c o m } } return timers; }
From source file:edu.harvard.iq.dvn.core.harvest.HarvesterServiceBean.java
/** * This method is called whenever an EJB Timer goes off. * Check to see if this is a Harvest Timer, and if it is * Run the harvest for the given (scheduled) dataverse * @param timer//from w w w .j a v a 2 s .com */ @Timeout @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void handleTimeout(javax.ejb.Timer timer) { // We have to put all the code in a try/catch block because // if an exception is thrown from this method, Glassfish will automatically // call the method a second time. (The minimum number of re-tries for a Timer method is 1) if (timer.getInfo() instanceof HarvestTimerInfo) { HarvestTimerInfo info = (HarvestTimerInfo) timer.getInfo(); try { // First, check if we are in read-only mode: if (vdcNetworkService.defaultTransactionReadOnly()) { logger.log(Level.ALL, "Network is in read-only mode."); return; } // Proceeding with the scheduled harvest: logger.log(Level.INFO, "DO HARVESTING of dataverse " + info.getHarvestingDataverseId()); doHarvesting(info.getHarvestingDataverseId()); } catch (Throwable e) { harvestingDataverseService.setHarvestResult(info.getHarvestingDataverseId(), HarvestingDataverse.HARVEST_RESULT_FAILED); mailService.sendHarvestErrorNotification(vdcNetworkService.find().getSystemEmail(), vdcNetworkService.find().getName()); logException(e, logger); } } }
From source file:edu.harvard.iq.dvn.core.index.IndexServiceBean.java
public void createIndexTimer() { for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) { Timer timer = (Timer) it.next(); if (timer.getInfo().equals(INDEX_TIMER)) { logger.info("Cannot create IndexTimer, timer already exists."); logger.info("IndexTimer next timeout is " + timer.getNextTimeout()); return; }/* www . j a va 2s . co m*/ } Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 1); logger.log(Level.INFO, "Indexer timer set for " + cal.getTime()); Date initialExpiration = cal.getTime(); // First timeout is 1:00 AM of next day long intervalDuration = 1000 * 60 * 60 * 24; // repeat every 24 hours timerService.createTimer(initialExpiration, intervalDuration, INDEX_TIMER); }
From source file:edu.harvard.iq.dvn.core.index.IndexServiceBean.java
public void createIndexNotificationTimer() { for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) { Timer timer = (Timer) it.next(); if (timer.getInfo().equals(INDEX_NOTIFICATION_TIMER)) { logger.info("Cannot create IndexNotificationTimer, timer already exists."); logger.info("IndexNotificationTimer next timeout is " + timer.getNextTimeout()); return; }//from ww w . j a v a2 s . com } Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 15); logger.log(Level.INFO, "Indexer notification timer set for " + cal.getTime()); Date initialExpiration = cal.getTime(); // First timeout is 1:00 AM of next day long intervalDuration = 1000 * 60 * 60 * 24; // repeat every 24 hours timerService.createTimer(initialExpiration, intervalDuration, INDEX_NOTIFICATION_TIMER); }
From source file:edu.harvard.iq.dvn.core.index.IndexServiceBean.java
public void createCollectionIndexTimer() { for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) { Timer timer = (Timer) it.next(); if (timer.getInfo().equals(COLLECTION_INDEX_TIMER)) { logger.info("Cannot create COllectionIndexTimer, timer already exists."); logger.info("IndexTimer next timeout is " + timer.getNextTimeout()); return; }//from ww w . j ava2 s. co m } Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, 5); // First run 5 minutes from now Date initialRun = cal.getTime(); long intervalInMinutes = 60; // default value String intervalJVMOption = System.getProperty("dvn.index.collection.reindex.interval"); if (intervalJVMOption != null) { Long intervalValue = null; try { intervalValue = new Long(intervalJVMOption); } catch (Exception ex) { } if (intervalValue != null && (intervalValue.longValue() > 0L)) { intervalInMinutes = intervalValue.longValue(); } } long intervalDuration = 1000 * 60 * intervalInMinutes; timerService.createTimer(initialRun, intervalDuration, COLLECTION_INDEX_TIMER); logger.log(Level.INFO, "Collection index timer set for " + initialRun); }
From source file:edu.harvard.iq.dvn.core.index.IndexServiceBean.java
@Timeout @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void handleTimeout(javax.ejb.Timer timer) { System.out.println("in handleTimeout, timer = " + timer.getInfo()); try {/* w w w. jav a 2s . co m*/ // read-only mode check: boolean readOnly = vdcNetworkService.defaultTransactionReadOnly(); if (timer.getInfo().equals(INDEX_TIMER)) { if (readOnly) { logger.log(Level.ALL, "Network is in read-only mode; skipping scheduled index job."); } else { logger.log(Level.INFO, "Index update"); indexBatch(); } } else if (timer.getInfo().equals(INDEX_NOTIFICATION_TIMER)) { if (readOnly) { logger.log(Level.ALL, "Network is in read-only mode; skipping scheduled index notification."); } else { logger.log(Level.INFO, "Index notify"); indexProblemNotify(); } } else if (timer.getInfo().equals(COLLECTION_INDEX_TIMER)) { if (readOnly) { logger.log(Level.ALL, "Network is in read-only mode; skipping scheduled collection reindexing."); } else { logger.log(Level.INFO, "Collection ReIndex"); updateStudiesInCollections(); } } } catch (Throwable e) { mailService.sendIndexUpdateErrorNotification(vdcNetworkService.find().getSystemEmail(), vdcNetworkService.find().getName()); e.printStackTrace(); } }
From source file:org.cesecore.certificates.certificate.CertificateStoreSessionBean.java
License:asdf
/** * When a timer expires, this method will update * // w w w. j av a 2 s . com * According to JSR 220 FR (18.2.2), this method may not throw any exceptions. * * @param timer The timer whose expiration caused this notification. */ @Timeout /* Glassfish 2.1.1: * "Timeout method ....timeoutHandler(javax.ejb.Timer)must have TX attribute of TX_REQUIRES_NEW or TX_REQUIRED or TX_NOT_SUPPORTED" * JBoss 5.1.0.GA: We cannot mix timer updates with our EJBCA DataSource transactions. */ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void timeoutHandler(Timer timer) { if (log.isTraceEnabled()) { log.trace(">timeoutHandler: " + timer.getInfo().toString()); } if (timer.getInfo() instanceof Integer) { final int currentTimerId = ((Integer) timer.getInfo()).intValue(); if (currentTimerId == TIMERID_CACERTIFICATECACHE) { reloadCaCertificateCacheAndSetTimeout(); } } if (log.isTraceEnabled()) { log.trace("<timeoutHandler"); } }