summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientApp.java4
-rw-r--r--same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java14
-rw-r--r--same/src/main/java/com/orbekk/same/MasterApp.java4
3 files changed, 18 insertions, 4 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientApp.java b/same/src/main/java/com/orbekk/same/ClientApp.java
index bf391dc..0effab4 100644
--- a/same/src/main/java/com/orbekk/same/ClientApp.java
+++ b/same/src/main/java/com/orbekk/same/ClientApp.java
@@ -10,11 +10,13 @@ import com.orbekk.net.HttpUtil;
public class ClientApp {
private Logger logger = LoggerFactory.getLogger(getClass());
private Server server;
+ private static final int timeout = 1000;
public void run(int port, String networkName, String masterUrl) {
logger.info("Starting client with port:{}, networkName:{}, masterUrl:{}",
new Object[]{port, networkName, masterUrl});
- ConnectionManagerImpl connections = new ConnectionManagerImpl();
+ ConnectionManagerImpl connections = new ConnectionManagerImpl(timeout,
+ timeout);
State state = new State(networkName);
Broadcaster broadcaster =
BroadcasterImpl.getDefaultBroadcastRunner(connections);
diff --git a/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java b/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
index 0a1e54f..f74bca7 100644
--- a/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
+++ b/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
@@ -8,16 +8,26 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ConnectionManagerImpl implements ConnectionManager {
-
+ private int connectionTimeout;
+ private int readTimeout;
+
private Logger logger = LoggerFactory.getLogger(getClass());
- public ConnectionManagerImpl() {
+ /**
+ * @param connectionTimout Timeout for establishing connection in milliseconds.
+ * @param readTimeout Timeout for waiting for answer in milliseconds.
+ */
+ public ConnectionManagerImpl(int connectionTimout, int readTimeout) {
+ this.connectionTimeout = connectionTimout;
+ this.readTimeout = readTimeout;
}
private <T>T getClassProxy(String url, Class<T> clazz) {
T service = null;
try {
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(url));
+ client.setConnectionTimeoutMillis(connectionTimeout);
+ client.setReadTimeoutMillis(readTimeout);
service = ProxyUtil.createProxy(
this.getClass().getClassLoader(),
clazz,
diff --git a/same/src/main/java/com/orbekk/same/MasterApp.java b/same/src/main/java/com/orbekk/same/MasterApp.java
index 3e22563..1aff6fc 100644
--- a/same/src/main/java/com/orbekk/same/MasterApp.java
+++ b/same/src/main/java/com/orbekk/same/MasterApp.java
@@ -9,9 +9,11 @@ import com.googlecode.jsonrpc4j.JsonRpcServer;
public class MasterApp {
private Logger logger = LoggerFactory.getLogger(getClass());
private Server server;
+ private static final int timeout = 1000;
public void run(int port) {
- ConnectionManagerImpl connections = new ConnectionManagerImpl();
+ ConnectionManagerImpl connections = new ConnectionManagerImpl(timeout,
+ timeout);
State state = new State("MasterNetwork");
Broadcaster broadcaster =
BroadcasterImpl.getDefaultBroadcastRunner(connections);