summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-30 15:58:22 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-30 15:58:22 +0200
commitf4a71e0d8a17a39b856e20122df60d51326f2cd0 (patch)
tree4ac49f90d069463fbc63e4ef0b895ada6f3a32a5 /same/src/main/java/com
parentfa96cffcbc0f9a1ace736ab72dc8b12cfcf52171 (diff)
Fix error handling in ConnectionManagerImpl.
Diffstat (limited to 'same/src/main/java/com')
-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() {