Package com.cloudhopper.mq.util

Examples of com.cloudhopper.mq.util.CompositeKey


    }

    public CompositeKey decode(byte[] encoded) {
        int queueId = decodeQueueId(encoded);
        long itemId = decodeItemId(encoded);
        return new CompositeKey(queueId, itemId);
    }
View Full Code Here


    }

    public void preload(DataStoreIterator iterator) throws DataStoreFatalException, QueueFatalException {
  while (iterator.next()) {
      DataStoreIterator.Record record = iterator.getRecord();
      CompositeKey key = priorityKeyUtil.decode(record.getKey());
      PriorityMQMessage<E> element = null;
      try {
    element = priorityTranscoder.decode(record.getValue());
      } catch (Throwable t) {
    throw new QueueFatalException("Unable to decode element with transcoder for queueId " + getId() + ". Perhaps incorrect transcoder?", t);
View Full Code Here

    public void preload(DataStoreIterator iterator) throws DataStoreFatalException, QueueFatalException {
  boolean useBackQueue = true;
  while (iterator.next()) {
      DataStoreIterator.Record record = iterator.getRecord();
      CompositeKey key = keyUtil.decode(record.getKey());

      // use the transcoder to decode the value
      E element = null;
      try {
    element = transcoder.decode(record.getValue());
    //logger.trace("preloaded {}:{}", key, element);
      } catch (Throwable t) {
    throw new QueueFatalException("Unable to decode element with transcoder for queueId " + getId() + ". Perhaps incorrect transcoder?", t);
      }

      // assume the first item is the first itemId
      if (firstItemId < 0) {
    firstItemId = key.getItemId();
      } else {
    // if this current itemId does not follow the lastItemId
    // then this indicates we have a gap and this current itemId
    // is really the first itemId
    if (key.getItemId() > lastItemId+1) {
        // this should only be allowed to happen once, if it happens
        // more than once, then this indicates there is a gap of records
        // that is incorrect and this means this queue is likely bad
        if (!useBackQueue) {
      throw new QueueFatalException("Gap of itemIds for queueId=" + getId() + ". Perhaps bad queue?");
        }
        // the current itemId is actually our first item
        firstItemId = key.getItemId();
       
        // start adding things to the "front" queue
        useBackQueue = false;
    } else if (key.getItemId() < lastItemId+1) {
        throw new DataStoreFatalException("ItemId out of order while loading queue itemId=" + key.getItemId() + " < " + (lastItemId+1));
    } else {
        // key is in the correct order, no issue
    }
      }
      if (useBackQueue) {
    backQueue.add(element);
    //logger.trace("added {} to backQueue", element);
      } else {
    frontQueue.add(element);
    //logger.trace("added {} to frontQueue", element);
      }
      // set this lastItemId to the current itemId
      lastItemId = key.getItemId();
  }
    }
View Full Code Here

      firstNext = false;
      return true;
  }
  if (storeIterator.next()) {
      DataStoreIterator.Record record = storeIterator.getRecord();
      CompositeKey key = keyUtil.decode(record.getKey());
      if (key.getQueueId() != queueId) return false;
      return true;
  } else {
      return false;
  }
    }
View Full Code Here

     */
    private int moveToNextQueue(DataStoreIterator iterator, int currentQueueId) throws DataStoreFatalException {
  do {
      try {
    DataStoreIterator.Record record = iterator.getRecord();
    CompositeKey key = priorityKeyUtil.decode(record.getKey());
    if (key.getQueueId() != currentQueueId) return key.getQueueId();
      } catch (DataStoreFatalException e) {
    //we might not be on the first record?
      }
  } while (iterator.next());
  return -1;
View Full Code Here

    private long lastItemId = -1L;
    private long queueSize = 0L;
    public void preload(DataStoreIterator iterator) throws DataStoreFatalException, QueueFatalException {
  while (iterator.next()) {
      DataStoreIterator.Record record = iterator.getRecord();
      CompositeKey key = keyUtil.decode(record.getKey());
      queueSize++;
      // assume the first item is the first itemId
      if (firstItemId  < 0) {
    firstItemId = key.getItemId();
      } else {
    // if this current itemId does not follow the lastItemId
    // then this indicates we have a gap and this current itemId
    // is really the first itemId
    if (key.getItemId() > lastItemId + 1) {
        // the current itemId is actually our first item
        firstItemId = key.getItemId();
        } else if (key.getItemId() < lastItemId + 1) {
        throw new DataStoreFatalException("ItemId out of order while loading queue itemId=" + key.getItemId() + " < " + (lastItemId + 1));
    } else {
        // key is in the correct order, no issue
    }
      }
      // set this lastItemId to the current itemId
      lastItemId = key.getItemId();
  }
    }
View Full Code Here

    @Override
    public void preload(DataStoreIterator iterator) throws DataStoreFatalException, QueueFatalException {
  int itemsLoaded = 0;
  while (iterator.next()) {
      DataStoreIterator.Record record = iterator.getRecord();
      CompositeKey key = priorityKeyUtil.decode(record.getKey());
      PriorityMQMessage element = null;
      try {
    element = priorityTranscoder.decode(record.getValue());
      } catch (Throwable t) {
    throw new QueueFatalException("Unable to decode element with transcoder for queueId " + getId() + ". Perhaps incorrect transcoder?", t);
View Full Code Here

  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;
    }
View Full Code Here

    @Override
    public void preload(DataStoreIterator iterator) throws DataStoreFatalException, QueueFatalException {
  int itemsLoaded = 0;
  while (iterator.next()) {
      DataStoreIterator.Record record = iterator.getRecord();
      CompositeKey key = priorityKeyUtil.decode(record.getKey());
      PriorityMQMessage element = null;
      try {
    element = priorityTranscoder.decode(record.getValue());
      } catch (Throwable t) {
    throw new QueueFatalException("Unable to decode element with transcoder for queueId " + getId() + ". Perhaps incorrect transcoder?", t);
View Full Code Here

  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:"));
View Full Code Here

TOP

Related Classes of com.cloudhopper.mq.util.CompositeKey

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.