Example usage for javax.ejb TimerConfig TimerConfig

List of usage examples for javax.ejb TimerConfig TimerConfig

Introduction

In this page you can find the example usage for javax.ejb TimerConfig TimerConfig.

Prototype

public TimerConfig(Serializable info, boolean persistent) 

Source Link

Usage

From source file:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * {@inheritDoc}//  ww  w  . j  a va 2s.  c  o  m
 */
@Timeout
public void excecute(Timer timer) {
    Long taskId = (Long) timer.getInfo();
    this.log.debug("excecuteTask - START: task ID = " + taskId);
    try {
        Task task = super.getDaoFactory().getTaskDAO().findById(taskId, false, true);
        if (task != null && task.getActive()) {
            List<Device> deviceList = super.getDaoFactory().getDeviceDAO().findByTaskId(taskId);
            for (Device device : deviceList) {
                if (task.getAction().equals(EnumDeviceAction.ACTIVATE)
                        || task.getAction().equals(EnumDeviceAction.LOCK)) {
                    device.setActive(true);
                } else if (task.getAction().equals(EnumDeviceAction.DEACTIVATE)
                        || task.getAction().equals(EnumDeviceAction.UNLOCK)) {
                    device.setActive(false);
                }
                super.getDaoFactory().getDeviceDAO().update(device);

                // TODO: SEND TO THE HIPERIUM CLOUD
                //               DeviceGsonConverter jsonConverter = new DeviceGsonConverter();
                //               Long homeId = this.zoneRepositoryLocal.findHomeIdByZoneId(device.getZoneId(), 
                //                     EnumPlatformSessionID.INSTANCE.getSessionId());
            }

            //CREATE A NEW TIMER SERVICE FOR FREQUENCY MORE THAN DAILY
            if (EnumFrequency.WEEKLY.equals(task.getFrequency())
                    || EnumFrequency.MONTHLY.equals(task.getFrequency())
                    || EnumFrequency.QUARTERLY.equals(task.getFrequency())
                    || EnumFrequency.SEMIANNUAL.equals(task.getFrequency())
                    || EnumFrequency.ANNUAL.equals(task.getFrequency())) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                switch (task.getFrequency()) {
                case WEEKLY:
                    this.log.debug("excecuteTask - WEEKLY");
                    calendar.add(Calendar.DAY_OF_MONTH, 7);
                    break;
                case MONTHLY:
                    this.log.debug("excecuteTask - MONTHLY");
                    calendar.add(Calendar.MONTH, 1);
                    break;
                case QUARTERLY:
                    this.log.debug("excecuteTask - QUARTERLY");
                    calendar.add(Calendar.MONTH, 3);
                    break;
                case SEMIANNUAL:
                    this.log.debug("excecuteTask - SEMIANNUAL");
                    calendar.add(Calendar.MONTH, 6);
                    break;
                case ANNUAL:
                    this.log.debug("excecuteTask - ANNUAL");
                    calendar.add(Calendar.YEAR, 1);
                    break;
                default:
                    break;
                }
                // We recreate the task with the new manipulated date time.
                this.timerService.createSingleActionTimer(calendar.getTime(),
                        new TimerConfig(task.getId(), true));
            }
        }
    } catch (Exception e) {
        this.log.error("Error: " + e.getMessage());
    }
    timer.cancel();
    this.log.debug("excecuteTask - END");
}

From source file:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * //from  w ww. j a  v  a  2s .  c o m
 * @param task
 */
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
private void createSingleTimer(Task task) {
    this.log.debug("createSingleTimer - START");
    this.timerService.createSingleActionTimer(task.getExecutionDate(), new TimerConfig(task.getId(), true));
    this.log.debug("createSingleTimer - END");
}

From source file:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * /*w w w.  j ava  2 s  . c  om*/
 * @param task
 * @throws InformationException 
 */
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
private void createCalendarTimer(Task task) throws InformationException {
    this.log.debug("createCalendarTimer - START");
    ScheduleExpression expression = new ScheduleExpression();
    // TODO: Create CRON TASK based on task.getCronTask() parameter.
    this.timerService.createCalendarTimer(expression, new TimerConfig(task.getId(), true));
    this.log.debug("createCalendarTimer - END");
}

From source file:com.hiperium.bo.control.impl.TaskBOImpl.java

/**
 * /* w  ww . j ava 2 s.com*/
 * @param task
 */
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
private void createIntervalTimer(Task task) {
    this.log.debug("createIntervalTimer - START: " + task.getExecutionDate());
    Long interval = 0L;
    switch (task.getFrequency()) {
    case EVERY_MIMUTE:
        this.log.debug("createIntervalTimer - EVERY_MIMUTE");
        interval = 60000L;
        break;
    case QUARTER_HOUR:
        this.log.debug("createIntervalTimer - QUARTER_HOUR");
        interval = 900000L;
        break;
    case HALF_HOUR:
        this.log.debug("createIntervalTimer - HALF_HOUR");
        interval = 1800000L;
        break;
    case HOURLY:
        this.log.debug("createIntervalTimer - HOURLY");
        interval = 3600000L;
        break;
    case DAILY:
        this.log.debug("createIntervalTimer - DAILY");
        interval = 86400000L;
        break;
    default:
        break;
    }
    this.log.debug("Interval in milliseconds: " + interval);
    this.timerService.createIntervalTimer(task.getExecutionDate(), interval,
            new TimerConfig(task.getId(), true));
    this.log.debug("createIntervalTimer - END");
}

From source file:org.niord.core.batch.BatchSetService.java

/**
 * Starts executing a batch set by scheduling each batch job of the specification
 * @param batchSetSpec the batch set specification
 *//*from   w  ww  .j av  a  2  s  . c  o  m*/
private void executeBatchSet(BatchSetSpecification batchSetSpec, StringBuilder txt) {
    txt = txt != null ? txt : new StringBuilder();

    for (BatchSetVo batchSetItem : batchSetSpec.getBatchSetItems()) {

        BatchSetExecution execution = new BatchSetExecution(batchSetSpec, batchSetItem);
        long delay = batchSetItem.getDelay();

        txt.append("Scheduling batch job ").append(batchSetItem.getJobName()).append(" in ").append(delay)
                .append(" ms\n");

        timerService.createSingleActionTimer(delay, new TimerConfig(execution, false));
    }
}

From source file:org.rhq.enterprise.server.core.StartupBean.java

/**
 * Creates the timer that will trigger periodic scans for new plugins.
 * @throws RuntimeException/*from w  w w.  j ava  2s  . c  o m*/
 */
private void registerPluginDeploymentScannerJob() throws RuntimeException {
    log.info("Creating timer to begin scanning for plugins...");

    try {
        PluginDeploymentScannerMBean deployer = getPluginDeploymentScanner();

        long scanPeriod = 5 * 60000L;
        try {
            String scanPeriodString = deployer.getScanPeriod();
            scanPeriod = Long.parseLong(scanPeriodString);
        } catch (Exception e) {
            log.warn("could not determine plugin scanner scan period - using: " + scanPeriod, e);
        }

        // create a non-persistent periodic timer (we'll reset it ever startup) with the scan period as configured in our scanner object
        timerService.createIntervalTimer(scanPeriod, scanPeriod, new TimerConfig(null, false));
    } catch (Exception e) {
        error += (error.isEmpty() ? "" : ", ") + "plugin scanner";
        throw new RuntimeException("Cannot schedule plugin scanning timer - new plugins will not be detected!",
                e);
    }
}

From source file:org.rhq.enterprise.server.core.StartupBeanPreparation.java

@PostConstruct
public void initWithTransactionBecauseAS75530() throws RuntimeException {
    timerService.createSingleActionTimer(10000, new TimerConfig(null, false)); // call StartupBean in 10s
}

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  w  w w. ja v  a  2  s.  c o 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));
}

From source file:org.rhq.enterprise.server.test.StrippedDownStartupBeanPreparation.java

@PostConstruct
public void initWithTransactionBecauseAS75530() throws RuntimeException {
    log.info("Scheduling the initialization of the testing RHQ deployment");
    timerService.createSingleActionTimer(1, new TimerConfig(null, false)); // call StartupBean in 1ms

    startupBean.purgeTestServerAndStorageNodes();
    createTestServer();/*from ww  w. j a  v  a 2 s.  c om*/
    loadCassandraConnectionProps();
    createStorageNodes();
}

From source file:org.tomitribe.tribestream.registryng.service.monitoring.MonitoringService.java

@PostConstruct
private void boot() {
    startedAt = System.currentTimeMillis();

    if ("skip".equals(period)) {
        log.info("Monitoring is disabled");
        return;/*from   www. j a  v a2  s .  co m*/
    }

    periodMs = new Duration(period, TimeUnit.SECONDS).getTime(TimeUnit.MILLISECONDS);
    if (periodMs <= 0) {
        log.info("Monitoring is disabled");
        return;
    }

    monitor(null); // init state

    timer = timerService.createIntervalTimer(periodMs, periodMs,
            new TimerConfig("tribestream-api-registry-monitoring", false));
    log.info("Monitoring active each " + periodMs + "ms");
}