Package org.hornetq.core.paging.cursor

Examples of org.hornetq.core.paging.cursor.PageSubscription


      Filter filter = FilterImpl.createFilter(filterString);

      long txID = storageManager.generateUniqueID();;
      long queueID = storageManager.generateUniqueID();

      PageSubscription pageSubscription;

      if (filterString != null && filterString.toString().equals(GENERIC_IGNORED_FILTER))
      {
         pageSubscription = null;
      }
      else
      {
         pageSubscription = pagingManager.getPageStore(address)
                                         .getCursorProvier()
                                         .createSubscription(queueID, filter, durable);
      }

      final Queue queue = queueFactory.createQueue(queueID,
                                                   address,
                                                   queueName,
                                                   filter,
                                                   pageSubscription,
                                                   durable,
                                                   temporary);

      binding = new LocalQueueBinding(address, queue, nodeManager.getNodeId());

      if (durable)
      {
         storageManager.addQueueBinding(txID, binding);
      }

      try
      {
         postOffice.addBinding(binding);
         if (durable)
         {
            storageManager.commitBindings(txID);
         }
      }
      catch (Exception e)
      {
         if (durable)
         {
            storageManager.rollbackBindings(txID);
         }
         try
         {
            if (queue!= null)
            {
               queue.close();
            }
            if (pageSubscription != null)
            {
               pageSubscription.destroy();
            }
         }
         catch (Throwable ignored)
         {
            log.error(ignored);
View Full Code Here


               CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
               encoding.decode(buff);

               encoding.position.setRecordID(record.id);

               PageSubscription sub = locateSubscription(encoding.queueID, pageSubscriptions, queueInfos, pagingManager);

               if (sub != null)
               {
                  sub.reloadACK(encoding.position);
               }
               else
               {
                  log.warn("Can't find queue " + encoding.queueID + " while reloading ACKNOWLEDGE_CURSOR");
               }

               break;
            }
            case PAGE_CURSOR_COUNTER_VALUE:
            {
               PageCountRecord encoding = new PageCountRecord();

               encoding.decode(buff);

               PageSubscription sub = locateSubscription(encoding.queueID, pageSubscriptions, queueInfos, pagingManager);

               if (sub != null)
               {
                  sub.getCounter().loadValue(record.id, encoding.value);
               }
               else
               {
                  log.warn("Can't find queue " + encoding.queueID + " while reloading ACKNOWLEDGE_CURSOR");
               }

               break;
            }

            case PAGE_CURSOR_COUNTER_INC:
            {
               PageCountRecordInc encoding = new PageCountRecordInc();

               encoding.decode(buff);

               PageSubscription sub = locateSubscription(encoding.queueID, pageSubscriptions, queueInfos, pagingManager);

               if (sub != null)
               {
                  sub.getCounter().loadInc(record.id, encoding.value);
               }
               else
               {
                  log.warn("Can't find queue " + encoding.queueID + " while reloading ACKNOWLEDGE_CURSOR");
               }

               break;
            }
            default:
            {
               throw new IllegalStateException("Invalid record type " + recordType);
            }
         }

         // This will free up memory sooner. The record is not needed any more
         // and its byte array would consume memory during the load process even though it's not necessary any longer
         // what would delay processing time during load
         records.set(reccount, null);
      }

      // Release the memory as soon as not needed any longer
      records.clear();
      records = null;

      for (Map.Entry<Long, Map<Long, AddMessageRecord>> entry : queueMap.entrySet())
      {
         long queueID = entry.getKey();

         Map<Long, AddMessageRecord> queueRecords = entry.getValue();

         Queue queue = queues.get(queueID);

         if (queue == null)
         {
            log.warn("Message for queue " + queueID + " which does not exist. This message will be ignored.");

            continue;
         }
        
         // Redistribution could install a Redistributor while we are still loading records, what will be an issue with prepared ACKs
         // We make sure te Queue is paused before we reroute values.
         queue.pause();

         Collection<AddMessageRecord> valueRecords = queueRecords.values();
        
         long currentTime = System.currentTimeMillis();

         for (AddMessageRecord record : valueRecords)
         {
            long scheduledDeliveryTime = record.scheduledDeliveryTime;
           
            if (scheduledDeliveryTime != 0 && scheduledDeliveryTime <= currentTime)
            {
               scheduledDeliveryTime = 0;
               record.message.removeProperty(Message.HDR_SCHEDULED_DELIVERY_TIME);
            }

            if (scheduledDeliveryTime != 0)
            {
               record.message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, scheduledDeliveryTime);
            }

            MessageReference ref = postOffice.reroute(record.message, queue, null);

            ref.setDeliveryCount(record.deliveryCount);

            if (scheduledDeliveryTime != 0)
            {
               record.message.removeProperty(Message.HDR_SCHEDULED_DELIVERY_TIME);
            }
         }
      }

      loadPreparedTransactions(postOffice,
                               pagingManager,
                               resourceManager,
                               queues,
                               queueInfos,
                               preparedTransactions,
                               duplicateIDMap,
                               pageSubscriptions);

      for (PageSubscription sub : pageSubscriptions.values())
      {
         sub.getCounter().processReload();
      }

      for (LargeServerMessage msg : largeMessages)
      {
         if (msg.getRefCount() == 0)
View Full Code Here

                                               final Map<Long, PageSubscription> pageSubscriptions,
                                               final Map<Long, QueueBindingInfo> queueInfos,
                                               final PagingManager pagingManager) throws Exception
   {

      PageSubscription subs = pageSubscriptions.get(queueID);
      if (subs == null)
      {
         QueueBindingInfo queueInfo = queueInfos.get(queueID);

         if (queueInfo != null)
View Full Code Here

                  CursorAckRecordEncoding encoding = new CursorAckRecordEncoding();
                  encoding.decode(buff);

                  encoding.position.setRecordID(record.id);

                  PageSubscription sub = locateSubscription(encoding.queueID,
                                                            pageSubscriptions,
                                                            queueInfos,
                                                            pagingManager);

                  if (sub != null)
                  {
                     sub.reloadPreparedACK(tx, encoding.position);
                     referencesToAck.add(new PagedReferenceImpl(encoding.position, null, sub));
                  }
                  else
                  {
                     log.warn("Can't find queue " + encoding.queueID + " while reloading ACKNOWLEDGE_CURSOR");
                  }
                  break;
               }
               case PAGE_CURSOR_COUNTER_VALUE:
               {
                  log.warn("PAGE_CURSOR_COUNTER_VALUE record used on a prepared statement, what shouldn't happen");

                  break;
               }

               case PAGE_CURSOR_COUNTER_INC:
               {
                  PageCountRecordInc encoding = new PageCountRecordInc();

                  encoding.decode(buff);

                  PageSubscription sub = locateSubscription(encoding.queueID,
                                                            pageSubscriptions,
                                                            queueInfos,
                                                            pagingManager);

                  if (sub != null)
                  {
                     sub.getCounter().applyIncrement(tx, record.id, encoding.value);
                  }
                  else
                  {
                     log.warn("Can't find queue " + encoding.queueID + " while reloading ACKNOWLEDGE_CURSOR");
                  }
View Full Code Here

      return pagingStore;
   }

   public synchronized PageSubscription createSubscription(long cursorID, Filter filter, boolean persistent)
   {
      PageSubscription activeCursor = activeCursors.get(cursorID);
      if (activeCursor != null)
      {
         throw new IllegalStateException("Cursor " + cursorID + " had already been created");
      }
View Full Code Here

      if (queue.getPageSubscription() != null)
      {
         queue.getPageSubscription().close();
      }
     
      PageSubscription subs = queue.getPageSubscription();
     
      if (subs != null)
      {
         subs.cleanupEntries(true);
      }
   }
View Full Code Here

                                                                            .toString()
                                                                            .equals(GENERIC_IGNORED_FILTER))
         {
            Filter filter = FilterImpl.createFilter(queueBindingInfo.getFilterString());

            PageSubscription subscription = pagingManager.getPageStore(queueBindingInfo.getAddress())
                                                         .getCursorProvier()
                                                         .createSubscription(queueBindingInfo.getId(), filter, true);

            Queue queue = queueFactory.createQueue(queueBindingInfo.getId(),
                                                   queueBindingInfo.getAddress(),
View Full Code Here

      Filter filter = FilterImpl.createFilter(filterString);

      long txID = storageManager.generateUniqueID();;
      long queueID = storageManager.generateUniqueID();

      PageSubscription pageSubscription;

      if (filterString != null && filterString.toString().equals(GENERIC_IGNORED_FILTER))
      {
         pageSubscription = null;
      }
      else
      {
         pageSubscription = pagingManager.getPageStore(address)
                                         .getCursorProvier()
                                         .createSubscription(queueID, filter, durable);
      }

      final Queue queue = queueFactory.createQueue(queueID,
                                                   address,
                                                   queueName,
                                                   filter,
                                                   pageSubscription,
                                                   durable,
                                                   temporary);

      binding = new LocalQueueBinding(address, queue, nodeManager.getNodeId());

      if (durable)
      {
         storageManager.addQueueBinding(txID, binding);
      }

      try
      {
         postOffice.addBinding(binding);
         if (durable)
         {
            storageManager.commitBindings(txID);
         }
      }
      catch (Exception e)
      {
         if (durable)
         {
            storageManager.rollbackBindings(txID);
         }
         try
         {
            if (queue!= null)
            {
               queue.close();
            }
            if (pageSubscription != null)
            {
               pageSubscription.close();
            }
         }
         catch (Throwable ignored)
         {
            log.error(ignored);
View Full Code Here

      PageCursorProvider cursorProvider = lookupCursorProvider();

      PageCache cache = cursorProvider.getPageCache(new PagePositionImpl(5, 0));

      PageSubscription cursor = cursorProvider.getSubscription(queue.getID());
      PagePosition startingPos = new PagePositionImpl(5, cache.getNumberOfMessages() / 2);
      cursor.bookmark(startingPos);

      // We can't proceed until the operation has finished
      server.getStorageManager().waitOnOperations();
     
      PagedMessage msg = cache.getMessage(startingPos.getMessageNr() + 1);
      msg.initMessage(server.getStorageManager());
      int initialKey = msg.getMessage().getIntProperty("key").intValue();
      int key = initialKey;

      msg = null;

      cache = null;

      LinkedListIterator<PagedReference> iterator = cursor.iterator();

      PagedReference msgCursor = null;
      while ((msgCursor = iterator.next()) != null)
      {
         assertEquals(key++, msgCursor.getMessage().getIntProperty("key").intValue());
      }
      assertEquals(NUM_MESSAGES, key);

      server.stop();

      OperationContextImpl.clearContext();

      createServer();

      cursorProvider = lookupCursorProvider();
      cursor = cursorProvider.getSubscription(queue.getID());
      key = initialKey;
      iterator = cursor.iterator();
      while ((msgCursor = iterator.next()) != null)
      {
         assertEquals(key++, msgCursor.getMessage().getIntProperty("key").intValue());
         cursor.ack(msgCursor);
      }

      forceGC();

      assertTrue(cursorProvider.getCacheSize() < numberOfPages);
View Full Code Here

      System.out.println("NumberOfPages = " + numberOfPages);

      PageCursorProvider cursorProvider = lookupCursorProvider();

      PageSubscription cursor = cursorProvider.getSubscription(queue.getID());

      LinkedListIterator<PagedReference> iter = cursor.iterator();
     
      LinkedListIterator<PagedReference> iter2 = cursor.iterator();
     
      assertTrue(iter.hasNext());
     
      PagedReference msg1 = iter.next();
     
View Full Code Here

TOP

Related Classes of org.hornetq.core.paging.cursor.PageSubscription

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.