01: package com.jat.integration.util;
02:
03: import java.util.Hashtable;
04:
05: import com.jat.business.BusinessObjectProperties;
06: import com.jat.business.MultiBusinessObjectProperties;
07: import com.jat.core.log.LogManager;
08: import com.jat.core.util.JatThread;
09: import com.jat.integration.DataSourceFactory;
10:
11: /**
12: * <p>Title: JAT</p>
13: * <p>Description: </p>
14: * <p>Copyright: Copyright (c) 2004 - 2005</p>
15: *
16: * @author stf
17: * @version 1.0
18: * @since 1.2
19: */
20:
21: public class DataSourceAsyncExecuter extends JatThread {
22:
23: public static DataSourceAsyncExecuter getInstance(String dataSource) {
24: DataSourceAsyncExecuter executer = (DataSourceAsyncExecuter) pushers
25: .get(dataSource);
26: if (executer == null) {
27: executer = new DataSourceAsyncExecuter(dataSource);
28: pushers.put(dataSource, executer);
29: }
30: return executer;
31: }
32:
33: public void runIt() {
34: synchronized (multi) {
35: if (this .multi.size() > 0) {
36: try {
37: DataSourceFactory.getFactory().getDataSource(
38: this .dataSource).execute(multi);
39: LogManager.sendDebug(this .getClass().getName()
40: + "::runIt: " + this .getName()
41: + " successfully executed for "
42: + multi.size() + " item(s)");
43: multi = new MultiBusinessObjectProperties();
44: } catch (Exception ex) {
45: LogManager.sendWarning(this .getClass().getName()
46: + "::runIt: " + this .getName()
47: + ": exception: " + ex);
48: }
49: }
50: }
51: }
52:
53: public void addProperties(String operation,
54: BusinessObjectProperties prop) {
55: synchronized (multi) {
56: this .multi.put(operation, prop);
57: }
58: }
59:
60: public void destroy() {
61: super .destroy();
62: pushers.remove(this .dataSource);
63: }
64:
65: private DataSourceAsyncExecuter(String dataSource) {
66: super ("JAT_DS_ASYNC_EXEC - " + dataSource);
67: this .dataSource = dataSource;
68: this .setPriority(this .MIN_PRIORITY);
69: this .start();
70: }
71:
72: private String dataSource;
73:
74: private MultiBusinessObjectProperties multi = new MultiBusinessObjectProperties();
75: private static Hashtable pushers = new Hashtable();
76: }
|