Skip to content

Commit 36ff7c3

Browse files
committed
Deadlock fix and clean up AbstractFeed, add onFeedSocketException
The 'onFeedSocketException()' and 'onFeedSocketClose()' methods are used to notify any listeners or CompletableFutures that there was an exception thrown by the underlying Socket in the AbstractFeed instance. This fixes forever-waiting SingleMessageFutures and MultiMessageAccumulators
1 parent fc010f2 commit 36ff7c3

File tree

18 files changed

+225
-154
lines changed

18 files changed

+225
-154
lines changed

src/main/java/net/jacobpeterson/iqfeed4j/IQFeed4j.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void stopIQConnect() {
149149
}
150150

151151
/**
152-
* Starts the {@link Level1Feed} instance, or does nothing it it's already started.
152+
* Starts the {@link Level1Feed} instance, or does nothing if it's already started.
153153
*
154154
* @throws IOException thrown for {@link IOException}s
155155
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -159,7 +159,7 @@ public void startLevel1Feed() throws IOException, InterruptedException {
159159
}
160160

161161
/**
162-
* Stops the {@link Level1Feed} instance, or does nothing it it's already stopped.
162+
* Stops the {@link Level1Feed} instance, or does nothing if it's already stopped.
163163
*
164164
* @throws IOException thrown for {@link IOException}s
165165
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -170,7 +170,7 @@ public void stopLevel1Feed() throws IOException, InterruptedException {
170170
}
171171

172172
/**
173-
* Starts the {@link DerivativeFeed} instance, or does nothing it it's already started.
173+
* Starts the {@link DerivativeFeed} instance, or does nothing if it's already started.
174174
*
175175
* @throws IOException thrown for {@link IOException}s
176176
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -181,7 +181,7 @@ public void startDerivativeFeed() throws IOException, InterruptedException {
181181
}
182182

183183
/**
184-
* Stops the {@link DerivativeFeed} instance, or does nothing it it's already stopped.
184+
* Stops the {@link DerivativeFeed} instance, or does nothing if it's already stopped.
185185
*
186186
* @throws IOException thrown for {@link IOException}s
187187
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -192,7 +192,7 @@ public void stopDerivativeFeed() throws IOException, InterruptedException {
192192
}
193193

194194
/**
195-
* Starts the {@link AdminFeed} instance, or does nothing it it's already started.
195+
* Starts the {@link AdminFeed} instance, or does nothing if it's already started.
196196
*
197197
* @throws IOException thrown for {@link IOException}s
198198
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -202,7 +202,7 @@ public void startAdminFeed() throws IOException, InterruptedException {
202202
}
203203

204204
/**
205-
* Stops the {@link AdminFeed} instance, or does nothing it it's already stopped.
205+
* Stops the {@link AdminFeed} instance, or does nothing if it's already stopped.
206206
*
207207
* @throws IOException thrown for {@link IOException}s
208208
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -213,7 +213,7 @@ public void stopAdminFeed() throws IOException, InterruptedException {
213213
}
214214

215215
/**
216-
* Starts the {@link HistoricalFeed} instance, or does nothing it it's already started.
216+
* Starts the {@link HistoricalFeed} instance, or does nothing if it's already started.
217217
*
218218
* @throws IOException thrown for {@link IOException}s
219219
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -223,7 +223,7 @@ public void startHistoricalFeed() throws IOException, InterruptedException {
223223
}
224224

225225
/**
226-
* Stops the {@link HistoricalFeed} instance, or does nothing it it's already stopped.
226+
* Stops the {@link HistoricalFeed} instance, or does nothing if it's already stopped.
227227
*
228228
* @throws IOException thrown for {@link IOException}s
229229
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -234,7 +234,7 @@ public void stopHistoricalFeed() throws IOException, InterruptedException {
234234
}
235235

236236
/**
237-
* Starts the {@link MarketSummaryFeed} instance, or does nothing it it's already started.
237+
* Starts the {@link MarketSummaryFeed} instance, or does nothing if it's already started.
238238
*
239239
* @throws IOException thrown for {@link IOException}s
240240
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -245,7 +245,7 @@ public void startMarketSummaryFeed() throws IOException, InterruptedException {
245245
}
246246

247247
/**
248-
* Stops the {@link MarketSummaryFeed} instance, or does nothing it it's already stopped.
248+
* Stops the {@link MarketSummaryFeed} instance, or does nothing if it's already stopped.
249249
*
250250
* @throws IOException thrown for {@link IOException}s
251251
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -256,7 +256,7 @@ public void stopMarketSummaryFeed() throws IOException, InterruptedException {
256256
}
257257

258258
/**
259-
* Starts the {@link NewsFeed} instance, or does nothing it it's already started.
259+
* Starts the {@link NewsFeed} instance, or does nothing if it's already started.
260260
*
261261
* @throws IOException thrown for {@link IOException}s
262262
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -266,7 +266,7 @@ public void startNewsFeed() throws IOException, InterruptedException {
266266
}
267267

268268
/**
269-
* Stops the {@link NewsFeed} instance, or does nothing it it's already stopped.
269+
* Stops the {@link NewsFeed} instance, or does nothing if it's already stopped.
270270
*
271271
* @throws IOException thrown for {@link IOException}s
272272
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -277,7 +277,7 @@ public void stopNewsFeed() throws IOException, InterruptedException {
277277
}
278278

279279
/**
280-
* Starts the {@link OptionChainsFeed} instance, or does nothing it it's already started.
280+
* Starts the {@link OptionChainsFeed} instance, or does nothing if it's already started.
281281
*
282282
* @throws IOException thrown for {@link IOException}s
283283
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -288,7 +288,7 @@ public void startOptionChainsFeed() throws IOException, InterruptedException {
288288
}
289289

290290
/**
291-
* Stops the {@link OptionChainsFeed} instance, or does nothing it it's already stopped.
291+
* Stops the {@link OptionChainsFeed} instance, or does nothing if it's already stopped.
292292
*
293293
* @throws IOException thrown for {@link IOException}s
294294
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -299,7 +299,7 @@ public void stopOptionChainsFeed() throws IOException, InterruptedException {
299299
}
300300

301301
/**
302-
* Starts the {@link SymbolMarketInfoFeed} instance, or does nothing it it's already started.
302+
* Starts the {@link SymbolMarketInfoFeed} instance, or does nothing if it's already started.
303303
*
304304
* @throws IOException thrown for {@link IOException}s
305305
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -310,7 +310,7 @@ public void startSymbolMarketInfoFeed() throws IOException, InterruptedException
310310
}
311311

312312
/**
313-
* Stops the {@link SymbolMarketInfoFeed} instance, or does nothing it it's already stopped.
313+
* Stops the {@link SymbolMarketInfoFeed} instance, or does nothing if it's already stopped.
314314
*
315315
* @throws IOException thrown for {@link IOException}s
316316
* @throws InterruptedException thrown for {@link InterruptedException}s
@@ -329,11 +329,9 @@ public void stopSymbolMarketInfoFeed() throws IOException, InterruptedException
329329
*
330330
* @return the started {@link AbstractFeed}
331331
*
332-
* @throws IOException thrown for {@link IOException}s
333-
* @throws InterruptedException thrown for {@link InterruptedException}s
332+
* @throws IOException thrown for {@link IOException}s
334333
*/
335-
private <F extends AbstractFeed> F startFeed(F feed, Supplier<F> feedInstantiator)
336-
throws IOException, InterruptedException {
334+
private <F extends AbstractFeed> F startFeed(F feed, Supplier<F> feedInstantiator) throws IOException {
337335
if (feed == null) {
338336
feed = feedInstantiator.get();
339337
feed.start();
@@ -352,10 +350,9 @@ private <F extends AbstractFeed> F startFeed(F feed, Supplier<F> feedInstantiato
352350
* @param <F> the {@link AbstractFeed} type parameter
353351
* @param feed the {@link AbstractFeed}
354352
*
355-
* @throws IOException thrown for {@link IOException}s
356-
* @throws InterruptedException thrown for {@link InterruptedException}s
353+
* @throws IOException thrown for {@link IOException}s
357354
*/
358-
private <F extends AbstractFeed> void stopFeed(F feed) throws IOException, InterruptedException {
355+
private <F extends AbstractFeed> void stopFeed(F feed) throws IOException {
359356
if (feed != null) {
360357
feed.stop();
361358
}

src/main/java/net/jacobpeterson/iqfeed4j/executable/ExecutablePollingFeed.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public ExecutablePollingFeed(String hostname, int port) {
2424

2525
@Override
2626
protected void onMessageReceived(String[] csv) {}
27+
28+
@Override
29+
protected void onFeedSocketException(Exception exception) {}
30+
31+
@Override
32+
protected void onFeedSocketClose() {}
2733
}

src/main/java/net/jacobpeterson/iqfeed4j/executable/IQConnectExecutable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public int waitForConnection(long timeoutMillis) throws TimeoutException {
193193
* @param pollingInterval the time to wait between connection attempts
194194
* @param timoutMillis the timeout time in milliseconds
195195
*
196-
* @return the number of attempts it took to connect
196+
* @return the number of attempts it took to connect, or <code>-1</code> if waiting for connection was interrupted
197197
*
198198
* @throws TimeoutException thrown when <code>timoutMillis</code> have elapsed without a successful connection
199199
*/
@@ -216,7 +216,7 @@ public int waitForConnection(String hostname, int port, int pollingInterval, lon
216216

217217
return attempts;
218218
} catch (InterruptedException interruptedException) {
219-
return 0;
219+
return -1;
220220
} catch (IOException ignored) {}
221221
}
222222

0 commit comments

Comments
 (0)