Example usage for com.liferay.portal.kernel.scheduler SchedulerEntryImpl SchedulerEntryImpl

List of usage examples for com.liferay.portal.kernel.scheduler SchedulerEntryImpl SchedulerEntryImpl

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.scheduler SchedulerEntryImpl SchedulerEntryImpl.

Prototype

SchedulerEntryImpl

Source Link

Usage

From source file:de.uhh.l2g.plugins.util.PortletScheduler.java

License:Open Source License

/**
 * Assembles (adds and schedules) an missing SchedulerEntry
 * //w  ww  . j a  v  a 2 s .co  m
 * @return SchedulerEntry
 */
public SchedulerEntry assembleEntryFromSettings(String portletId, TriggerState state) {
    Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
    SchedulerEntry entry = new SchedulerEntryImpl();
    String cron = "";
    try {
        cron = GetterUtil
                .getString(ScheduledThreadLocalServiceUtil.getCronBySchedulerName(this.schedulerClassName));
        // TODO: Persist Description String description;
        this.generalTrigger = new CronTrigger(this.schedulerClassName, this.schedulerClassName, cron);
        LOG.info("Building Trigger: " + cron);
        entry.setDescription(this.schedulerClassName);
        entry.setEventListenerClass(this.schedulerClassName);
        entry.setTriggerType(TriggerType.CRON);
        entry.setTriggerValue(cron);

        this.schedulerEntry = entry;

    } catch (Exception e) {
        LOG.error("Scheduler CronText was lost. Requires server restart to recover.");
    }
    // Add and schedule if it is supposed to be running
    if (state != TriggerState.UNSCHEDULED) {
        portlet.getSchedulerEntries().add(entry);
        // , description=This scheduler is used to collect Statistical Data
        // from Database,
        // eventListenerClass=de.uhh.l2g.plugins.util.StatisticsScheduler,
        // propertyKey=, timeUnit=null, trigger={cronText=0 */1 * * * ?,
        // {endDate=null,
        // groupName=de.uhh.l2g.plugins.util.StatisticsScheduler,
        // jobName=de.uhh.l2g.plugins.util.StatisticsScheduler,
        // startDate=null, triggerType=CRON}}, triggerType=CRON,
        // triggerValue=0 */1 * * * ?}
        try {
            SchedulerEngineHelperUtil.schedule(entry, this.STOR, portletId, 0);
        } catch (SchedulerException e) {
            LOG.error("Failed adding Scheduler!");
        }
    }
    return this.schedulerEntry;

}