Skip to content

Commit dae1dd8

Browse files
committed
Revert "CLOUD-974 JGroups 4 support"
This reverts commit 27c8ca6.
1 parent 5f03ab2 commit dae1dd8

File tree

11 files changed

+31
-147
lines changed

11 files changed

+31
-147
lines changed

common/src/main/java/org/jgroups/ping/common/OpenshiftPing.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.DataInputStream;
2323
import java.io.DataOutputStream;
2424
import java.io.InputStream;
25-
import java.lang.reflect.Method;
2625
import java.net.HttpURLConnection;
2726
import java.net.InetSocketAddress;
2827
import java.net.URL;
@@ -33,12 +32,10 @@
3332
import org.jgroups.Event;
3433
import org.jgroups.Message;
3534
import org.jgroups.annotations.Property;
35+
import org.jgroups.protocols.PING;
3636
import org.jgroups.ping.common.server.Server;
3737
import org.jgroups.ping.common.server.ServerFactory;
3838
import org.jgroups.ping.common.server.Servers;
39-
import org.jgroups.protocols.PING;
40-
import org.openshift.ping.common.compatibility.CompatibilityException;
41-
import org.openshift.ping.common.compatibility.CompatibilityUtils;
4239

4340
public abstract class OpenshiftPing extends PING {
4441

@@ -66,20 +63,9 @@ public abstract class OpenshiftPing extends PING {
6663
private Server _server;
6764
private String _serverName;
6865

69-
private static Method sendMethod; //handled via reflection due to JGroups 3/4 incompatibility
70-
7166
public OpenshiftPing(String systemEnvPrefix) {
7267
super();
7368
_systemEnvPrefix = trimToNull(systemEnvPrefix);
74-
try {
75-
if(CompatibilityUtils.isJGroups4()) {
76-
sendMethod = this.getClass().getMethod("up", Message.class);
77-
} else {
78-
sendMethod = this.getClass().getMethod("up", Event.class);
79-
}
80-
} catch (Exception e) {
81-
throw new CompatibilityException("Could not find suitable 'up' method.", e);
82-
}
8369
}
8470

8571
protected final String getSystemEnvName(String systemEnvSuffix) {
@@ -207,24 +193,12 @@ public void handlePingRequest(InputStream stream) throws Exception {
207193
Message msg = new Message();
208194
msg.readFrom(dataInput);
209195
try {
210-
sendUp(msg);
196+
up(new Event(Event.MSG, msg));
211197
} catch (Exception e) {
212198
log.error("Error processing GET_MBRS_REQ.", e);
213199
}
214200
}
215201

216-
private void sendUp(Message msg) {
217-
try {
218-
if(CompatibilityUtils.isJGroups4()) {
219-
sendMethod.invoke(this, msg);
220-
} else {
221-
sendMethod.invoke(this, new Event(1, msg));
222-
}
223-
} catch (Exception e) {
224-
throw new CompatibilityException("Could not invoke 'up' method.", e);
225-
}
226-
}
227-
228202
private List<InetSocketAddress> readAll() {
229203
if (isClusteringEnabled()) {
230204
return doReadAll(clusterName);

common/src/main/java/org/jgroups/ping/common/server/AbstractServer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24+
import org.jgroups.Channel;
2425
import org.jgroups.JChannel;
2526
import org.jgroups.ping.common.OpenshiftPing;
2627

@@ -30,13 +31,13 @@
3031
public abstract class AbstractServer implements Server {
3132

3233
protected final int port;
33-
protected final Map<String, JChannel> CHANNELS = new HashMap<>();
34+
protected final Map<String, Channel> CHANNELS = new HashMap<String, Channel>();
3435

3536
protected AbstractServer(int port) {
3637
this.port = port;
3738
}
3839

39-
public final JChannel getChannel(String clusterName) {
40+
public final Channel getChannel(String clusterName) {
4041
if (clusterName != null) {
4142
synchronized (CHANNELS) {
4243
return CHANNELS.get(clusterName);
@@ -45,7 +46,7 @@ public final JChannel getChannel(String clusterName) {
4546
return null;
4647
}
4748

48-
protected final void addChannel(JChannel channel) {
49+
protected final void addChannel(Channel channel) {
4950
String clusterName = getClusterName(channel);
5051
if (clusterName != null) {
5152
synchronized (CHANNELS) {
@@ -54,7 +55,7 @@ protected final void addChannel(JChannel channel) {
5455
}
5556
}
5657

57-
protected final void removeChannel(JChannel channel) {
58+
protected final void removeChannel(Channel channel) {
5859
String clusterName = getClusterName(channel);
5960
if (clusterName != null) {
6061
synchronized (CHANNELS) {
@@ -69,11 +70,11 @@ protected final boolean hasChannels() {
6970
}
7071
}
7172

72-
private String getClusterName(final JChannel channel) {
73+
private String getClusterName(final Channel channel) {
7374
if (channel != null) {
7475
String clusterName = channel.getClusterName();
7576
// clusterName will be null if the Channel is not yet connected, but we still need it!
76-
if (clusterName == null) {
77+
if (clusterName == null && channel instanceof JChannel) {
7778
try {
7879
Field field = JChannel.class.getDeclaredField("cluster_name");
7980
field.setAccessible(true);
@@ -84,7 +85,7 @@ private String getClusterName(final JChannel channel) {
8485
return null;
8586
}
8687

87-
protected final void handlePingRequest(JChannel channel, InputStream stream) throws Exception {
88+
protected final void handlePingRequest(Channel channel, InputStream stream) throws Exception {
8889
if (channel != null) {
8990
OpenshiftPing handler = (OpenshiftPing) channel.getProtocolStack().findProtocol(OpenshiftPing.class);
9091
handler.handlePingRequest(stream);

common/src/main/java/org/jgroups/ping/common/server/JDKServer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.net.InetSocketAddress;
2222
import java.util.concurrent.Executors;
2323

24-
import org.jgroups.JChannel;
24+
import org.jgroups.Channel;
2525

2626
import com.sun.net.httpserver.HttpExchange;
2727
import com.sun.net.httpserver.HttpHandler;
@@ -38,7 +38,7 @@ public JDKServer(int port) {
3838
super(port);
3939
}
4040

41-
public synchronized boolean start(JChannel channel) throws Exception {
41+
public synchronized boolean start(Channel channel) throws Exception {
4242
boolean started = false;
4343
if (server == null) {
4444
try {
@@ -57,7 +57,7 @@ public synchronized boolean start(JChannel channel) throws Exception {
5757
return started;
5858
}
5959

60-
public synchronized boolean stop(JChannel channel) {
60+
public synchronized boolean stop(Channel channel) {
6161
boolean stopped = false;
6262
removeChannel(channel);
6363
if (server != null && !hasChannels()) {
@@ -82,7 +82,7 @@ public void handle(HttpExchange exchange) throws IOException {
8282
exchange.sendResponseHeaders(200, 0);
8383
try {
8484
String clusterName = exchange.getRequestHeaders().getFirst(CLUSTER_NAME);
85-
JChannel channel = server.getChannel(clusterName);
85+
Channel channel = server.getChannel(clusterName);
8686
try (InputStream stream = exchange.getRequestBody()) {
8787
handlePingRequest(channel, stream);
8888
}

common/src/main/java/org/jgroups/ping/common/server/Server.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package org.jgroups.ping.common.server;
1818

19-
import org.jgroups.JChannel;
19+
import org.jgroups.Channel;
2020

2121
/**
2222
* @author <a href="mailto:[email protected]">Ales Justin</a>
2323
*/
2424
public interface Server {
2525
public static final String CLUSTER_NAME = "CLUSTER_NAME";
26-
public boolean start(JChannel channel) throws Exception;
27-
public boolean stop(JChannel channel);
28-
public JChannel getChannel(String clusterName);
26+
public boolean start(Channel channel) throws Exception;
27+
public boolean stop(Channel channel);
28+
public Channel getChannel(String clusterName);
2929
}

common/src/main/java/org/jgroups/ping/common/server/UndertowServer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package org.jgroups.ping.common.server;
1818

19-
import java.io.InputStream;
20-
21-
import org.jgroups.JChannel;
22-
2319
import io.undertow.Undertow;
2420
import io.undertow.server.HttpHandler;
2521
import io.undertow.server.HttpServerExchange;
2622

23+
import java.io.InputStream;
24+
25+
import org.jgroups.Channel;
26+
2727
/**
2828
* @author <a href="mailto:[email protected]">Ales Justin</a>
2929
*/
@@ -34,7 +34,7 @@ public UndertowServer(int port) {
3434
super(port);
3535
}
3636

37-
public synchronized boolean start(JChannel channel) throws Exception {
37+
public synchronized boolean start(Channel channel) throws Exception {
3838
boolean started = false;
3939
if (server == null) {
4040
try {
@@ -53,7 +53,7 @@ public synchronized boolean start(JChannel channel) throws Exception {
5353
return started;
5454
}
5555

56-
public synchronized boolean stop(JChannel channel) {
56+
public synchronized boolean stop(Channel channel) {
5757
boolean stopped = false;
5858
removeChannel(channel);
5959
if (server != null && !hasChannels()) {
@@ -82,7 +82,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
8282

8383
exchange.startBlocking();
8484
String clusterName = exchange.getRequestHeaders().getFirst(CLUSTER_NAME);
85-
JChannel channel = server.getChannel(clusterName);
85+
Channel channel = server.getChannel(clusterName);
8686
try (InputStream stream = exchange.getInputStream()) {
8787
handlePingRequest(channel, stream);
8888
}

common/src/main/java/org/openshift/ping/common/compatibility/CompatibilityException.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

common/src/main/java/org/openshift/ping/common/compatibility/CompatibilityUtils.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

kube/src/test/java/org/jgroups/ping/kube/test/PingTestBase.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,19 @@
1616

1717
package org.jgroups.ping.kube.test;
1818

19-
import java.lang.reflect.Method;
2019
import java.util.ArrayList;
2120
import java.util.List;
2221

23-
import org.jgroups.Channel;
2422
import org.jgroups.JChannel;
2523
import org.jgroups.util.Util;
2624
import org.junit.Assert;
2725
import org.junit.Test;
28-
import org.openshift.ping.common.compatibility.CompatibilityException;
29-
import org.openshift.ping.common.compatibility.CompatibilityUtils;
3026

3127
/**
3228
* @author <a href="mailto:[email protected]">Ales Justin</a>
3329
*/
3430
public abstract class PingTestBase extends TestBase {
3531

36-
//handles via reflection because of JGroups 3/4 incompatibility.
37-
private static final Method waitForViewMethod;
38-
39-
static {
40-
try {
41-
if (CompatibilityUtils.isJGroups4()) {
42-
waitForViewMethod = Util.class.getMethod("waitUntilAllChannelsHaveSameView", long.class, long.class, JChannel[].class);
43-
} else {
44-
waitForViewMethod = Util.class.getMethod("waitUntilAllChannelsHaveSameSize", long.class, long.class, Channel[].class);
45-
}
46-
} catch (NoSuchMethodException e) {
47-
throw new CompatibilityException("Could not find proper 'waitUntilAllChannelsHaveSame*' method.", e);
48-
}
49-
}
50-
5132
@Test
5233
public void testCluster() throws Exception {
5334
doTestCluster();
@@ -64,7 +45,7 @@ public void testRestart() throws Exception {
6445
}
6546

6647
protected void doTestCluster() throws Exception {
67-
waitForViewMethod.invoke(null, 10000, 1000, channels);
48+
Util.waitUntilAllChannelsHaveSameSize(10000, 1000, channels);
6849

6950
// Tests unicasts from the first to the last
7051
JChannel first = channels[0], last = channels[getNum() - 1];

kube/src/test/java/org/jgroups/ping/kube/test/ServerTestBase.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818

1919
import java.io.ByteArrayOutputStream;
2020
import java.io.DataOutputStream;
21-
import java.lang.reflect.Constructor;
2221
import java.net.HttpURLConnection;
2322
import java.net.URL;
2423
import java.util.Arrays;
25-
import java.util.Collection;
2624

2725
import org.jgroups.Address;
2826
import org.jgroups.Event;
2927
import org.jgroups.Message;
3028
import org.jgroups.PhysicalAddress;
31-
import org.jgroups.View;
3229
import org.jgroups.conf.ClassConfigurator;
3330
import org.jgroups.ping.common.server.Server;
3431
import org.jgroups.ping.kube.Client;
@@ -42,8 +39,6 @@
4239
import org.jgroups.util.Util;
4340
import org.junit.Assert;
4441
import org.junit.Test;
45-
import org.openshift.ping.common.compatibility.CompatibilityException;
46-
import org.openshift.ping.common.compatibility.CompatibilityUtils;
4742

4843
/**
4944
* @author <a href="mailto:[email protected]">Ales Justin</a>
@@ -76,7 +71,8 @@ public void testResponse() throws Exception {
7671
PhysicalAddress physical_addr = (PhysicalAddress) pinger
7772
.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
7873
PingHeader hdr = new TestPingHeader();
79-
PingData data = createPingData(local_addr, physical_addr);
74+
PingData data = new PingData(local_addr, null, false, UUID.get(local_addr),
75+
physical_addr != null ? Arrays.asList(physical_addr) : null);
8076
Message msg = new Message(null).setFlag(Message.Flag.DONT_BUNDLE)
8177
.putHeader(pinger.getId(), hdr).setBuffer(streamableToBuffer(data));
8278

@@ -93,25 +89,6 @@ public void testResponse() throws Exception {
9389
Assert.assertEquals(200, conn.getResponseCode());
9490
}
9591

96-
/*
97-
* Handled via reflection because of JGroups 3/4 incompatibility.
98-
*/
99-
private PingData createPingData(Address local_addr, PhysicalAddress physical_addr) {
100-
try {
101-
if(CompatibilityUtils.isJGroups4()) {
102-
Constructor<PingData> constructor = PingData.class.getConstructor(Address.class, boolean.class);
103-
return constructor.newInstance(local_addr, false);
104-
} else {
105-
String localAddressAsString = (String) UUID.class.getMethod("get", Address.class).invoke(null, local_addr);
106-
Constructor<PingData> constructor = PingData.class.getConstructor(Address.class, View.class, boolean.class, String.class, Collection.class);;
107-
return constructor.newInstance(local_addr, null, false, localAddressAsString,
108-
physical_addr != null ? Arrays.asList(physical_addr) : null);
109-
}
110-
} catch (Exception e) {
111-
throw new CompatibilityException("Could not find or invoke proper 'PingData' constructor");
112-
}
113-
}
114-
11592
private static Buffer streamableToBuffer(Streamable obj) {
11693
final ByteArrayOutputStream out_stream = new ByteArrayOutputStream(512);
11794
DataOutputStream out = new DataOutputStream(out_stream);

0 commit comments

Comments
 (0)