Search in sources :

Example 1 with DeleteTableRequest

use of org.bboxdb.network.packages.request.DeleteTableRequest 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 DeleteTableRequest

use of org.bboxdb.network.packages.request.DeleteTableRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method encodeAndDecodeDeleteTable.

/**
 * The the encoding and decoding of an delete table package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeDeleteTable() throws IOException, PackageEncodeException {
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final DeleteTableRequest deletePackage = new DeleteTableRequest(sequenceNumber, "test");
    byte[] encodedVersion = networkPackageToByte(deletePackage);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final DeleteTableRequest decodedPackage = DeleteTableRequest.decodeTuple(bb);
    Assert.assertEquals(deletePackage.getTable(), decodedPackage.getTable());
    Assert.assertEquals(deletePackage, decodedPackage);
    Assert.assertEquals(decodedPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertEquals(deletePackage.toString(), decodedPackage.toString());
}
Also used : DeleteTableRequest(org.bboxdb.network.packages.request.DeleteTableRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

DeleteTableRequest (org.bboxdb.network.packages.request.DeleteTableRequest)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)1 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1 Test (org.junit.Test)1