Search in sources :

Example 1 with Timeout

use of javax.ejb.Timeout in project dataverse by IQSS.

the class DataverseTimerServiceBean method handleTimeout.

/**
 * 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
 */
@Timeout
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void handleTimeout(javax.ejb.Timer timer) {
    if (!systemConfig.isTimerServer()) {
        // logger.info("I am not the timer server! - bailing out of handleTimeout()");
        Logger.getLogger(DataverseTimerServiceBean.class.getName()).log(Level.WARNING, null, "I am not the timer server! - but handleTimeout() got called. Please investigate!");
    }
    try {
        logger.log(Level.INFO, "Handling timeout on " + InetAddress.getLocalHost().getCanonicalHostName());
    } catch (UnknownHostException ex) {
        Logger.getLogger(DataverseTimerServiceBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (timer.getInfo() instanceof MotherTimerInfo) {
        logger.info("Behold! I am the Master Timer, king of all timers! I'm here to create all the lesser timers!");
        removeHarvestTimers();
        for (HarvestingClient client : harvestingClientService.getAllHarvestingClients()) {
            createHarvestTimer(client);
        }
    } else if (timer.getInfo() instanceof HarvestTimerInfo) {
        HarvestTimerInfo info = (HarvestTimerInfo) timer.getInfo();
        try {
            logger.log(Level.INFO, "running a harvesting client: id=" + info.getHarvestingClientId());
            // Timer batch jobs are run by the main Admin user.
            // TODO: revisit how we retrieve the superuser here.
            // Should it be configurable somewhere, which superuser
            // runs these jobs? Should there be a central mechanism for obtaining
            // the "major", builtin superuser for this Dataverse instance?
            // -- L.A. 4.5, Aug. 2016
            // getAuthenticatedUser("admin");
            AuthenticatedUser adminUser = authSvc.getAdminUser();
            if (adminUser == null) {
                logger.info("Scheduled harvest: failed to locate the admin user! Exiting.");
                throw new IOException("Scheduled harvest: failed to locate the admin user");
            }
            logger.info("found admin user " + adminUser.getName());
            DataverseRequest dataverseRequest = new DataverseRequest(adminUser, (HttpServletRequest) null);
            harvesterService.doHarvest(dataverseRequest, info.getHarvestingClientId());
        } catch (Throwable e) {
            // Harvester Service should be handling any error notifications,
            // if/when things go wrong.
            // (TODO: -- verify this logic; harvesterService may still be able
            // to throw an IOException, if it could not run the harvest at all,
            // or could not for whatever reason modify the database record...
            // in this case we should, probably, log the error and try to send
            // a mail notification. -- L.A. 4.4)
            // dataverseService.setHarvestResult(info.getHarvestingDataverseId(), harvesterService.HARVEST_RESULT_FAILED);
            // mailService.sendHarvestErrorNotification(dataverseService.find().getSystemEmail(), dataverseService.find().getName());
            logException(e, logger);
        }
    } else if (timer.getInfo() instanceof ExportTimerInfo) {
        try {
            ExportTimerInfo info = (ExportTimerInfo) timer.getInfo();
            logger.info("Timer Service: Running a scheduled export job.");
            // try to export all unexported datasets:
            datasetService.exportAll();
            // and update all oai sets:
            oaiSetService.exportAllSets();
        } catch (Throwable e) {
            logException(e, logger);
        }
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient) HarvestTimerInfo(edu.harvard.iq.dataverse.harvest.client.HarvestTimerInfo) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) TransactionAttribute(javax.ejb.TransactionAttribute) Timeout(javax.ejb.Timeout)

Example 2 with Timeout

use of javax.ejb.Timeout in project jbpm by kiegroup.

the class EJBTimerScheduler method executeTimerJob.

@SuppressWarnings("unchecked")
@Timeout
public void executeTimerJob(Timer timer) {
    EjbTimerJob timerJob = (EjbTimerJob) timer.getInfo();
    logger.debug("About to execute timer for job {}", timerJob);
    TimerJobInstance timerJobInstance = timerJob.getTimerJobInstance();
    String timerServiceId = ((EjbGlobalJobHandle) timerJobInstance.getJobHandle()).getDeploymentId();
    // handle overdue timers as ejb timer service might start before all deployments are ready
    long time = 0;
    while (TimerServiceRegistry.getInstance().get(timerServiceId) == null) {
        logger.debug("waiting for timer service to be available, elapsed time {} ms", time);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        time += 500;
        if (time > OVERDUE_WAIT_TIME) {
            logger.debug("No timer service found after waiting {} ms", time);
            break;
        }
    }
    try {
        ((Callable<Void>) timerJobInstance).call();
    } catch (Exception e) {
        logger.warn("Execution of time failed due to {}", e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) Callable(java.util.concurrent.Callable) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) Timeout(javax.ejb.Timeout)

Example 3 with Timeout

use of javax.ejb.Timeout in project quickstart by wildfly.

the class TimeoutExample method scheduler.

@Timeout
public void scheduler(Timer timer) {
    Date currentTime = new Date();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
    System.out.println("TimeoutExample.scheduler() " + timer.getInfo() + simpleDateFormat.format(currentTime));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Timeout(javax.ejb.Timeout)

Example 4 with Timeout

use of javax.ejb.Timeout in project narayana by jbosstm.

the class QueueReaperBean method run.

@Timeout
public void run(Timer timer) {
    try {
        log.trace("QueueReaper Running: timer is " + timer.getInfo());
        ObjectName objName = new ObjectName("jboss.as:subsystem=messaging,hornetq-server=default,jms-queue=*");
        ObjectInstance[] dests = beanServerConnection.queryMBeans(objName, null).toArray(new ObjectInstance[] {});
        for (int i = 0; i < dests.length; i++) {
            String serviceComponentOfObjectName = dests[i].getObjectName().getCanonicalName();
            serviceComponentOfObjectName = serviceComponentOfObjectName.substring(serviceComponentOfObjectName.indexOf('_') + 1, serviceComponentOfObjectName.indexOf(",", serviceComponentOfObjectName.indexOf('_')));
            log.trace("Service name component of ObjectName is: " + serviceComponentOfObjectName);
            String server = (String) prop.get("blacktie." + serviceComponentOfObjectName + ".server");
            log.trace("Checking for: " + serviceComponentOfObjectName + " " + server + " " + prop.get("blacktie." + serviceComponentOfObjectName + ".externally-managed-destination"));
            if ((serviceComponentOfObjectName.startsWith(".") || ((server != null && !(Boolean) prop.get("blacktie." + serviceComponentOfObjectName + ".externally-managed-destination")))) && consumerCount(serviceComponentOfObjectName) == 0) {
                log.warn("undeploy service pending for " + serviceComponentOfObjectName + " as consumer count is 0, will check again in " + interval + "ms");
                long queueReapCheck = System.currentTimeMillis();
                Thread.sleep(this.interval);
                // double check consumer is 0
                if (BlacktieStompAdministrationService.isOlderThanReapCheck(serviceComponentOfObjectName, queueReapCheck) && consumerCount(serviceComponentOfObjectName) == 0) {
                    BlacktieStompAdministrationService.undeployQueue(serviceComponentOfObjectName);
                    log.warn("undeploy service " + serviceComponentOfObjectName + " for consumer is 0");
                } else {
                    log.debug("Undeploy not required for: " + serviceComponentOfObjectName + " at: " + server + " as client connected");
                }
            } else {
                log.debug("Undeploy not required for: " + serviceComponentOfObjectName + " at: " + server);
            }
        }
    } catch (NoSuchObjectLocalException e) {
        log.debug("The timer has expired or has been cancelled");
    } catch (InterruptedException e) {
        log.debug("Sleeping interrupted");
    } catch (Exception e) {
        log.error("run ping thread failed with (will wait for: " + interval + " ms): " + e, e);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) ObjectInstance(javax.management.ObjectInstance) AttributeNotFoundException(javax.management.AttributeNotFoundException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) Timeout(javax.ejb.Timeout)

Aggregations

Timeout (javax.ejb.Timeout)4 IOException (java.io.IOException)2 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 HarvestTimerInfo (edu.harvard.iq.dataverse.harvest.client.HarvestTimerInfo)1 HarvestingClient (edu.harvard.iq.dataverse.harvest.client.HarvestingClient)1 UnknownHostException (java.net.UnknownHostException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Callable (java.util.concurrent.Callable)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanException (javax.management.MBeanException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectInstance (javax.management.ObjectInstance)1 ObjectName (javax.management.ObjectName)1 ReflectionException (javax.management.ReflectionException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1