Skip to content

Commit a568b81

Browse files
committed
CLOUD-1576 prevent multiple servers from being created; use same server for all channels
1 parent dda646c commit a568b81

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.openshift.ping.common.server;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public abstract class AbstractServerFactory implements ServerFactory {
7+
8+
private static final Map<Integer, Server> SERVERS = new HashMap<Integer, Server>();
9+
10+
@Override
11+
public synchronized final Server getServer(int port) {
12+
Server server = SERVERS.get(port);
13+
if (server == null) {
14+
server = createServer(port);
15+
SERVERS.put(port, server);
16+
}
17+
return server;
18+
}
19+
20+
public abstract Server createServer(int port);
21+
22+
}

common/src/main/java/org/openshift/ping/common/server/JBossServerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author <a href="mailto:[email protected]">Ales Justin</a>
2121
*/
22-
public class JBossServerFactory implements ServerFactory {
22+
public class JBossServerFactory extends AbstractServerFactory {
2323

2424
public boolean isAvailable() {
2525
try {
@@ -30,7 +30,7 @@ public boolean isAvailable() {
3030
}
3131

3232
@Override
33-
public Server getServer(int port) {
33+
public Server createServer(int port) {
3434
return new JBossServer(port);
3535
}
3636

common/src/main/java/org/openshift/ping/common/server/JDKServerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author <a href="mailto:[email protected]">Ales Justin</a>
2121
*/
22-
public class JDKServerFactory implements ServerFactory {
22+
public class JDKServerFactory extends AbstractServerFactory {
2323

2424
public boolean isAvailable() {
2525
try {
@@ -30,7 +30,7 @@ public boolean isAvailable() {
3030
}
3131

3232
@Override
33-
public Server getServer(int port) {
33+
public Server createServer(int port) {
3434
return new JDKServer(port);
3535
}
3636

common/src/main/java/org/openshift/ping/common/server/UndertowServerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* @author <a href="mailto:[email protected]">Ales Justin</a>
2121
*/
22-
public class UndertowServerFactory implements ServerFactory {
22+
public class UndertowServerFactory extends AbstractServerFactory {
2323

2424
public boolean isAvailable() {
2525
try {
@@ -30,7 +30,7 @@ public boolean isAvailable() {
3030
}
3131

3232
@Override
33-
public Server getServer(int port) {
33+
public Server createServer(int port) {
3434
return new UndertowServer(port);
3535
}
3636

0 commit comments

Comments
 (0)