summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
Diffstat (limited to 'same')
-rw-r--r--same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java b/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
index 280df9b..e76b9f8 100644
--- a/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
+++ b/same/src/main/java/com/orbekk/same/ConnectionManagerImpl.java
@@ -35,11 +35,31 @@ public class ConnectionManagerImpl implements ConnectionManager {
this.readTimeout = readTimeout;
}
+ private boolean isValidLocation(String location) {
+ String[] args = location.split(":");
+ if (args.length != 2) {
+ logger.error("Invalid location: " + location);
+ return false;
+ }
+ try {
+ Integer.valueOf(args[1]);
+ } catch (IllegalArgumentException e) {
+ logger.error("Invalid location: " + location);
+ return false;
+ }
+ return true;
+ }
+
private RpcChannel getChannel(String location) {
Future<RpcChannel> channel = channels.get(location);
if (channel == null) {
- final String hostname = location.split(":")[0];
- final int port = Integer.valueOf(location.split(":")[1]);
+ if (!isValidLocation(location)) {
+ return null;
+ }
+ String[] args = location.split(":");
+ final String hostname = args[0];
+ final int port = Integer.valueOf(args[1]);
+
Callable<RpcChannel> channelFactory =
new Callable<RpcChannel>() {
@Override public RpcChannel call() {