|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.core; |
|
21 |
| |
|
22 |
| import java.util.Hashtable; |
|
23 |
| import java.util.Iterator; |
|
24 |
| import java.util.Map; |
|
25 |
| import java.util.Timer; |
|
26 |
| import java.util.TimerTask; |
|
27 |
| |
|
28 |
| import org.apache.commons.logging.Log; |
|
29 |
| import org.apache.commons.logging.LogFactory; |
|
30 |
| import org.apache.xindice.core.data.Key; |
|
31 |
| import org.apache.xindice.core.data.Record; |
|
32 |
| import org.apache.xindice.util.Configuration; |
|
33 |
| import org.w3c.dom.Document; |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| public class DatabaseChangeObserver extends DBObserver { |
|
46 |
| |
|
47 |
| private static final Log log = LogFactory.getLog(DatabaseChangeObserver.class); |
|
48 |
| |
|
49 |
| |
|
50 |
| private static final long FLUSH_PERIOD = 1000 * 60; |
|
51 |
| |
|
52 |
| |
|
53 |
| private final Hashtable collectionDirtyFlags; |
|
54 |
| private Timer flushTimer; |
|
55 |
| |
|
56 |
19
| public DatabaseChangeObserver() {
|
|
57 |
19
| collectionDirtyFlags = new Hashtable();
|
|
58 |
19
| flushTimer = new Timer(true);
|
|
59 |
19
| flushTimer.schedule(new FlushTask(), FLUSH_PERIOD, FLUSH_PERIOD);
|
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
1725
| public void dropDocument(Collection col, Key key) throws DBException {
|
|
70 |
1725
| collectionDirtyFlags.put(col,Boolean.TRUE);
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
10196
| public void putDocument(Collection col, Key key, Document document, boolean create) throws DBException {
|
|
82 |
10196
| collectionDirtyFlags.put(col,Boolean.TRUE);
|
|
83 |
| } |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
1033
| public void createCollection(Collection col) throws DBException {
|
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
35233
| public void loadDocument(Collection col, Record record, Document document) throws DBException {
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
1036
| public void dropCollection(Collection col) throws DBException {
|
|
109 |
| } |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
1321
| public void flushDatabaseConfig(Database db, Configuration cfg) {
|
|
117 |
| } |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
1894
| public void setCollectionConfig(Collection col, Configuration cfg) {
|
|
125 |
| } |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
123
| public void setDatabaseConfig(Database db, Map collections, Configuration cfg) {
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| private class FlushTask extends TimerTask { |
|
140 |
19
| public FlushTask() {
|
|
141 |
| } |
|
142 |
| |
|
143 |
9
| public void run() {
|
|
144 |
9
| synchronized (collectionDirtyFlags) {
|
|
145 |
9
| int flushCount = 0;
|
|
146 |
9
| Iterator collections = collectionDirtyFlags.entrySet().iterator();
|
|
147 |
9
| while (collections.hasNext()) {
|
|
148 |
526
| Map.Entry e = (Map.Entry) collections.next();
|
|
149 |
526
| Collection c = (Collection) e.getKey();
|
|
150 |
526
| try {
|
|
151 |
| |
|
152 |
| |
|
153 |
526
| c.getFiler().flush();
|
|
154 |
526
| flushCount ++;
|
|
155 |
| } catch (DBException ex) { |
|
156 |
0
| log.error("Couldn't flush collection: " + c.getName(), ex);
|
|
157 |
| } |
|
158 |
| } |
|
159 |
| |
|
160 |
9
| if (flushCount > 0) {
|
|
161 |
4
| log.info("Successfully flushed " + flushCount + " collections out of " +
|
|
162 |
| collectionDirtyFlags.size()); |
|
163 |
| } |
|
164 |
| |
|
165 |
9
| collectionDirtyFlags.clear();
|
|
166 |
| } |
|
167 |
| } |
|
168 |
| } |
|
169 |
| |
|
170 |
| } |