/** * Sets the value of the last failure exception and sends out an * attribute change notification for {@link #isConnected()} if necessary. * <p> * It's assumed that this method can only be invoked when the module * is started. * * @param inLastFailure the failure exception, can be null. */ private void setLastFailure(Exception inLastFailure) { boolean oldConnected = mLastFailure == null; mLastFailure = inLastFailure; boolean newConnected = mLastFailure == null; if(oldConnected != newConnected) { sendConnectedChanged(oldConnected, newConnected); } }
/** * Closes the connection to the remote source of data. * This instance is unusable after this method is invoked. * <p> * If one needs to reconnect to the remote source, a new instance * of this class should be created. * <p> * This method does not fail if the attempt to close the connection fails. * In case of failures, the failures are logged and the method returns * silently. */ public synchronized void close() { if(mContext == null) { return; } boolean isConnected = getLastFailure() == null; try { mContext.close(); } catch (Exception e) { //Swallow the exception as it prevents the module from stopping. //If the receiver closed the connection from its end //this method always fails. Messages.LOG_ERROR_CLOSING_CONNECTION.warn(this, e); } mContext = null; if(isConnected) { sendConnectedChanged(isConnected, false); } }