use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class TestCompressionRatio method handleCompressedData.
/**
* Handle compressed packages
* @param tableName
* @param buffer
* @return
* @throws PackageEncodeException
* @throws IOException
*/
protected long handleCompressedData(final TupleStoreName tableName, final List<Tuple> buffer) {
final RoutingHeader routingHeader = new RoutingHeader(false);
final List<NetworkRequestPackage> packages = buffer.stream().map(t -> new InsertTupleRequest((short) 4, routingHeader, tableName, t)).collect(Collectors.toList());
final CompressionEnvelopeRequest compressionEnvelopeRequest = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, packages);
buffer.clear();
return packageToBytes(compressionEnvelopeRequest);
}
use of org.bboxdb.network.packages.PackageEncodeException 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.PackageEncodeException in project bboxdb by jnidzwetzki.
the class NetworkHelper method uncompressBytes.
/**
* Uncompress the data in the byte array
* @param compressionType
* @param compressedBytes
* @return
* @throws PackageEncodeException
*/
public static byte[] uncompressBytes(final byte compressionType, final byte[] compressedBytes) throws PackageEncodeException {
try {
final ByteArrayInputStream bais = new ByteArrayInputStream(compressedBytes);
final GZIPInputStream inputStream = new GZIPInputStream(bais);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buffer = new byte[10240];
for (int length = 0; (length = inputStream.read(buffer)) > 0; ) {
baos.write(buffer, 0, length);
}
inputStream.close();
baos.close();
return baos.toByteArray();
} catch (IOException e) {
throw new PackageEncodeException(e);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class BBoxDBConnection method testPackageSend.
/**
* Recalculate the routing header and handle the exceptions
* @param requestPackage
* @param future
* @return
*/
private boolean testPackageSend(final NetworkRequestPackage requestPackage, final NetworkOperationFuture future) {
try {
// Check if package needs to be send
final RoutingHeader routingHeader = requestPackage.getRoutingHeader();
if (routingHeader.isRoutedPackage()) {
if (routingHeader.getHopCount() == 0) {
future.setMessage("No distribution regions in next hop, not sending to server");
future.fireCompleteEvent();
return false;
}
}
} catch (PackageEncodeException e) {
final String message = "Got a exception during package encoding";
logger.error(message);
future.setMessage(message);
future.setFailedState();
future.fireCompleteEvent();
return false;
}
return true;
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static CreateDistributionGroupRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_DISTRIBUTION_GROUP);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final int dimensions = encodedPackage.getInt();
final short replicationFactor = encodedPackage.getShort();
final short groupLength = encodedPackage.getShort();
final short placementLength = encodedPackage.getShort();
final short spacePartitionerLength = encodedPackage.getShort();
final int placementConfigLength = encodedPackage.getInt();
final int spacePartitionerConfigLength = encodedPackage.getInt();
final int maximumRegionSize = encodedPackage.getInt();
final int minimumRegionSize = encodedPackage.getInt();
// Distribution group
final byte[] groupBytes = new byte[groupLength];
encodedPackage.get(groupBytes, 0, groupBytes.length);
final String distributionGroup = new String(groupBytes);
// Placement strategy
final byte[] placementBytes = new byte[placementLength];
encodedPackage.get(placementBytes, 0, placementBytes.length);
final String placemeneStrategy = new String(placementBytes);
// Placement config length
final byte[] placementConfigBytes = new byte[placementConfigLength];
encodedPackage.get(placementConfigBytes, 0, placementConfigBytes.length);
final String placementConfig = new String(placementConfigBytes);
// Space partitioner
final byte[] spacePartitionerBytes = new byte[spacePartitionerLength];
encodedPackage.get(spacePartitionerBytes, 0, spacePartitionerBytes.length);
final String spacePartitioner = new String(spacePartitionerBytes);
// Space partitioner configuration
final byte[] spacePartitionerConfigBytes = new byte[spacePartitionerConfigLength];
encodedPackage.get(spacePartitionerConfigBytes, 0, spacePartitionerConfigBytes.length);
final String spacePartitionerConfig = new String(spacePartitionerConfigBytes);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withPlacementStrategy(placemeneStrategy, placementConfig).withSpacePartitioner(spacePartitioner, spacePartitionerConfig).withMaximumRegionSize(maximumRegionSize).withMinimumRegionSize(minimumRegionSize).withReplicationFactor(replicationFactor).build();
return new CreateDistributionGroupRequest(sequenceNumber, distributionGroup, configuration);
}
Aggregations