001: /*
002: * $Id: GenericAbstractDispatcher.java,v 1.4 2003/12/06 23:10:14 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.service;
026:
027: import java.util.Date;
028: import java.util.Map;
029:
030: import org.ofbiz.service.calendar.RecurrenceRule;
031: import org.ofbiz.entity.GenericDelegator;
032: import org.ofbiz.security.Security;
033: import org.ofbiz.service.jms.JmsListenerFactory;
034: import org.ofbiz.service.job.JobManager;
035: import org.ofbiz.service.job.JobManagerException;
036: import org.ofbiz.base.util.Debug;
037:
038: /**
039: * Generic Services Local Dispatcher
040: *
041: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
042: * @version $Revision: 1.4 $
043: * @since 2.0
044: */
045: public abstract class GenericAbstractDispatcher implements
046: LocalDispatcher {
047:
048: public static final String module = GenericAbstractDispatcher.class
049: .getName();
050:
051: protected DispatchContext ctx = null;
052: protected ServiceDispatcher dispatcher = null;
053: protected String name = null;
054:
055: public GenericAbstractDispatcher() {
056: }
057:
058: /**
059: * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.lang.String, java.util.Map, long, int, int, int, long)
060: */
061: public void schedule(String poolName, String serviceName,
062: Map context, long startTime, int frequency, int interval,
063: int count, long endTime) throws GenericServiceException {
064: try {
065: getJobManager().schedule(poolName, serviceName, context,
066: startTime, frequency, interval, count, endTime);
067:
068: if (Debug.verboseOn()) {
069: Debug.logVerbose(
070: "[LocalDispatcher.schedule] : Current time: "
071: + (new Date()).getTime(), module);
072: Debug.logVerbose(
073: "[LocalDispatcher.schedule] : Runtime: "
074: + startTime, module);
075: Debug.logVerbose(
076: "[LocalDispatcher.schedule] : Frequency: "
077: + frequency, module);
078: Debug.logVerbose(
079: "[LocalDispatcher.schedule] : Interval: "
080: + interval, module);
081: Debug.logVerbose("[LocalDispatcher.schedule] : Count: "
082: + count, module);
083: Debug.logVerbose(
084: "[LocalDispatcher.schedule] : EndTime: "
085: + endTime, module);
086: }
087:
088: } catch (JobManagerException e) {
089: throw new GenericServiceException(e.getMessage(), e);
090: }
091: }
092:
093: /**
094: * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long, int, int, int, long)
095: */
096: public void schedule(String serviceName, Map context,
097: long startTime, int frequency, int interval, int count,
098: long endTime) throws GenericServiceException {
099: schedule(null, serviceName, context, startTime, frequency,
100: interval, count, endTime);
101: }
102:
103: /**
104: * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long, int, int, int)
105: */
106: public void schedule(String serviceName, Map context,
107: long startTime, int frequency, int interval, int count)
108: throws GenericServiceException {
109: schedule(serviceName, context, startTime, frequency, interval,
110: count, 0);
111: }
112:
113: /**
114: * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long, int, int, long)
115: */
116: public void schedule(String serviceName, Map context,
117: long startTime, int frequency, int interval, long endTime)
118: throws GenericServiceException {
119: schedule(serviceName, context, startTime, frequency, interval,
120: -1, endTime);
121: }
122:
123: /**
124: * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long)
125: */
126: public void schedule(String serviceName, Map context, long startTime)
127: throws GenericServiceException {
128: schedule(serviceName, context, startTime, RecurrenceRule.DAILY,
129: 1, 1);
130: }
131:
132: /**
133: * @see org.ofbiz.service.LocalDispatcher#getJobManager()
134: */
135: public JobManager getJobManager() {
136: return dispatcher.getJobManager();
137: }
138:
139: /**
140: * @see org.ofbiz.service.LocalDispatcher#getJMSListeneFactory()
141: */
142: public JmsListenerFactory getJMSListeneFactory() {
143: return dispatcher.getJMSListenerFactory();
144: }
145:
146: /**
147: * @see org.ofbiz.service.LocalDispatcher#getDelegator()
148: */
149: public GenericDelegator getDelegator() {
150: return dispatcher.getDelegator();
151: }
152:
153: /**
154: * @see org.ofbiz.service.LocalDispatcher#getSecurity()
155: */
156: public Security getSecurity() {
157: return dispatcher.getSecurity();
158: }
159:
160: /**
161: * @see org.ofbiz.service.LocalDispatcher#getName()
162: */
163: public String getName() {
164: return this .name;
165: }
166:
167: /**
168: * @see org.ofbiz.service.LocalDispatcher#getDispatchContext()
169: */
170: public DispatchContext getDispatchContext() {
171: return ctx;
172: }
173:
174: /**
175: * @see org.ofbiz.service.LocalDispatcher#deregister()
176: */
177: public void deregister() {
178: dispatcher.deregister(this);
179: }
180:
181: }
|