List of usage examples for com.liferay.portal.kernel.scheduler SchedulerEngineHelperUtil getScheduledJobs
public static List<SchedulerResponse> getScheduledJobs() throws SchedulerException
From source file:com.rivetlogic.quartz.util.QuartzSchedulerUtil.java
License:Open Source License
public static void getSchedulerJobs(PortletRequest request) throws SchedulerException { // Scheduler List List<SchedulerResponse> schedulerJobs = SchedulerEngineHelperUtil.getScheduledJobs(); List<SchedulerJobBean> schedulerJobBeans = getSchedulerJobsList(schedulerJobs); request.setAttribute(ATTRIBUTE_JOBS_LIST, schedulerJobBeans); request.setAttribute(ATTRIBUTE_COUNT, schedulerJobBeans.size()); }
From source file:de.uhh.l2g.plugins.util.PortletScheduler.java
License:Open Source License
/** * Crowds this Scheduler with ResponseMessage Data Unique iff (jobName == * schedulerClassName == groupName && storageType == STOR) * //from w ww .ja v a2 s . com * @return PortletScheduler */ public PortletScheduler assembleMessageFromResponses() { // These should be unique if everything is configured by liferay default try { List<SchedulerResponse> scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs(); for (SchedulerResponse resp : scheduledJobs) { if (resp.getJobName().equalsIgnoreCase(this.schedulerClassName)) { this.setJobName(resp.getJobName()); this.setGroupName(resp.getGroupName()); this.setStorageType(resp.getStorageType()); this.setDescription(resp.getDescription()); this.setMessage(resp.getMessage()); this.setTrigger(resp.getTrigger()); if (this.getMessage() == null) this.setMessage(new Message()); LOG.debug("Job found. Copy Portlet Information: " + this.getMessage().toString()); Map<String, Object> map = this.getMessage().getValues(); // Fill this message with portlet specific data if (map.containsKey(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME)) this.getMessage().put(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME, map.get(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME).toString()); if (map.containsKey(SchedulerEngine.PORTLET_ID)) this.getMessage().put(SchedulerEngine.PORTLET_ID, map.get(SchedulerEngine.PORTLET_ID).toString()); if (map.containsKey(SchedulerEngine.MESSAGE_LISTENER_UUID)) this.getMessage().put(SchedulerEngine.MESSAGE_LISTENER_UUID, map.get(SchedulerEngine.MESSAGE_LISTENER_UUID).toString()); LOG.debug(this.getMessage().get(SchedulerEngine.DESTINATION_NAME) + " " + this.getMessage().getDestinationName() + " " + this.getMessage().getValues().get(SchedulerEngine.DESTINATION_NAME) + " " + this.getMessage().getDestinationName()); if (map.containsKey("MESSAGE_LISTENER_CLASS_NAME") && map.get("DESTINATION_NAME") != null) { this.destination = map.get("DESTINATION_NAME").toString(); // this.getMessage().put(SchedulerEngine.DESTINATION_NAME, // map.get("DESTINATION_NAME").toString()); this.getMessage().getValues().put(SchedulerEngine.DESTINATION_NAME, map.get("DESTINATION_NAME").toString()); this.getMessage().setDestinationName( this.getMessage().getValues().get(SchedulerEngine.DESTINATION_NAME).toString()); } else { LOG.debug("Destination not available yet. Setting to " + DEST); this.destination = DEST; // this.getMessage().put(SchedulerEngine.DESTINATION_NAME, // DEST); this.getMessage().getValues().put(SchedulerEngine.DESTINATION_NAME, DEST); this.getMessage().setDestinationName( this.getMessage().getValues().get(SchedulerEngine.DESTINATION_NAME).toString()); } // new ReceiverKey(this.getJobName(), this.getGroupName()) this.getMessage().put(SchedulerEngine.RECEIVER_KEY, GetterUtil.getString(new ReceiverKey(this.getJobName(), this.getGroupName()))); LOG.debug("ReceiverKey: " + new ReceiverKey(this.getJobName(), this.getGroupName())); TriggerState state = SchedulerEngineHelperUtil.getJobState(this.getJobName(), this.getGroupName(), this.getStorageType()); LOG.debug(state); } } } catch (SchedulerException e) { LOG.warn(e); } return this; }
From source file:de.uhh.l2g.plugins.util.PortletScheduler.java
License:Open Source License
/** * Unschedules Quartz Job but keeps SchedulerEntry in Memory (Scheduler will * be not correctly (re)deployed if in state UNSCHEDULED * /*from ww w. j a va2 s . c om*/ */ public void unschedule() { try { List<SchedulerResponse> scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs(); for (SchedulerResponse resp : scheduledJobs) { if (resp.getJobName().equalsIgnoreCase(this.schedulerClassName)) { LOG.info("Stopping :" + resp.toString()); Map<String, Object> map = resp.getMessage().getValues(); String portletId = ""; String listenerName = ""; if (map.containsKey(SchedulerEngine.PORTLET_ID)) portletId = map.get(SchedulerEngine.PORTLET_ID).toString(); if (map.containsKey(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME)) listenerName = map.get(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME).toString(); LOG.info("Associated to :" + portletId + " " + listenerName + " " + this.destination); TriggerState state = SchedulerEngineHelperUtil.getJobState(resp.getJobName(), resp.getGroupName(), resp.getStorageType()); if (state != (TriggerState.UNSCHEDULED)) { Thread thread = Thread.currentThread(); LOG.info("Thread :" + thread.getContextClassLoader() + thread.toString()); LOG.info("Unscheduling :" + this.schedulerClassName + " " + resp.getTrigger().toString()); SchedulerEngineHelperUtil.unschedule(schedulerEntry, resp.getStorageType()); // TODO: Check Workaround // This removes the SchedulerEntry from Liferay's // Scheduler List so it is not started aditionally on // re-deploy // BUT, removing this entry will also destroy our // Trigger (as Quartz unschedule(), removes the Trigger // from QuartzJob this.removeFromEntries(); } else { LOG.warn("Scheduler could not be unscheduled beacuse it was in state " + state); } } } } catch (SchedulerException e) { LOG.warn("Failed to unschedule job" + this.schedulerClassName, e); } }
From source file:de.uhh.l2g.plugins.util.PortletScheduler.java
License:Open Source License
/** * Deletes the Scheduler thoroughly until server restart! * /*from w w w. ja v a2 s .com*/ */ public void delete() { try { List<SchedulerResponse> scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs(); for (SchedulerResponse resp : scheduledJobs) { if (resp.getJobName().equalsIgnoreCase(this.schedulerClassName)) { LOG.info("Stopping :" + resp.toString()); Map<String, Object> map = resp.getMessage().getValues(); String portletId = ""; String listenerName = ""; if (map.containsKey(SchedulerEngine.PORTLET_ID)) portletId = map.get(SchedulerEngine.PORTLET_ID).toString(); if (map.containsKey(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME)) listenerName = map.get(SchedulerEngine.MESSAGE_LISTENER_CLASS_NAME).toString(); LOG.info("Associated to :" + portletId + " " + listenerName + " " + this.destination); TriggerState state = SchedulerEngineHelperUtil.getJobState(resp.getJobName(), resp.getGroupName(), resp.getStorageType()); if (state.equals(TriggerState.NORMAL)) { Thread thread = Thread.currentThread(); LOG.info("Thread :" + thread.getContextClassLoader() + thread.toString()); LOG.info("Unscheduling :" + this.schedulerClassName + " " + resp.getTrigger().toString()); SchedulerEngineHelperUtil.delete(schedulerEntry, resp.getStorageType()); // This removes the SchedulerEntry from Liferay's // Scheduler List so it is not started aditionally on // re-deploy // Removing this entry will also destroy our Trigger (as // Quartz unschedule(), removes the Trigger from // QuartzJob this.removeFromEntries(); } else { LOG.warn("Scheduler could not be unscheduled beacuse it was in state " + state); } } } } catch (SchedulerException e) { LOG.warn("Failed to unschedule job" + this.schedulerClassName, e); } }
From source file:de.uhh.l2g.plugins.util.PortletScheduler.java
License:Open Source License
/** * Unschedules all Jobs associated with this Listener Class' * //ww w . ja va 2s .c om * 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 deletes all Jobs associated with this Listener Class' * Does not affect SchedulerEntries!/*w w w. j av a 2 s . com*/ * Assumes Job and Group Name are equal */ public static void pauseAllJobs() { List<SchedulerResponse> scheduledJobs; try { scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs(); for (SchedulerResponse resp : scheduledJobs) { if (resp != null && resp.getJobName().contains(PortletScheduler.class.getPackage().getName())) { SchedulerEngineHelperUtil.pause(resp.getJobName(), resp.getGroupName(), resp.getStorageType()); } } LOG.info("Paused all Schedulers associated with " + PortletScheduler.class.getPackage().getName()); } catch (SchedulerException e) { LOG.error("Could not retrieve ScheduledJobs"); } }
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 .ja va2s . 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"); } }
From source file:de.uhh.l2g.plugins.util.PortletScheduler.java
License:Open Source License
public static List<PortletScheduler> ListSchedulers() { List<PortletScheduler> schedulers = new LinkedList<PortletScheduler>(); PortletScheduler psch = null;/*from w w w . j a v a2 s .c o m*/ try { List<SchedulerResponse> scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs(); for (SchedulerResponse resp : scheduledJobs) { if (resp != null && resp.getJobName().contains(PortletScheduler.class.getPackage().getName())) { psch = new PortletScheduler(); LOG.info(resp.toString()); psch.setJobName(resp.getJobName()); psch.setGroupName(resp.getGroupName()); psch.setStorageType(resp.getStorageType()); psch.setDescription(resp.getDescription()); psch.setMessage(resp.getMessage()); psch.setTrigger(resp.getTrigger()); TriggerState state = SchedulerEngineHelperUtil.getJobState(resp.getJobName(), resp.getGroupName(), resp.getStorageType()); schedulers.add(psch); LOG.info("SchedulerResponse: " + psch.getJobName()); } } } catch (SchedulerException e) { LOG.error("Could not retrieve ScheduledJobs"); } return schedulers; }