use of org.bboxdb.network.packages.request.KeepAliveRequest in project bboxdb by jnidzwetzki.
the class KeepAliveHandler method handleRequest.
/**
* Handle the keep alive package. Simply send a success response package back
*/
@Override
public boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
this.clientConnectionHandler = clientConnectionHandler;
final KeepAliveRequest keepAliveRequst = KeepAliveRequest.decodeTuple(encodedPackage);
boolean gossipResult = true;
if (!keepAliveRequst.getTuples().isEmpty()) {
gossipResult = handleGossip(keepAliveRequst, clientConnectionHandler);
}
if (gossipResult) {
final SuccessResponse responsePackage = new SuccessResponse(packageSequence);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_OUTDATED_TUPLES);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.request.KeepAliveRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testRequestPackageHeader.
/**
* Test the encoding of the request package header
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testRequestPackageHeader() throws IOException, PackageEncodeException {
final short currentSequenceNumber = sequenceNumberGenerator.getSequeneNumberWithoutIncrement();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final KeepAliveRequest listTablesRequest = new KeepAliveRequest(sequenceNumber);
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
listTablesRequest.writeToOutputStream(bos);
bos.flush();
bos.close();
final byte[] encodedPackage = bos.toByteArray();
Assert.assertEquals(26, encodedPackage.length);
final ByteBuffer bb = ByteBuffer.wrap(encodedPackage);
bb.order(Const.APPLICATION_BYTE_ORDER);
// Check fields
Assert.assertEquals(currentSequenceNumber, bb.getShort());
Assert.assertEquals(NetworkConst.REQUEST_TYPE_KEEP_ALIVE, bb.getShort());
}
use of org.bboxdb.network.packages.request.KeepAliveRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeKeepAlive2.
/**
* The the encoding and decoding of a keep alive package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeKeepAlive2() throws IOException, PackageEncodeException {
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final String tablename = "testgroup_abc";
final List<Tuple> tuples = new ArrayList<>();
tuples.add(new Tuple("abc", new BoundingBox(1d, 2d, 1d, 2d), "".getBytes()));
tuples.add(new Tuple("def", new BoundingBox(2d, 2d, 4d, 20d), "".getBytes()));
tuples.add(new Tuple("xyz", new BoundingBox(10d, 20d, 10d, 20d), "".getBytes()));
final KeepAliveRequest keepAlivePackage = new KeepAliveRequest(sequenceNumber, tablename, tuples);
byte[] encodedVersion = networkPackageToByte(keepAlivePackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final KeepAliveRequest decodedPackage = KeepAliveRequest.decodeTuple(bb);
Assert.assertEquals(keepAlivePackage.getTablename(), decodedPackage.getTablename());
Assert.assertEquals(keepAlivePackage.getTuples().size(), decodedPackage.getTuples().size());
}
use of org.bboxdb.network.packages.request.KeepAliveRequest in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeKeepAlive1.
/**
* The the encoding and decoding of a keep alive package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeKeepAlive1() throws IOException, PackageEncodeException {
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final KeepAliveRequest keepAlivePackage = new KeepAliveRequest(sequenceNumber);
byte[] encodedVersion = networkPackageToByte(keepAlivePackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final KeepAliveRequest decodedPackage = KeepAliveRequest.decodeTuple(bb);
Assert.assertEquals(keepAlivePackage, decodedPackage);
Assert.assertEquals(keepAlivePackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(keepAlivePackage.toString(), decodedPackage.toString());
}
Aggregations