Skip to content

Commit 734ee01

Browse files
authored
minor cleanup (#59)
* minor cleanup * minor cleanup
1 parent a7dccef commit 734ee01

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/main/java/com/github/dariobalinzo/elastic/ElasticIndexMonitorThread.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77

8-
import java.util.Arrays;
98
import java.util.ArrayList;
109
import java.util.List;
1110
import java.util.concurrent.CountDownLatch;
@@ -17,7 +16,7 @@
1716
*/
1817
public class ElasticIndexMonitorThread extends Thread {
1918
private static final Logger log = LoggerFactory.getLogger(ElasticIndexMonitorThread.class);
20-
private static final long timeout = 10000L;
19+
private static final long TIMEOUT = 10_000L;
2120

2221
private final ConnectorContext context;
2322
private final CountDownLatch shutdownLatch;
@@ -36,7 +35,7 @@ public ElasticIndexMonitorThread(ConnectorContext context, long pollMs, ElasticR
3635
}
3736

3837
public static long getTimeout() {
39-
return timeout;
38+
return TIMEOUT;
4039
}
4140

4241
@Override
@@ -66,16 +65,16 @@ public synchronized List<String> indexes() {
6665

6766
long started = System.currentTimeMillis();
6867
long now = started;
69-
while (indexes.size() == 0 && now - started < timeout) {
68+
while (indexes.isEmpty() && now - started < TIMEOUT) {
7069
try {
71-
wait(timeout - (now - started));
70+
wait(TIMEOUT - (now - started));
7271
} catch (InterruptedException e) {
7372
// Ignore
7473
}
7574
now = System.currentTimeMillis();
7675
}
77-
if (indexes.size() == 0) {
78-
throw new ConnectException("Indexes could not be updated quickly enough.");
76+
if (indexes.isEmpty()) {
77+
throw new ConnectException("Cannot find any elasticsearch index");
7978
}
8079
return indexes;
8180
}
@@ -88,20 +87,20 @@ private synchronized boolean updateIndexes() {
8887
final List<String> indexes;
8988
try {
9089
indexes = elasticRepository.catIndices(this.prefix);
91-
log.debug("Got the following topics: " + Arrays.toString(indexes.toArray()));
90+
log.debug("Got the following topics: {}", indexes);
9291
} catch (RuntimeException e) {
9392
log.error("Error while trying to get updated topics list, ignoring and waiting for next table poll interval", e);
9493
return false;
9594
}
9695

9796
if (!indexes.equals(this.indexes)) {
98-
log.debug("After filtering we got topics: " + Arrays.toString(indexes.toArray()));
97+
log.debug("After filtering we got topics: {}", indexes);
9998
List<String> previousIndexes = this.indexes;
10099
this.indexes = indexes;
101100
notifyAll();
102101
// Only return true if the table list wasn't previously null, i.e. if this was not the
103102
// first table lookup
104-
return previousIndexes.size() > 0;
103+
return !previousIndexes.isEmpty();
105104
}
106105
return false;
107106
}

src/test/java/com/github/dariobalinzo/elastic/ElasticSourceConnectorTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public void shouldGetAListOfTasks() throws IOException {
4444

4545
try {
4646
Thread.sleep(1000);
47-
} catch (InterruptedException e) {
48-
// TODO Auto-generated catch block
49-
e.printStackTrace();
47+
} catch (InterruptedException ignored) {
5048
}
5149

5250
//when

0 commit comments

Comments
 (0)