use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class ContinuousBoundingBoxClientQuery method fetchAndSendNextTuples.
@Override
public void fetchAndSendNextTuples(final short packageSequence) throws IOException, PackageEncodeException {
try {
long sendTuplesInThisPage = 0;
clientConnectionHandler.writeResultPackage(new MultipleTupleStartResponse(packageSequence));
while (queryActive) {
if (sendTuplesInThisPage >= tuplesPerPage) {
clientConnectionHandler.writeResultPackage(new PageEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
return;
}
// Send next tuple or wait
final Tuple tuple = tupleQueue.take();
final JoinedTuple joinedTuple = new JoinedTuple(tuple, requestTable.getFullname());
clientConnectionHandler.writeResultTuple(packageSequence, joinedTuple);
totalSendTuples++;
sendTuplesInThisPage++;
}
// All tuples are send
clientConnectionHandler.writeResultPackage(new MultipleTupleEndResponse(packageSequence));
clientConnectionHandler.flushPendingCompressionPackages();
} catch (InterruptedException e) {
logger.debug("Got interrupted excetion");
close();
Thread.currentThread().interrupt();
}
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class KeyClientQuery method computeTuples.
/**
* Fetch the tuples for the given key and remove the duplicates
*/
protected void computeTuples() {
try {
final String fullname = requestTable.getDistributionGroup();
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
final List<TupleStoreName> localTables = regionIdMapper.getAllLocalTables(requestTable);
for (final TupleStoreName tupleStoreName : localTables) {
final TupleStoreManager storageManager = clientConnectionHandler.getStorageRegistry().getTupleStoreManager(tupleStoreName);
final List<Tuple> tuplesInTable = storageManager.get(key);
tuplesForKey.addAll(tuplesInTable);
}
removeDuplicates(localTables);
} catch (BBoxDBException | StorageManagerException e) {
logger.error("Got an exception while fetching tuples for key " + key, e);
tuplesForKey.clear();
}
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class JoinedTupleResponse method decodePackage.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static JoinedTupleResponse decodePackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short requestId = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateResponsePackageHeader(encodedPackage, NetworkConst.RESPONSE_TYPE_JOINED_TUPLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final List<String> tupleStoreNames = new ArrayList<>();
final List<Tuple> tuples = new ArrayList<>();
final int numberOfTuples = encodedPackage.getInt();
for (int i = 0; i < numberOfTuples; i++) {
final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
tupleStoreNames.add(tupleAndTable.getTable());
tuples.add(tupleAndTable.getTuple());
}
final JoinedTuple joinedTuple = new JoinedTuple(tuples, tupleStoreNames);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after encoding: " + encodedPackage.remaining());
}
return new JoinedTupleResponse(requestId, joinedTuple);
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class RequestWorker method runThread.
@Override
protected void runThread() throws Exception {
while (!Thread.currentThread().isInterrupted()) {
try {
final TupleListFuture future = queue.take();
synchronized (activeWorker) {
activeWorker.incrementAndGet();
activeWorker.notifyAll();
}
if (future != null) {
future.waitForAll();
final Iterator<Tuple> iter = future.iterator();
while (iter.hasNext()) {
iter.next();
}
}
synchronized (activeWorker) {
activeWorker.decrementAndGet();
activeWorker.notifyAll();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
}
use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.
the class NetworkTupleEncoderDecoder method decode.
/**
* Convert a ByteBuffer into a TupleAndTable object
* @param encodedPackage
* @return
*/
public static TupleAndTable decode(final ByteBuffer encodedPackage) {
final short tableLength = encodedPackage.getShort();
final short keyLength = encodedPackage.getShort();
final int bBoxLength = encodedPackage.getInt();
final int dataLength = encodedPackage.getInt();
final long timestamp = encodedPackage.getLong();
final byte[] tableBytes = new byte[tableLength];
encodedPackage.get(tableBytes, 0, tableBytes.length);
final String table = new String(tableBytes);
final byte[] keyBytes = new byte[keyLength];
encodedPackage.get(keyBytes, 0, keyBytes.length);
final String key = new String(keyBytes);
final byte[] boxBytes = new byte[bBoxLength];
encodedPackage.get(boxBytes, 0, boxBytes.length);
final byte[] dataBytes = new byte[dataLength];
encodedPackage.get(dataBytes, 0, dataBytes.length);
final BoundingBox boundingBox = BoundingBox.fromByteArray(boxBytes);
Tuple tuple = null;
if (TupleHelper.isDeletedTuple(boxBytes, dataBytes)) {
tuple = new DeletedTuple(key, timestamp);
} else {
tuple = new Tuple(key, boundingBox, dataBytes, timestamp);
}
return new TupleAndTable(tuple, table);
}
Aggregations