5
5
import org .slf4j .Logger ;
6
6
import org .slf4j .LoggerFactory ;
7
7
8
- import java .util .Arrays ;
9
8
import java .util .ArrayList ;
10
9
import java .util .List ;
11
10
import java .util .concurrent .CountDownLatch ;
17
16
*/
18
17
public class ElasticIndexMonitorThread extends Thread {
19
18
private static final Logger log = LoggerFactory .getLogger (ElasticIndexMonitorThread .class );
20
- private static final long timeout = 10000L ;
19
+ private static final long TIMEOUT = 10_000L ;
21
20
22
21
private final ConnectorContext context ;
23
22
private final CountDownLatch shutdownLatch ;
@@ -36,7 +35,7 @@ public ElasticIndexMonitorThread(ConnectorContext context, long pollMs, ElasticR
36
35
}
37
36
38
37
public static long getTimeout () {
39
- return timeout ;
38
+ return TIMEOUT ;
40
39
}
41
40
42
41
@ Override
@@ -66,16 +65,16 @@ public synchronized List<String> indexes() {
66
65
67
66
long started = System .currentTimeMillis ();
68
67
long now = started ;
69
- while (indexes .size () == 0 && now - started < timeout ) {
68
+ while (indexes .isEmpty () && now - started < TIMEOUT ) {
70
69
try {
71
- wait (timeout - (now - started ));
70
+ wait (TIMEOUT - (now - started ));
72
71
} catch (InterruptedException e ) {
73
72
// Ignore
74
73
}
75
74
now = System .currentTimeMillis ();
76
75
}
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 " );
79
78
}
80
79
return indexes ;
81
80
}
@@ -88,20 +87,20 @@ private synchronized boolean updateIndexes() {
88
87
final List <String > indexes ;
89
88
try {
90
89
indexes = elasticRepository .catIndices (this .prefix );
91
- log .debug ("Got the following topics: " + Arrays . toString ( indexes . toArray ()) );
90
+ log .debug ("Got the following topics: {}" , indexes );
92
91
} catch (RuntimeException e ) {
93
92
log .error ("Error while trying to get updated topics list, ignoring and waiting for next table poll interval" , e );
94
93
return false ;
95
94
}
96
95
97
96
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 );
99
98
List <String > previousIndexes = this .indexes ;
100
99
this .indexes = indexes ;
101
100
notifyAll ();
102
101
// Only return true if the table list wasn't previously null, i.e. if this was not the
103
102
// first table lookup
104
- return previousIndexes .size () > 0 ;
103
+ return ! previousIndexes .isEmpty () ;
105
104
}
106
105
return false ;
107
106
}
0 commit comments