Package org.hornetq.core.paging.cursor

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


      int numberOfPages = addMessages(NUM_MESSAGES, 1024 * 1024);

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

      PagedReference msg;

      LinkedListIterator<PagedReference> iterator = cursor.iterator();
      int key = 0;
      while ((msg = iterator.next()) != null)
      {
         assertEquals(key++, msg.getMessage().getIntProperty("key").intValue());
         cursor.confirmPosition(msg.getPosition());
      }
      assertEquals(NUM_MESSAGES, key);

      server.getStorageManager().waitOnOperations();

View Full Code Here


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

      queue.getPageSubscription().close();

      PagedReference msg;

      LinkedListIterator<PagedReference> iteratorEven = cursorEven.iterator();

      LinkedListIterator<PagedReference> iteratorOdd = cursorOdd.iterator();

      int key = 0;
      while ((msg = iteratorEven.next()) != null)
      {
         System.out.println("Received" + msg);
         assertEquals(key, msg.getMessage().getIntProperty("key").intValue());
         assertTrue(msg.getMessage().getBooleanProperty("even").booleanValue());
         key += 2;
         cursorEven.confirmPosition(msg.getPosition());
      }
      assertEquals(NUM_MESSAGES, key);

      key = 1;
      while ((msg = iteratorOdd.next()) != null)
      {
         assertEquals(key, msg.getMessage().getIntProperty("key").intValue());
         assertFalse(msg.getMessage().getBooleanProperty("even").booleanValue());
         key += 2;
         cursorOdd.confirmPosition(msg.getPosition());
      }
      assertEquals(NUM_MESSAGES + 1, key);

      forceGC();
View Full Code Here

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

      for (int i = 0; i < 1000; i++)
      {
         System.out.println("Reading Msg : " + i);
         PagedReference msg = iterator.next();
         assertNotNull(msg);
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());

         if (i < firstPageSize)
         {
            cursor.ack(msg);
         }
      }
      cursorProvider.printDebug();

      server.getStorageManager().waitOnOperations();
      lookupPageStore(ADDRESS).flushExecutors();

      // needs to clear the context since we are using the same thread over two distinct servers
      // otherwise we will get the old executor on the factory
      OperationContextImpl.clearContext();

      server.stop();

      server.start();

      cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvier().getSubscription(queue.getID());

      iterator = cursor.iterator();

      for (int i = firstPageSize; i < NUM_MESSAGES; i++)
      {
         System.out.println("Received " + i);
         PagedReference msg = iterator.next();
         assertNotNull(msg);
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());

         cursor.ack(msg);

         OperationContextImpl.getContext(null).waitCompletion();
View Full Code Here

      System.out.println("Cursor: " + cursor);
      LinkedListIterator<PagedReference> iterator = cursor.iterator();
      for (int i = 0; i < 100; i++)
      {
         PagedReference msg = iterator.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
         if (i < 10 || i > 20)
         {
            cursor.ack(msg);
         }
      }
     
      server.getStorageManager().waitOnOperations();

      server.stop();

      OperationContextImpl.clearContext();

      server.start();

      cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvier().getSubscription(queue.getID());
      iterator = cursor.iterator();

      for (int i = 10; i <= 20; i++)
      {
         PagedReference msg = iterator.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
         cursor.ack(msg);
      }

      for (int i = 100; i < NUM_MESSAGES; i++)
      {
         PagedReference msg = iterator.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
         cursor.ack(msg);
      }

      server.stop();
      createServer();
View Full Code Here

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

      for (int i = 0; i < 100; i++)
      {
         PagedReference msg = iterator.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
         if (i < 10 || i > 20)
         {
            cursor.ackTx(tx, msg);
         }
      }

      tx.commit();

      server.stop();

      OperationContextImpl.clearContext();

      server.start();

      cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvier().getSubscription(queue.getID());

      tx = new TransactionImpl(server.getStorageManager(), 60 * 1000);
      iterator = cursor.iterator();

      for (int i = 10; i <= 20; i++)
      {
         PagedReference msg = iterator.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
         cursor.ackTx(tx, msg);
      }

      for (int i = 100; i < NUM_MESSAGES; i++)
      {
         PagedReference msg = iterator.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
         cursor.ackTx(tx, msg);
      }

      tx.commit();

View Full Code Here

         msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());

         Assert.assertTrue(pageStore.page(msg, ctx, ctx.getContextListing(ADDRESS)));

         PagedReference readMessage = iterator.next();

         assertNotNull(readMessage);

         assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());

         assertNull(iterator.next());
      }

      server.stop();

      OperationContextImpl.clearContext();

      createServer();

      pageStore = lookupPageStore(ADDRESS);

      cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvier().getSubscription(queue.getID());
      iterator = cursor.iterator();

      for (int i = 0; i < NUM_MESSAGES * 2; i++)
      {
         if (i % 100 == 0)
            System.out.println("Paged " + i);

         if (i >= NUM_MESSAGES)
         {

            HornetQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1l);

            ServerMessage msg = new ServerMessageImpl(i, buffer.writerIndex());
            msg.putIntProperty("key", i);

            msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());

            Assert.assertTrue(pageStore.page(msg, ctx, ctx.getContextListing(ADDRESS)));
         }

         PagedReference readMessage = iterator.next();

         assertNotNull(readMessage);

         assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
      }

      server.stop();

      OperationContextImpl.clearContext();

      createServer();

      pageStore = lookupPageStore(ADDRESS);

      cursor = this.server.getPagingManager().getPageStore(ADDRESS).getCursorProvier().getSubscription(queue.getID());
      iterator = cursor.iterator();

      for (int i = 0; i < NUM_MESSAGES * 3; i++)
      {
         if (i % 100 == 0)
            System.out.println("Paged " + i);

         if (i >= NUM_MESSAGES * 2 - 1)
         {

            HornetQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1l);

            ServerMessage msg = new ServerMessageImpl(i, buffer.writerIndex());
            msg.putIntProperty("key", i + 1);

            msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());

            Assert.assertTrue(pageStore.page(msg, ctx, ctx.getContextListing(ADDRESS)));
         }

         PagedReference readMessage = iterator.next();

         assertNotNull(readMessage);

         cursor.ack(readMessage);

         assertEquals(i, readMessage.getMessage().getIntProperty("key").intValue());
      }

      PagedReference readMessage = iterator.next();

      assertEquals(NUM_MESSAGES * 3, readMessage.getMessage().getIntProperty("key").intValue());

      cursor.ack(readMessage);

      server.getStorageManager().waitOnOperations();

View Full Code Here

      LinkedListIterator<PagedReference> iterator = cursor.iterator();
     
      for (int i = 0 ; i < TOTAL_MSG; i++ )
      {
         assertEquals(0, exceptions.get());
         PagedReference ref = null;
         for (int repeat = 0 ; repeat < 5; repeat++)
         {
            ref = iterator.next();
            if (ref == null)
            {
               Thread.sleep(1000);
            }
            else
            {
               break;
            }
         }
         assertNotNull(ref);
        
         ref.acknowledge();
         assertNotNull(ref);
        
         System.out.println("Consuming " + ref.getMessage().getIntProperty("key"));
         //assertEquals(i, ref.getMessage().getIntProperty("key").intValue());
      }

      assertEquals(0, exceptions.get());
   }
View Full Code Here

      System.out.println("Number of pages - " + pageStore.getNumberOfPages());

      // First consume what's already there without any tx as nothing was committed
      for (int i = 300; i < 400; i++)
      {
         PagedReference pos = iterator.next();
         assertNotNull("Null at position " + i, pos);
         assertEquals(i, pos.getMessage().getIntProperty("key").intValue());
         cursor.ack(pos);
      }

      assertNull(iterator.next());

      cursor.printDebug();
      txCommit.commit();

      txRollback.rollback();
     
      storage.waitOnOperations();

      // Second:after pgtxCommit was done
      for (int i = 200; i < 300; i++)
      {
         PagedReference pos = iterator.next();
         assertNotNull(pos);
         assertEquals(i, pos.getMessage().getIntProperty("key").intValue());
         cursor.ack(pos);
      }

      assertNull(iterator.next());
     
View Full Code Here

      System.out.println("Number of pages - " + pageStore.getNumberOfPages());

      // First consume what's already there without any tx as nothing was committed
      for (int i = 100; i < 200; i++)
      {
         PagedReference pos = iterator.next();
         assertNotNull("Null at position " + i, pos);
         assertEquals(i, pos.getMessage().getIntProperty("key").intValue());
         cursor.ack(pos);
      }

      assertNull(iterator.next());
     
      txLazy.commit();
     
      storage.waitOnOperations();

      for (int i = 0; i < 100; i++)
      {
         PagedReference pos = iterator.next();
         assertNotNull("Null at position " + i, pos);
         assertEquals(i, pos.getMessage().getIntProperty("key").intValue());
         cursor.ack(pos);
      }

      assertNull(iterator.next());
View Full Code Here

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

      queue.getPageSubscription().close();

      PagedReference msg;
      LinkedListIterator<PagedReference> iterator = cursor.iterator();
      LinkedListIterator<PagedReference> iterator2 = cursor2.iterator();
     
      cursor2.bookmark(new PagePositionImpl(1, -1));

      int key = 0;
      while ((msg = iterator.next()) != null)
      {
         System.out.println("key = " + key);
         assertEquals(key++, msg.getMessage().getIntProperty("key").intValue());
         cursor.ack(msg);
      }
      assertEquals(NUM_MESSAGES, key);

      forceGC();

      for (int i = 0; i < 10; i++)
      {
         assertTrue(iterator2.hasNext());
         msg = iterator2.next();
         assertEquals(i, msg.getMessage().getIntProperty("key").intValue());
      }

      assertSame(cursor2.getProvider(), cursorProvider);

      cursor2.close();
View Full Code Here

TOP

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

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.