use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeHeloResponse2.
/**
* The the encoding and decoding of the response helo
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeHeloResponse2() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.setGZipCompression();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
byte[] encodedVersion = networkPackageToByte(helloPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final HelloResponse decodedPackage = HelloResponse.decodePackage(bb);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertTrue(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertTrue(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.
the class BBoxDBConnection method runHandshake.
/**
* Run the handshake with the server
* @throws ExecutionException
* @throws InterruptedException
*/
private void runHandshake() throws Exception {
if (!connectionState.isInStartingState()) {
logger.error("Handshaking called in wrong state: {}", connectionState);
}
// Capabilities are reported to server; now freeze client capabilities.
clientCapabilities.freeze();
final NetworkOperationFuture operationFuture = new NetworkOperationFuture(this, () -> {
return new HelloRequest(getNextSequenceNumber(), NetworkConst.PROTOCOL_VERSION, clientCapabilities);
});
final HelloFuture helloFuture = new HelloFuture(operationFuture);
helloFuture.waitForAll();
if (operationFuture.isFailed()) {
throw new Exception("Got an error during handshake");
}
final HelloResponse helloResponse = helloFuture.get(0);
connectionCapabilities = helloResponse.getPeerCapabilities();
connectionState.dispatchToRunning();
logger.debug("Handshaking with {} done", getConnectionName());
flushHandler = new ConnectionFlushRunnable(this);
flushThread = new Thread(flushHandler);
flushThread.setName("Flush thread for: " + getConnectionName());
flushThread.start();
mainteinanceHandler = new ConnectionMainteinanceRunnable(this);
mainteinanceThread = new Thread(mainteinanceHandler);
mainteinanceThread.setName("Connection mainteinace thread for: " + getConnectionName());
mainteinanceThread.start();
}
use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.
the class HelloHandler method handleServerResult.
/**
* Handle the hello result package
* @return
*/
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle helo package");
}
final HelloResponse helloResponse = HelloResponse.decodePackage(encodedPackage);
if (future != null) {
future.setOperationResult(helloResponse);
future.fireCompleteEvent();
}
return true;
}
use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeHeloResponse1.
/**
* The the encoding and decoding of the response helo
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeHeloResponse1() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
byte[] encodedVersion = networkPackageToByte(helloPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final HelloResponse decodedPackage = HelloResponse.decodePackage(bb);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertFalse(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertFalse(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testCompressionReponse2.
/**
* Test the compression response
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testCompressionReponse2() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.setGZipCompression();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
final CompressionEnvelopeResponse compressionEnvelopeResponse = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(helloPackage));
final byte[] encodedPackage = networkPackageToByte(compressionEnvelopeResponse);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final InputStream uncompressedByteStream = CompressionEnvelopeResponse.decodePackage(bb);
final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
final HelloResponse decodedPackage = HelloResponse.decodePackage(uncompressedByteBuffer);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertTrue(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertTrue(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
Aggregations