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 ClientConnectionHandler method flushPendingCompressionPackages.
/**
* Write all pending compression packages to server, called by the maintainance thread
*/
protected void flushPendingCompressionPackages() {
final List<NetworkResponsePackage> packagesToWrite = new ArrayList<>();
synchronized (pendingCompressionPackages) {
if (pendingCompressionPackages.isEmpty()) {
return;
}
packagesToWrite.addAll(pendingCompressionPackages);
pendingCompressionPackages.clear();
}
if (logger.isDebugEnabled()) {
logger.debug("Chunk size is: {}", packagesToWrite.size());
}
final NetworkResponsePackage compressionEnvelopeRequest = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, packagesToWrite);
try {
writePackageToSocket(compressionEnvelopeRequest);
} catch (PackageEncodeException | IOException e) {
logger.error("Got an exception while write pending compression packages to client", e);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class ClientConnectionHandler method sendNextResultsForQuery.
/**
* Send next results for the given query
* @param packageSequence
* @param
* @throws PackageEncodeException
* @throws IOException
*/
public void sendNextResultsForQuery(final short packageSequence, final short querySequence) throws IOException, PackageEncodeException {
if (!getActiveQueries().containsKey(querySequence)) {
logger.error("Unable to resume query {} - package {} - not found", querySequence, packageSequence);
writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_QUERY_NOT_FOUND));
return;
}
final Runnable queryRunable = new ExceptionSafeRunnable() {
@Override
protected void runThread() throws IOException, PackageEncodeException {
final ClientQuery clientQuery = getActiveQueries().get(querySequence);
clientQuery.fetchAndSendNextTuples(packageSequence);
if (clientQuery.isQueryDone()) {
logger.info("Query {} is done with {} tuples, removing iterator ", querySequence, clientQuery.getTotalSendTuples());
clientQuery.close();
getActiveQueries().remove(querySequence);
}
}
@Override
protected void afterExceptionHook() {
try {
writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
} catch (IOException | PackageEncodeException e) {
logger.error("Unable to send result package", e);
}
}
};
// Submit the runnable to our pool
if (threadPool.isShutdown()) {
logger.warn("Thread pool is shutting down, don't execute query: {}", querySequence);
writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
} else {
getThreadPool().submit(queryRunable);
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class BBoxDBConnection method flushPendingCompressionPackages.
/**
* Write all pending compression packages to server, called by the maintainance thread
*/
public void flushPendingCompressionPackages() {
final List<NetworkRequestPackage> packagesToWrite = new ArrayList<>();
synchronized (pendingCompressionPackages) {
if (pendingCompressionPackages.isEmpty()) {
return;
}
packagesToWrite.addAll(pendingCompressionPackages);
pendingCompressionPackages.clear();
}
if (logger.isDebugEnabled()) {
logger.debug("Chunk size is: {}", packagesToWrite.size());
}
final NetworkRequestPackage compressionEnvelopeRequest = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, packagesToWrite);
try {
writePackageToSocket(compressionEnvelopeRequest);
} catch (PackageEncodeException | IOException e) {
logger.error("Got an exception while write pending compression packages to server", e);
terminateConnection();
}
}
use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.
the class HandleBoundingBoxQuery method handleQuery.
@Override
public /**
* Handle a bounding box query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is already known, please close old query first", packageSequence);
return;
}
final QueryBoundingBoxRequest queryRequest = QueryBoundingBoxRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {
@Override
public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
if (storageManager.size() != 1) {
throw new IllegalArgumentException("This operator tree needs 1 storage manager");
}
final BoundingBox boundingBox = queryRequest.getBoundingBox();
final SpatialIndexReadOperator operator = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
return operator;
}
};
final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(requestTable));
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
Aggregations