Package com.cloudhopper.datastore

Examples of com.cloudhopper.datastore.DataStoreIterator


    public void dump(Queue queue) throws Exception {
  // queue
  if (queue.getSize() > 0 && dataStore.hasAscendingIteratorSupport()) {
      printHeader(queue);
      DataStoreIterator iterator = dataStore.getAscendingIterator();
      boolean jumped = iterator.jump(priorityKeyUtil.encode(queue.getId(), 0L));
      if (!jumped) return;
      while (true) {
    try {
        DataStoreIterator.Record record = iterator.getRecord();
        byte[] keyBytes = record.getKey();
        CompositeKey key = priorityKeyUtil.decode(keyBytes);
        // long queueId = keyUtil.decodeQueueId(bytes);
        // long itemId = keyUtil.decodeItemId(bytes);
        if (key.getQueueId() != queue.getId()) break;
        PriorityMQMessage.Key pkey = null;
        try {
      pkey = new PriorityMQMessage.Key(key.getItemId());
        } catch (Exception e) {}
        byte[] valueBytes = record.getValue();
        //Object value = queue.getTranscoder().decode(valueBytes);
        printKey(keyBytes, key.getQueueId(), key.getItemId(), pkey);
        writer.println(byteArrayToHexString(valueBytes));
        if (!iterator.next()) return;
    } catch (Exception e) {
        e.printStackTrace();
        break;
    }
      }
View Full Code Here


    throw new QueueFatalException("Error initializing queue", e);
      }
  }

        // iterate thru all the current data in the data store by ascending key
        DataStoreIterator iterator = ds.getAscendingIterator();
        try {
      if (iterator != null && iterator.next()) { //the iterator exists, and has at least 1 record
    int queueId = -1;
    QueueInfo queueInfo = null;
    Queue queue = null;
   
    while (true) {
        queueId = moveToNextQueue(iterator, queueId);
        if (queueId < 0) break; //there are no more queues
       
        queueInfo = queueInfoMap.get(queueId);
        logger.trace("Current queue at {} is {}", queueId, queueInfo);
        if (queueInfo == null) {
      throw new QueueFatalException("The queueId " + queueId + " was in the DataStore, but was not in our queueInfoMap");
        }
        queue = queueIdMap.get(queueId);
        logger.info("Loading persistent queue with id=" + queueId);
       
        if (queue instanceof Preloadable) {
      try {
          ((Preloadable)queue).preload(new PerQueueDataStoreIterator(queueId, priorityKeyUtil.getQueueIdByteLength(), iterator));
      } catch (Exception e) {
          throw new QueueFatalException("Error preloading queue "+queueId, e);
      }
        }
    }
      }
  } finally {
      iterator.close();
  }

  // Activate the queues
  for (Map.Entry<Integer,Queue> entry : queueIdMap.entrySet()) {
      if (entry.getValue() instanceof InitializingQueue) {
View Full Code Here

    /**
     * Load a page from the ds. Call this only when the lock is acquired.
     */
    private int loadPage() throws DataStoreFatalException {
  int loaded = 0;
        DataStoreIterator iterator = ds.getAscendingIterator();
  iterator.jump(priorityKeyUtil.encode(getId(), 0L));
  try {
      do {
    // get the next record
    DataStoreIterator.Record record = iterator.getRecord();
    byte[] k = record.getKey();
    CompositeKey key = priorityKeyUtil.decode(k);
    if (key.getQueueId() == getId()) {
        queue.add(priorityTranscoder.decode(record.getValue()));
        loaded++;
    } else {
        break;
    }
      } while (iterator.next() && loaded < maxItemsInMemory);
  } finally {
      iterator.close();
  }
  return loaded;
    }
View Full Code Here

  return true;
    }

    @Override
    protected PriorityMQMessage<E> doTake() throws QueueInvalidStateException, QueueFatalException, QueueTimeoutException, DataStoreFatalException  {
        DataStoreIterator iterator = ds.getAscendingIterator();
  boolean jumped = iterator.jump(priorityKeyUtil.encode(getId(), 0L));
  if (!jumped) logger.warn("DataStoreIterator failed to jump to queue's first record {} {}", getId(), 0L);
  // if (!jumped) something is wrong, we should zero the size and exit
  try {
      DataStoreIterator.Record record = iterator.getRecord();
      CompositeKey key = priorityKeyUtil.decode(record.getKey());

      PriorityMQMessage.Key pkey = new PriorityMQMessage.Key(key.getItemId());
      if (key.getQueueId() != getId()) {
    logger.error("{} != {}: {} for queue {}", key.getQueueId(), getId(), pkey, this);
    throw new DataStoreFatalException("The next item wasn't for this queueId");
      }
      if (DEBUG) {
    logger.trace("doTake[{}]: {}", getId(), pkey);
    trxLog.offer(pkey.toCompactString("TAKE:"));
      }

      return priorityTranscoder.decode(record.getValue());
  } catch (DataStoreFatalException e) {
      logger.error("Unable to get record from datastore for {}", this);
      dumpTrxLog();
      if (size.get() != 0) {
    logger.warn("This is dangerous, but we're going to zero the queue size.");
    size.set(0);
      }
      this.errorCount.incrementAndGet();
      throw e;
  } finally {
      iterator.close();
  }
    }
View Full Code Here

    public void dump(Queue queue) throws Exception {
  // queue
  if (queue.getSize() > 0 && dataStore.hasAscendingIteratorSupport()) {
      printHeader(queue);
      DataStoreIterator iterator = dataStore.getAscendingIterator();
      boolean jumped = iterator.jump(priorityKeyUtil.encode(queue.getId(), 0L));
      if (!jumped) return;
      while (true) {
    try {
        DataStoreIterator.Record record = iterator.getRecord();
        byte[] keyBytes = record.getKey();
        CompositeKey key = priorityKeyUtil.decode(keyBytes);
        // long queueId = keyUtil.decodeQueueId(bytes);
        // long itemId = keyUtil.decodeItemId(bytes);
        if (key.getQueueId() != queue.getId()) break;
        PriorityMQMessage.Key pkey = null;
        try {
      pkey = new PriorityMQMessage.Key(key.getItemId());
        } catch (Exception e) {}
        byte[] valueBytes = record.getValue();
        //Object value = queue.getTranscoder().decode(valueBytes);
        printKey(keyBytes, key.getQueueId(), key.getItemId(), pkey);
        out.println(byteArrayToHexString(valueBytes));
        if (!iterator.next()) return;
    } catch (Exception e) {
        e.printStackTrace();
        break;
    }
      }
View Full Code Here

TOP

Related Classes of com.cloudhopper.datastore.DataStoreIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.