Search in sources :

Example 1 with CreateTableRequest

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

the class TestNetworkClasses method encodeAndDecodeCreateTable.

/**
 * The the encoding and decoding of an create table package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeCreateTable() throws IOException, PackageEncodeException {
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final TupleStoreConfiguration ssTableConfiguration = TupleStoreConfigurationBuilder.create().withTTL(10, TimeUnit.MILLISECONDS).withVersions(666).withSpatialIndexReader("reader").withSpatialIndexWriter("writer").build();
    final CreateTableRequest createPackage = new CreateTableRequest(sequenceNumber, "test", ssTableConfiguration);
    final byte[] encodedVersion = networkPackageToByte(createPackage);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final CreateTableRequest decodedPackage = CreateTableRequest.decodeTuple(bb);
    Assert.assertEquals(createPackage.getTable(), decodedPackage.getTable());
    Assert.assertEquals(createPackage.getTupleStoreConfiguration(), ssTableConfiguration);
    Assert.assertEquals(createPackage, decodedPackage);
    Assert.assertEquals(createPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertEquals(createPackage.toString(), decodedPackage.toString());
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) CreateTableRequest(org.bboxdb.network.packages.request.CreateTableRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 2 with CreateTableRequest

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

the class CreateTableHandler method handleRequest.

@Override
public /**
 * Handle the create table call
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final CreateTableRequest createPackage = CreateTableRequest.decodeTuple(encodedPackage);
        final TupleStoreName requestTable = createPackage.getTable();
        logger.info("Got create call for table: {}", requestTable.getFullname());
        final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
        if (tupleStoreAdapter.isTableKnown(requestTable)) {
            logger.warn("Table name is already known {}", requestTable.getFullname());
            final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_EXISTS);
            clientConnectionHandler.writeResultPackage(responsePackage);
        } else {
            tupleStoreAdapter.writeTuplestoreConfiguration(requestTable, createPackage.getTupleStoreConfiguration());
            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 : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) CreateTableRequest(org.bboxdb.network.packages.request.CreateTableRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

CreateTableRequest (org.bboxdb.network.packages.request.CreateTableRequest)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 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)1 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)1 Test (org.junit.Test)1