Example usage for com.liferay.portal.kernel.scheduler SchedulerEngineHelperUtil unschedule

List of usage examples for com.liferay.portal.kernel.scheduler SchedulerEngineHelperUtil unschedule

Introduction

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

Prototype

public static void unschedule(String jobName, String groupName, StorageType storageType)
            throws SchedulerException 

Source Link

Usage

From source file:com.liferay.alloy.mvc.AlloyPortlet.java

License:Open Source License

@Override
public void destroy() {
    for (BaseAlloyControllerImpl baseAlloyControllerImpl : _alloyControllers.values()) {

        Indexer indexer = baseAlloyControllerImpl.indexer;

        if (indexer != null) {
            IndexerRegistryUtil.unregister(indexer);
        }/*  www.j av  a  2 s  . c om*/

        MessageListener controllerMessageListener = baseAlloyControllerImpl.controllerMessageListener;

        if (controllerMessageListener != null) {
            MessageBusUtil.removeDestination(baseAlloyControllerImpl.getControllerDestinationName());
        }

        MessageListener schedulerMessageListener = baseAlloyControllerImpl.schedulerMessageListener;

        if (schedulerMessageListener != null) {
            try {
                SchedulerEngineHelperUtil.unschedule(baseAlloyControllerImpl.getSchedulerJobName(),
                        baseAlloyControllerImpl.getMessageListenerGroupName(), StorageType.MEMORY_CLUSTERED);

                MessageBusUtil.removeDestination(baseAlloyControllerImpl.getSchedulerDestinationName());
            } catch (Exception e) {
                _log.error(e, e);
            }
        }
    }
}

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected void initMessageListener(String destinationName, MessageListener messageListener,
        boolean enableScheduler) {

    MessageBus messageBus = MessageBusUtil.getMessageBus();

    Destination destination = messageBus.getDestination(destinationName);

    if (destination != null) {
        Set<MessageListener> messageListeners = destination.getMessageListeners();

        for (MessageListener curMessageListener : messageListeners) {
            if (!(curMessageListener instanceof InvokerMessageListener)) {
                continue;
            }//from  w w  w  .j a  v  a2 s  . c  o  m

            InvokerMessageListener invokerMessageListener = (InvokerMessageListener) curMessageListener;

            curMessageListener = invokerMessageListener.getMessageListener();

            if (messageListener == curMessageListener) {
                return;
            }

            Class<?> messageListenerClass = messageListener.getClass();

            String messageListenerClassName = messageListenerClass.getName();

            Class<?> curMessageListenerClass = curMessageListener.getClass();

            if (!messageListenerClassName.equals(curMessageListenerClass.getName())) {

                continue;
            }

            try {
                if (enableScheduler) {
                    SchedulerEngineHelperUtil.unschedule(getSchedulerJobName(), getMessageListenerGroupName(),
                            StorageType.MEMORY_CLUSTERED);
                }

                MessageBusUtil.unregisterMessageListener(destinationName, curMessageListener);
            } catch (Exception e) {
                log.error(e, e);
            }

            break;
        }
    } else {
        SerialDestination serialDestination = new SerialDestination();

        serialDestination.setName(destinationName);

        serialDestination.open();

        MessageBusUtil.addDestination(serialDestination);
    }

    try {
        MessageBusUtil.registerMessageListener(destinationName, messageListener);

        if (enableScheduler) {
            SchedulerEngineHelperUtil.schedule(getSchedulerTrigger(), StorageType.MEMORY_CLUSTERED, null,
                    destinationName, null, 0);
        }
    } catch (Exception e) {
        log.error(e, e);
    }
}

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

License:Open Source License

/**
 * Unschedules all Jobs associated with this Listener Class'
 * /*from  w  w w.  j  a v a  2  s . co  m*/
 * Assumes Job and Group Name are equal
 */
public void stopAll() {
    if (this.schedulerClassName != null && this.schedulerClassName != "") {
        List<SchedulerResponse> scheduledJobs;
        try {
            scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs();
            for (SchedulerResponse resp : scheduledJobs) {
                if (resp.getJobName().equalsIgnoreCase(this.schedulerClassName)) {
                    SchedulerEngineHelperUtil.unschedule(resp.getJobName(), resp.getGroupName(),
                            resp.getStorageType());
                }
            }
            LOG.warn("Removed all Schedulers associated with " + this.schedulerClassName);
        } catch (SchedulerException e) {
            LOG.error("Could not retrieve ScheduledJobs");
        }
    } else {
        LOG.info("No Scheduler set!");
    }
}

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

License:Open Source License

/**
 * Unschedules and removes all Jobs associated with this Listener Class'
 * //from www. j  a  v  a 2 s  .  c  o  m
 * Assumes Job and Group Name are equal
 */
public static void removeAllJobs(String portletId) {
    List<SchedulerResponse> scheduledJobs;
    List<SchedulerEntry> entries;
    Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
    List<SchedulerEntry> toRemove = new LinkedList<SchedulerEntry>();
    TriggerState state;

    try {
        scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs();
        for (SchedulerResponse resp : scheduledJobs) {
            if (resp.getJobName().startsWith(PortletScheduler.class.getPackage().getName())) {
                state = SchedulerEngineHelperUtil.getJobState(resp.getJobName(), resp.getGroupName(),
                        resp.getStorageType());
                if (state != (TriggerState.UNSCHEDULED))
                    SchedulerEngineHelperUtil.unschedule(resp.getJobName(), resp.getGroupName(),
                            resp.getStorageType());
                entries = portlet.getSchedulerEntries();
                for (SchedulerEntry entry : entries) {
                    if (entry.getEventListenerClass().equalsIgnoreCase(resp.getJobName())) {
                        LOG.info("SchedulerEntry: " + entry.toString());
                        toRemove.add(entry);
                    }
                }
                entries.removeAll(toRemove);
            }
        }
        LOG.warn("Removed all Schedulers associated with " + PortletScheduler.class.getPackage().getName());
    } catch (SchedulerException e) {
        LOG.error("Could not retrieve ScheduledJobs");
    }
}