KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > service > GenericAbstractDispatcher


1 /*
2  * $Id: GenericAbstractDispatcher.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.service;
26
27 import java.util.Date JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.ofbiz.service.calendar.RecurrenceRule;
31 import org.ofbiz.entity.GenericDelegator;
32 import org.ofbiz.security.Security;
33 import org.ofbiz.service.jms.JmsListenerFactory;
34 import org.ofbiz.service.job.JobManager;
35 import org.ofbiz.service.job.JobManagerException;
36 import org.ofbiz.base.util.Debug;
37
38 /**
39  * Generic Services Local Dispatcher
40  *
41  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
42  * @version $Rev: 5462 $
43  * @since 2.0
44  */

45 public abstract class GenericAbstractDispatcher implements LocalDispatcher {
46
47     public static final String JavaDoc module = GenericAbstractDispatcher.class.getName();
48
49     protected DispatchContext ctx = null;
50     protected ServiceDispatcher dispatcher = null;
51     protected String JavaDoc name = null;
52
53     public GenericAbstractDispatcher() {}
54
55     /**
56      * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.lang.String, java.util.Map, long, int, int, int, long, int)
57      */

58     public void schedule(String JavaDoc poolName, String JavaDoc serviceName, Map JavaDoc context, long startTime, int frequency, int interval, int count, long endTime, int maxRetry) throws GenericServiceException {
59         try {
60             getJobManager().schedule(poolName, serviceName, context, startTime, frequency, interval, count, endTime, maxRetry);
61                 
62             if (Debug.verboseOn()) {
63                 Debug.logVerbose("[LocalDispatcher.schedule] : Current time : " + (new Date JavaDoc()).getTime(), module);
64                 Debug.logVerbose("[LocalDispatcher.schedule] : Runtime : " + startTime, module);
65                 Debug.logVerbose("[LocalDispatcher.schedule] : Frequency : " + frequency, module);
66                 Debug.logVerbose("[LocalDispatcher.schedule] : Interval : " + interval, module);
67                 Debug.logVerbose("[LocalDispatcher.schedule] : Count : " + count, module);
68                 Debug.logVerbose("[LocalDispatcher.schedule] : EndTime : " + endTime, module);
69                 Debug.logVerbose("[LocalDispatcher.schedule] : MazRetry : " + maxRetry, module);
70             }
71             
72         } catch (JobManagerException e) {
73             throw new GenericServiceException(e.getMessage(), e);
74         }
75     }
76
77     /**
78      * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long, int, int, int, long)
79      */

80     public void schedule(String JavaDoc serviceName, Map JavaDoc context, long startTime, int frequency, int interval, int count, long endTime) throws GenericServiceException {
81         ModelService model = ctx.getModelService(serviceName);
82         schedule(null, serviceName, context, startTime, frequency, interval, count, endTime, model.maxRetry);
83     }
84
85     /**
86      * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long, int, int, int)
87      */

88     public void schedule(String JavaDoc serviceName, Map JavaDoc context, long startTime, int frequency, int interval, int count) throws GenericServiceException {
89         schedule(serviceName, context, startTime, frequency, interval, count, 0);
90     }
91       
92     /**
93      * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long, int, int, long)
94      */

95     public void schedule(String JavaDoc serviceName, Map JavaDoc context, long startTime, int frequency, int interval, long endTime) throws GenericServiceException {
96         schedule(serviceName, context, startTime, frequency, interval, -1, endTime);
97     }
98
99     /**
100      * @see org.ofbiz.service.LocalDispatcher#schedule(java.lang.String, java.util.Map, long)
101      */

102     public void schedule(String JavaDoc serviceName, Map JavaDoc context, long startTime) throws GenericServiceException {
103         schedule(serviceName, context, startTime, RecurrenceRule.DAILY, 1, 1);
104     }
105
106     /**
107      * @see org.ofbiz.service.LocalDispatcher#getJobManager()
108      */

109     public JobManager getJobManager() {
110         return dispatcher.getJobManager();
111     }
112    
113     /**
114      * @see org.ofbiz.service.LocalDispatcher#getJMSListeneFactory()
115      */

116     public JmsListenerFactory getJMSListeneFactory() {
117         return dispatcher.getJMSListenerFactory();
118     }
119   
120     /**
121      * @see org.ofbiz.service.LocalDispatcher#getDelegator()
122      */

123     public GenericDelegator getDelegator() {
124         return dispatcher.getDelegator();
125     }
126   
127     /**
128      * @see org.ofbiz.service.LocalDispatcher#getSecurity()
129      */

130     public Security getSecurity() {
131         return dispatcher.getSecurity();
132     }
133   
134     /**
135      * @see org.ofbiz.service.LocalDispatcher#getName()
136      */

137     public String JavaDoc getName() {
138         return this.name;
139     }
140
141     /**
142      * @see org.ofbiz.service.LocalDispatcher#getDispatchContext()
143      */

144     public DispatchContext getDispatchContext() {
145         return ctx;
146     }
147     
148     /**
149      * @see org.ofbiz.service.LocalDispatcher#deregister()
150      */

151     public void deregister() {
152         dispatcher.deregister(this);
153     }
154
155     /**
156      * @see org.ofbiz.service.LocalDispatcher#registerCallback(String, GenericServiceCallback)
157      */

158     public void registerCallback(String JavaDoc serviceName, GenericServiceCallback cb) {
159         dispatcher.registerCallback(serviceName, cb);
160     }
161 }
162
163
Popular Tags