use of org.bboxdb.network.packages.response.SuccessResponse in project bboxdb by jnidzwetzki.
the class DeleteTableHandler method handleRequest.
@Override
public /**
* Handle the delete table call
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final DeleteTableRequest deletePackage = DeleteTableRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = deletePackage.getTable();
logger.info("Got delete call for table: {}", requestTable);
// Delete zookeeper configuration
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
tupleStoreAdapter.deleteTable(requestTable);
// Clear cached data
TupleStoreConfigurationCache.getInstance().clear();
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while delete tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.network.packages.response.SuccessResponse 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.response.SuccessResponse in project bboxdb by jnidzwetzki.
the class PackageRouter method performInsertPackageRoutingAsync.
/**
* Perform the routing task async
* @param packageSequence
* @param insertTupleRequest
* @param boundingBox
*/
public void performInsertPackageRoutingAsync(final short packageSequence, final InsertTupleRequest insertTupleRequest) {
final Runnable routeRunable = new ExceptionSafeRunnable() {
@Override
protected void runThread() {
boolean operationSuccess = true;
try {
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
assert (routingHeader.isRoutedPackage()) : "Tuple is not a routed package";
if (!routingHeader.reachedFinalInstance()) {
routingHeader.dispatchToNextHop();
operationSuccess = sendInsertPackage(insertTupleRequest);
}
} catch (InterruptedException e) {
logger.error("Exception while routing package", e);
Thread.currentThread().interrupt();
operationSuccess = false;
} catch (PackageEncodeException e) {
logger.error("Exception while routing package", e);
operationSuccess = false;
}
if (operationSuccess) {
final SuccessResponse responsePackage = new SuccessResponse(packageSequence);
clientConnectionHandler.writeResultPackageNE(responsePackage);
} else {
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_ROUTING_FAILED);
clientConnectionHandler.writeResultPackageNE(responsePackage);
}
}
};
// Submit the runnable to our pool
if (threadPool.isShutdown()) {
logger.warn("Thread pool is shutting down, don't route package: {}", packageSequence);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_SHUTDOWN);
clientConnectionHandler.writeResultPackageNE(responsePackage);
} else {
threadPool.submit(routeRunable);
}
}
use of org.bboxdb.network.packages.response.SuccessResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testGetResultBodyLength1.
/**
* Read the body length from a result package
* @throws PackageEncodeException
* @throws IOException
*/
@Test(timeout = 60000)
public void testGetResultBodyLength1() throws PackageEncodeException, IOException {
final SuccessResponse response = new SuccessResponse((short) 2);
final byte[] encodedPackage = networkPackageToByte(response);
Assert.assertNotNull(encodedPackage);
// 2 Bytes message length
final int calculatedBodyLength = 2;
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final long bodyLength = NetworkPackageDecoder.getBodyLengthFromResponsePackage(bb);
Assert.assertEquals(calculatedBodyLength, bodyLength);
}
use of org.bboxdb.network.packages.response.SuccessResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method getPackageTypeFromResponse2.
/**
* Get the package type from the response
* @throws PackageEncodeException
* @throws IOException
*/
@Test(timeout = 60000)
public void getPackageTypeFromResponse2() throws PackageEncodeException, IOException {
final SuccessResponse response = new SuccessResponse((short) 2, "abc");
final byte[] encodedPackage = networkPackageToByte(response);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
Assert.assertEquals(NetworkConst.RESPONSE_TYPE_SUCCESS, NetworkPackageDecoder.getPackageTypeFromResponse(bb));
}
Aggregations