Skip to content

Commit 47e2410

Browse files
committed
No effective change - tidy and reformat
1 parent 43e758a commit 47e2410

6 files changed

Lines changed: 87 additions & 95 deletions

File tree

src/main/java/io/ebean/redis/encode/EncodeBeanData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class EncodeBeanData implements Encode {
1414
public byte[] encode(Object value) {
1515

1616
try {
17-
CachedBeanData data = (CachedBeanData)value;
17+
CachedBeanData data = (CachedBeanData) value;
1818
ByteArrayOutputStream os = new ByteArrayOutputStream();
1919
ObjectOutputStream oos = new ObjectOutputStream(os);
2020

src/main/java/io/ebean/redis/encode/EncodeManyIdsData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class EncodeManyIdsData implements Encode {
1414
public byte[] encode(Object value) {
1515

1616
try {
17-
CachedManyIds data = (CachedManyIds)value;
17+
CachedManyIds data = (CachedManyIds) value;
1818
ByteArrayOutputStream os = new ByteArrayOutputStream();
1919
ObjectOutputStream oos = new ObjectOutputStream(os);
2020

src/main/java/io/ebean/redis/topic/DaemonTopic.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public interface DaemonTopic {
99

1010
/**
1111
* Subscribe to the topic/channel (blocking).
12-
*
13-
* @param jedis The redis connection to subscribe (and block on).
14-
*/
15-
void subscribe(Jedis jedis);
12+
*
13+
* @param jedis The redis connection to subscribe (and block on).
14+
*/
15+
void subscribe(Jedis jedis);
1616

1717
/**
1818
* Notify that the topic subscription has been connected (or reconnected).
19-
*/
20-
void notifyConnected();
19+
*/
20+
void notifyConnected();
2121
}

src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,78 +18,78 @@
1818
*/
1919
public class DaemonTopicRunner {
2020

21-
private static final Logger log = LoggerFactory.getLogger(DaemonTopicRunner.class);
22-
23-
private static final long reconnectWaitMillis = 1000;
24-
25-
private final JedisPool jedisPool;
26-
27-
private final DaemonTopic daemonTopic;
28-
29-
public DaemonTopicRunner(JedisPool jedisPool, DaemonTopic daemonTopic) {
30-
this.jedisPool = jedisPool;
31-
this.daemonTopic = daemonTopic;
32-
}
33-
34-
public void run() {
35-
Thread t = new Thread(() -> attemptConnections(), "redis-sub");
36-
t.start();
37-
}
38-
39-
private void attemptConnections() {
40-
41-
Timer reloadTimer = new Timer("redis-sub-notify");
42-
ReloadNotifyTask notifyTask = null;
43-
int attempts = 1;
44-
45-
while (true) {
46-
if (notifyTask != null) {
47-
// we didn't successfully re-connect to redis
48-
notifyTask.cancel();
49-
}
50-
notifyTask = new ReloadNotifyTask();
51-
reloadTimer.schedule(notifyTask, reconnectWaitMillis + 500);
52-
attempts++;
53-
try {
54-
subscribe();
55-
} catch (JedisException e) {
56-
log.debug("... redis subscribe connection attempt:{} failed:{}", attempts, e.getMessage());
57-
try {
58-
// wait a little before retrying
59-
Thread.sleep(reconnectWaitMillis);
60-
} catch (InterruptedException e1) {
61-
log.warn("Interrupted redis re-connection wait", e1);
62-
}
63-
}
64-
}
65-
}
66-
67-
/**
68-
* Subscribe and block when successful.
69-
*/
70-
private void subscribe() {
71-
Jedis jedis = jedisPool.getResource();
72-
jedis.echo("hi");
73-
try {
74-
daemonTopic.subscribe(jedis);
75-
76-
} catch (Exception e) {
77-
log.error("Lost connection to topic, starting re-connection loop", e);
78-
attemptConnections();
79-
80-
} finally {
81-
try {
82-
jedis.close();
83-
} catch (Exception e) {
84-
log.warn("Error closing probably broken Redis connection", e);
85-
}
86-
}
87-
}
88-
89-
private class ReloadNotifyTask extends TimerTask {
90-
@Override
91-
public void run() {
92-
daemonTopic.notifyConnected();
93-
}
94-
}
21+
private static final Logger log = LoggerFactory.getLogger(DaemonTopicRunner.class);
22+
23+
private static final long reconnectWaitMillis = 1000;
24+
25+
private final JedisPool jedisPool;
26+
27+
private final DaemonTopic daemonTopic;
28+
29+
public DaemonTopicRunner(JedisPool jedisPool, DaemonTopic daemonTopic) {
30+
this.jedisPool = jedisPool;
31+
this.daemonTopic = daemonTopic;
32+
}
33+
34+
public void run() {
35+
Thread t = new Thread(() -> attemptConnections(), "redis-sub");
36+
t.start();
37+
}
38+
39+
private void attemptConnections() {
40+
41+
Timer reloadTimer = new Timer("redis-sub-notify");
42+
ReloadNotifyTask notifyTask = null;
43+
int attempts = 1;
44+
45+
while (true) {
46+
if (notifyTask != null) {
47+
// we didn't successfully re-connect to redis
48+
notifyTask.cancel();
49+
}
50+
notifyTask = new ReloadNotifyTask();
51+
reloadTimer.schedule(notifyTask, reconnectWaitMillis + 500);
52+
attempts++;
53+
try {
54+
subscribe();
55+
} catch (JedisException e) {
56+
log.debug("... redis subscribe connection attempt:{} failed:{}", attempts, e.getMessage());
57+
try {
58+
// wait a little before retrying
59+
Thread.sleep(reconnectWaitMillis);
60+
} catch (InterruptedException e1) {
61+
log.warn("Interrupted redis re-connection wait", e1);
62+
}
63+
}
64+
}
65+
}
66+
67+
/**
68+
* Subscribe and block when successful.
69+
*/
70+
private void subscribe() {
71+
Jedis jedis = jedisPool.getResource();
72+
jedis.echo("hi");
73+
try {
74+
daemonTopic.subscribe(jedis);
75+
76+
} catch (Exception e) {
77+
log.error("Lost connection to topic, starting re-connection loop", e);
78+
attemptConnections();
79+
80+
} finally {
81+
try {
82+
jedis.close();
83+
} catch (Exception e) {
84+
log.warn("Error closing probably broken Redis connection", e);
85+
}
86+
}
87+
}
88+
89+
private class ReloadNotifyTask extends TimerTask {
90+
@Override
91+
public void run() {
92+
daemonTopic.notifyConnected();
93+
}
94+
}
9595
}

src/test/java/io/ebean/redis/ClusterTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.ebean.redis;
22

33
import domain.EFoo;
4-
import io.ebean.Ebean;
54
import io.ebean.EbeanServer;
65
import io.ebean.EbeanServerFactory;
76
import io.ebean.config.ServerConfig;
@@ -27,8 +26,6 @@ private EbeanServer createOther() {
2726
@Test
2827
public void test() throws InterruptedException {
2928

30-
EbeanServer server = Ebean.getDefaultServer();
31-
3229
EbeanServer other = createOther();
3330

3431
for (int i = 0; i < 10; i++) {
@@ -57,9 +54,6 @@ public void test() throws InterruptedException {
5754
assertCounts(dualCache, 3, 2, 0, 2);
5855

5956

60-
//other.getServerCacheManager().clearAll();
61-
62-
6357
foo0.setName("name2");
6458
foo0.save();
6559
allowAsyncMessaging();

src/test/java/io/ebean/redis/IntegrationTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public class IntegrationTest {
1111
@Test
1212
public void test() throws InterruptedException {
1313

14-
// EbeanServer server = Ebean.getDefaultServer();
15-
1614
EFoo foo = new EFoo("Jack");
1715
foo.save();
1816

@@ -27,22 +25,22 @@ public void test() throws InterruptedException {
2725
.setId(id)
2826
.findOne();
2927

30-
System.out.println("got "+one);
28+
System.out.println("got " + one);
3129

3230

3331
EFoo one2 = Ebean.find(EFoo.class)
3432
.where().like("name", "fo%")
3533
.setUseQueryCache(true)
3634
.findOne();
3735

38-
System.out.println("one2 "+one2);
36+
System.out.println("one2 " + one2);
3937

4038
one2 = Ebean.find(EFoo.class)
4139
.where().like("name", "fo%")
4240
.setUseQueryCache(true)
4341
.findOne();
4442

45-
System.out.println("one2 "+one2);
43+
System.out.println("one2 " + one2);
4644

4745
foo.setName("fo2");
4846
foo.setLocalDate(LocalDate.now());
@@ -55,14 +53,14 @@ public void test() throws InterruptedException {
5553
.setUseQueryCache(true)
5654
.findOne();
5755

58-
System.out.println("one2 "+one2);
56+
System.out.println("one2 " + one2);
5957

6058
one2 = Ebean.find(EFoo.class)
6159
.where().like("name", "fo%")
6260
.setUseQueryCache(true)
6361
.findOne();
6462

65-
System.out.println("one2 "+one2);
63+
System.out.println("one2 " + one2);
6664

6765
System.out.println("done");
6866
}

0 commit comments

Comments
 (0)