summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-15 18:28:59 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-15 18:28:59 +0100
commitdce8d88ae2f8cc5140ac2006b8eedab7eaf13989 (patch)
tree93f557117f808467b52aa5afed813ccef8d79a1c /same/src/main/java
parentedc67abb54a52800eaf397e02c426f18e7b1a8dc (diff)
Change ConnectionManager.
Support Client and Master connections.
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/same/ConnectionManager.java3
-rw-r--r--same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java17
2 files changed, 15 insertions, 5 deletions
diff --git a/same/src/main/java/com/orbekk/same/ConnectionManager.java b/same/src/main/java/com/orbekk/same/ConnectionManager.java
index 985f6f0..aa4151e 100644
--- a/same/src/main/java/com/orbekk/same/ConnectionManager.java
+++ b/same/src/main/java/com/orbekk/same/ConnectionManager.java
@@ -6,5 +6,6 @@ package com.orbekk.same;
* When testing, this interface can be mocked to use local participants only.
*/
public interface ConnectionManager {
- SameService getConnection(String url);
+ ClientService getClient(String url);
+ MasterService getMaster(String url);
}
diff --git a/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java b/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
index 841d5fa..0a1e54f 100644
--- a/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
+++ b/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
@@ -14,18 +14,27 @@ public class ConnectionManagerImpl implements ConnectionManager {
public ConnectionManagerImpl() {
}
- @Override
- public SameService getConnection(String url) {
- SameService service = null;
+ private <T>T getClassProxy(String url, Class<T> clazz) {
+ T service = null;
try {
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(url));
service = ProxyUtil.createProxy(
this.getClass().getClassLoader(),
- SameService.class,
+ clazz,
client);
} catch (MalformedURLException e) {
logger.warn("Unable to create client for {}, {}", url, e);
}
return service;
}
+
+ @Override
+ public ClientService getClient(String url) {
+ return getClassProxy(url, ClientService.class);
+ }
+
+ @Override
+ public MasterService getMaster(String url) {
+ return getClassProxy(url, MasterService.class);
+ }
}