Search in sources :

Example 1 with SuccessResponse

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;
}
Also used : DeleteTableRequest(org.bboxdb.network.packages.request.DeleteTableRequest) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 2 with SuccessResponse

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;
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) KeepAliveRequest(org.bboxdb.network.packages.request.KeepAliveRequest) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 3 with SuccessResponse

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);
    }
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ExceptionSafeRunnable(org.bboxdb.commons.concurrent.ExceptionSafeRunnable) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 4 with SuccessResponse

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

Example 5 with SuccessResponse

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

Aggregations

SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)12 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)7 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)6 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)2 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)2 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)1 CancelQueryRequest (org.bboxdb.network.packages.request.CancelQueryRequest)1 CreateDistributionGroupRequest (org.bboxdb.network.packages.request.CreateDistributionGroupRequest)1 CreateTableRequest (org.bboxdb.network.packages.request.CreateTableRequest)1 DeleteDistributionGroupRequest (org.bboxdb.network.packages.request.DeleteDistributionGroupRequest)1 DeleteTableRequest (org.bboxdb.network.packages.request.DeleteTableRequest)1 KeepAliveRequest (org.bboxdb.network.packages.request.KeepAliveRequest)1 ClientQuery (org.bboxdb.network.server.ClientQuery)1