use of org.bboxdb.network.packages.request.DisconnectRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeDisconnect.
/**
* The the encoding and decoding of disconnect package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeDisconnect() throws IOException, PackageEncodeException {
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final DisconnectRequest listPackage = new DisconnectRequest(sequenceNumber);
byte[] encodedVersion = networkPackageToByte(listPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final DisconnectRequest decodedPackage = DisconnectRequest.decodeTuple(bb);
Assert.assertEquals(listPackage, decodedPackage);
Assert.assertEquals(listPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.packages.request.DisconnectRequest in project bboxdb by jnidzwetzki.
the class BBoxDBConnection method disconnect.
/* (non-Javadoc)
* @see org.bboxdb.network.client.BBoxDB#disconnect()
*/
public void disconnect() {
if (!connectionState.isInRunningState()) {
logger.error("Unable to disconnect, connection is in state {}", connectionState);
return;
}
synchronized (this) {
logger.info("Disconnecting from server: {}", getConnectionName());
connectionState.dispatchToStopping();
final NetworkOperationFuture future = new NetworkOperationFuture(this, () -> {
return new DisconnectRequest(getNextSequenceNumber());
});
future.execute();
}
settlePendingCalls(DEFAULT_TIMEOUT_MILLIS);
terminateConnection();
}
Aggregations