@Override public void close() { checkRunning(); closeConnections( null ); }
/** * Either calls the ErrorListener or closes the connection * if there are no listeners. */ protected void handleError( Throwable t ) { // If there are no listeners then close the connection with // a reason if( errorListeners.isEmpty() ) { log.log( Level.SEVERE, "Termining connection due to unhandled error", t ); DisconnectInfo info = new DisconnectInfo(); info.reason = "Connection Error"; info.error = t; closeConnections(info); return; } for( ErrorListener l : errorListeners ) { l.handleError( this, t ); } }
DisconnectInfo info = new DisconnectInfo(); info.reason = reason; closeConnections(info);
@Override public void close() { checkRunning(); closeConnections( null ); }
public void close() { checkRunning(); closeConnections( null ); }
/** * Either calls the ErrorListener or closes the connection * if there are no listeners. */ protected void handleError( Throwable t ) { // If there are no listeners then close the connection with // a reason if( errorListeners.isEmpty() ) { log.log( Level.SEVERE, "Termining connection due to unhandled error", t ); DisconnectInfo info = new DisconnectInfo(); info.reason = "Connection Error"; info.error = t; closeConnections(info); return; } for( ErrorListener l : errorListeners ) { l.handleError( this, t ); } }
/** * Either calls the ErrorListener or closes the connection * if there are no listeners. */ protected void handleError( Throwable t ) { // If there are no listeners then close the connection with // a reason if( errorListeners.isEmpty() ) { log.log( Level.SEVERE, "Termining connection due to unhandled error", t ); DisconnectInfo info = new DisconnectInfo(); info.reason = "Connection Error"; info.error = t; closeConnections(info); return; } for( ErrorListener l : errorListeners ) { l.handleError( this, t ); } }
protected void dispatch( Message m ) { // Pull off the connection management messages we're // interested in and then pass on the rest. if( m instanceof ClientRegistrationMessage ) { // Then we've gotten our real id this.id = (int)((ClientRegistrationMessage)m).getId(); log.log( Level.INFO, "Connection established, id:{0}.", this.id ); connecting.countDown(); fireConnected(); return; } if( m instanceof DisconnectMessage ) { // Can't do too much else yet String reason = ((DisconnectMessage)m).getReason(); log.log( Level.SEVERE, "Connection terminated, reason:{0}.", reason ); DisconnectInfo info = new DisconnectInfo(); info.reason = reason; closeConnections(info); } // Make sure client MessageListeners are called single-threaded // since it could receive messages from the TCP and UDP // thread simultaneously. synchronized( this ) { messageListeners.messageReceived( this, m ); } }
DisconnectInfo info = new DisconnectInfo(); info.reason = reason; closeConnections(info);