|
19 | 19 | import com.higherfrequencytrading.chronicle.Chronicle;
|
20 | 20 | import com.higherfrequencytrading.chronicle.Excerpt;
|
21 | 21 | import com.higherfrequencytrading.chronicle.ExcerptMarshallable;
|
| 22 | +import com.higherfrequencytrading.chronicle.tcp.InProcessChronicleSink; |
22 | 23 | import com.higherfrequencytrading.chronicle.tools.ChronicleTools;
|
23 | 24 |
|
24 | 25 | import java.io.Closeable;
|
@@ -57,14 +58,17 @@ public DataStore(final Chronicle chronicle, ModelMode mode) {
|
57 | 58 |
|
58 | 59 | case READ_ONLY:
|
59 | 60 | final String name = chronicle.name();
|
60 |
| - updater = Executors.newSingleThreadExecutor(new ThreadFactory() { |
61 |
| - @Override |
62 |
| - public Thread newThread(Runnable r) { |
63 |
| - Thread t = new Thread(r, name + "data store updater"); |
64 |
| - t.setDaemon(true); |
65 |
| - return t; |
66 |
| - } |
67 |
| - }); |
| 61 | + if (chronicle instanceof InProcessChronicleSink) |
| 62 | + updater = Executors.newSingleThreadExecutor(new ThreadFactory() { |
| 63 | + @Override |
| 64 | + public Thread newThread(Runnable r) { |
| 65 | + Thread t = new Thread(r, name + "data store updater"); |
| 66 | + t.setDaemon(true); |
| 67 | + return t; |
| 68 | + } |
| 69 | + }); |
| 70 | + else |
| 71 | + updater = null; |
68 | 72 | break;
|
69 | 73 |
|
70 | 74 | default:
|
@@ -157,24 +161,25 @@ public void start(final long lastEvent) {
|
157 | 161 | break;
|
158 | 162 |
|
159 | 163 | case READ_ONLY:
|
160 |
| - updater.submit(new Runnable() { |
161 |
| - @Override |
162 |
| - public void run() { |
163 |
| - excerpt = chronicle.createExcerpt(); |
164 |
| - while (!closed) { |
165 |
| - boolean found = excerpt.nextIndex(); |
166 |
| - if (found) { |
167 |
| - processNextEvent(excerpt.index() <= lastEvent); |
168 |
| - |
169 |
| - } else { |
170 |
| - for (Wrapper wrapper : wrappersArray) { |
171 |
| - wrapper.notifyOff(false); |
172 |
| - wrapper.inSync(); |
| 164 | + if (updater != null) |
| 165 | + updater.submit(new Runnable() { |
| 166 | + @Override |
| 167 | + public void run() { |
| 168 | + excerpt = chronicle.createExcerpt(); |
| 169 | + while (!closed) { |
| 170 | + boolean found = excerpt.nextIndex(); |
| 171 | + if (found) { |
| 172 | + processNextEvent(excerpt.index() <= lastEvent); |
| 173 | + |
| 174 | + } else { |
| 175 | + for (Wrapper wrapper : wrappersArray) { |
| 176 | + wrapper.notifyOff(false); |
| 177 | + wrapper.inSync(); |
| 178 | + } |
173 | 179 | }
|
174 | 180 | }
|
175 | 181 | }
|
176 |
| - } |
177 |
| - }); |
| 182 | + }); |
178 | 183 | break;
|
179 | 184 |
|
180 | 185 | default:
|
@@ -233,4 +238,18 @@ public void close() {
|
233 | 238 | updater.shutdown();
|
234 | 239 | chronicle.close();
|
235 | 240 | }
|
| 241 | + |
| 242 | + /** |
| 243 | + * Should only be used for plain IndexChronicle. |
| 244 | + * |
| 245 | + * @return was a new entry found. |
| 246 | + */ |
| 247 | + public boolean nextEvent() { |
| 248 | + assert updater == null; |
| 249 | + if (excerpt.nextIndex()) { |
| 250 | + processNextEvent(false); |
| 251 | + return true; |
| 252 | + } |
| 253 | + return false; |
| 254 | + } |
236 | 255 | }
|
0 commit comments