- Timestamp:
- 06/30/13 12:48:20 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/ClientConnection.java
r85 r88 32 32 protected final Map<String, Subscription<?>> subscriptions = new HashMap<>(); 33 33 34 public String getAddress() { 35 return address; 36 } 37 38 public void connect(StateFunctor connectedFunctor) { 34 /** 35 * @param connectedFunctor the connectedFunctor to set 36 */ 37 public void setConnectedFunctor(StateFunctor connectedFunctor) { 38 this.connectedFunctor = connectedFunctor; 39 } 40 41 42 protected StateFunctor connectedFunctor; 43 44 @Override 45 protected void joinableStart() { 39 46 try { 40 47 log.info("connecting to " + address); … … 46 53 log.info("connected to " + hostName + ":" + port); 47 54 connected = true; 48 49 55 runThreads(); 50 56 … … 56 62 log.error("buffer creation failure"); 57 63 connectedFunctor.call(e); 58 close(); 59 } 60 } 64 // close(); 65 } 66 } 67 61 68 62 69 private static abstract class InboundMessage { … … 149 156 150 157 151 protected final String address;152 158 protected final String hostName; 153 159 protected final int port; … … 156 162 157 163 public ClientConnection(String address) { 158 assert address != null; 159 this.address = address; 164 super(address); 160 165 Matcher matcher = addressPattern.matcher(address); 161 166 if (!matcher.matches()) { … … 235 240 @Override 236 241 public String toString() { 237 return address;242 return "client connection " + address; 238 243 } 239 244 … … 328 333 private int nextQueryId = 0; 329 334 330 protected void processMessage(InboundMessage inboundMessage) throws Exception{335 protected void processMessage(InboundMessage inboundMessage) { 331 336 if (inboundMessage == null) { 332 337 log.error("failed to use any inbound message"); … … 342 347 } 343 348 344 protected void processEvent(String rest) throws Exception{349 protected void processEvent(String rest) { 345 350 Matcher matcher = eventPattern.matcher(rest); 346 351 if (!matcher.matches()) { … … 359 364 360 365 361 protected void processMessageStartingWith(String line) throws Exception{366 protected void processMessageStartingWith(String line) { 362 367 Pair<String, String> command = Strings.splitIntoPair(line, ' ', "\n"); 363 368 if (command.first.equals("event")) { … … 384 389 385 390 @Override 386 protected void receiverThreadRoutine() throws Exception{391 protected void receiverThreadRoutine() { 387 392 while (connected) { 388 processMessageStartingWith(getLine()); 389 } 390 } 393 try { 394 processMessageStartingWith(getLine()); 395 } catch (Exception e) { 396 break; 397 } 398 } 399 } 400 391 401 392 402 }
Note: See TracChangeset
for help on using the changeset viewer.