Search in sources :

Example 1 with DisconnectRequest

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());
}
Also used : DisconnectRequest(org.bboxdb.network.packages.request.DisconnectRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with DisconnectRequest

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();
}
Also used : DisconnectRequest(org.bboxdb.network.packages.request.DisconnectRequest) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture)

Aggregations

DisconnectRequest (org.bboxdb.network.packages.request.DisconnectRequest)2 ByteBuffer (java.nio.ByteBuffer)1 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)1 Test (org.junit.Test)1