- Timestamp:
- 07/12/13 23:41:06 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/communication/Connection.java
r97 r100 8 8 import com.framsticks.util.lang.Strings; 9 9 10 import org.apache.log4j.Level; 11 import org.apache.log4j.Logger; 10 import org.apache.logging.log4j.Level; 11 import org.apache.logging.log4j.Logger; 12 import org.apache.logging.log4j.LogManager; 12 13 import java.io.BufferedReader; 13 14 import java.io.IOException; … … 22 23 23 24 import com.framsticks.util.dispatching.AbstractJoinable; 25 import com.framsticks.util.dispatching.Dispatcher; 24 26 import com.framsticks.util.dispatching.Dispatching; 27 import com.framsticks.util.dispatching.ExceptionResultHandler; 25 28 import com.framsticks.util.dispatching.Joinable; 26 29 import com.framsticks.util.dispatching.JoinableCollection; … … 32 35 33 36 @FramsClassAnnotation 34 public abstract class Connection extends AbstractJoinable implements JoinableParent {35 36 protected final static Logger log = Log ger.getLogger(Connection.class);37 public abstract class Connection extends AbstractJoinable implements JoinableParent, ExceptionResultHandler { 38 39 protected final static Logger log = LogManager.getLogger(Connection.class); 37 40 38 41 private PrintWriter output = null; … … 48 51 protected final JoinableCollection<Thread<Connection>> threads = new JoinableCollection<>(); 49 52 protected final Set<ConnectionListener> listeners = new HashSet<>(); 53 54 protected ExceptionResultHandler exceptionHandler = ThrowExceptionHandler.getInstance(); 50 55 51 56 /** … … 161 166 try { 162 167 processNextInputBatch(); 168 } catch (FramsticksException e) { 169 handle(e); 163 170 } catch (Exception e) { 164 171 log.log(isRunning() ? Level.ERROR : Level.DEBUG, "caught exception: ", e); … … 183 190 } 184 191 185 186 187 192 @Override 188 193 protected void joinableFinish() { … … 197 202 input = null; 198 203 } 199 200 204 201 205 if (socket != null) { … … 250 254 } 251 255 252 253 256 @Override 254 257 protected void joinableJoin() throws InterruptedException { … … 258 261 protected static void startClientConnection(Connection connection) { 259 262 while (connection.isRunning() && !connection.isConnected()) { 260 log.debug("connecting to " +connection.address);263 log.debug("connecting to {}", connection.address); 261 264 try { 262 265 connection.socket = new Socket(connection.getAddressObject().getHostName(), connection.getAddressObject().getPort()); 263 266 } catch (IOException e) { 264 log.info( connection + " failed to connect (retrying): " +e);267 log.info("{} failed to connect (retrying): ", connection, e); 265 268 Dispatching.sleep(0.5); 266 269 } 267 270 } 268 271 269 log.debug( connection + " connected");272 log.debug("{} connected", connection); 270 273 try { 271 274 connection.socket.setSoTimeout(500); … … 288 291 } 289 292 290 291 293 /** 292 294 * @return the listeners … … 294 296 public Collection<ConnectionListener> getListeners() { 295 297 return listeners; 298 } 299 300 /** 301 * @return the handler 302 */ 303 public ExceptionResultHandler getExceptionHandler() { 304 return exceptionHandler; 305 } 306 307 /** 308 * @param handler the handler to set 309 */ 310 public void setExceptionHandler(ExceptionResultHandler handler) { 311 this.exceptionHandler = handler; 296 312 } 297 313 … … 301 317 } 302 318 319 @Override 320 public void handle(FramsticksException exception) { 321 exceptionHandler.handle(exception); 322 } 323 324 public Dispatcher<Connection> getReceiverDispatcher() { 325 return receiverThread; 326 } 327 328 public Dispatcher<Connection> getSenderDispatcher() { 329 return senderThread; 330 } 331 332 303 333 }
Note: See TracChangeset
for help on using the changeset viewer.