Package org.hornetq.utils

Examples of org.hornetq.utils.TimeAndCounterIDGenerator


   {
      if (storage == null)
      {
         if (coreConfig.isPersistenceEnabled())
         {
            storage = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(),
                                                       server.getConfiguration(),
                                                       server.getReplicationManager());
         }
         else
         {
View Full Code Here


   // Public --------------------------------------------------------

   public void testCalculation()
   {
      TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();
      long max = 11000;

      long lastNr = 0;

      for (long i = 0; i < max; i++)
      {
         long seqNr = seq.generateID();

         Assert.assertTrue("The sequence generator should aways generate crescent numbers", seqNr > lastNr);

         lastNr = seqNr;
      }
View Full Code Here

   }

   public void testCalculationRefresh()
   {
      TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();

      long id1 = seq.generateID();
      Assert.assertEquals(1, id1 & 0xffff);
      Assert.assertEquals(2, seq.generateID() & 0xffff);

      seq.refresh();

      long id2 = seq.generateID();

      Assert.assertTrue(id2 > id1);

      Assert.assertEquals(1, id2 & 0xffff);
View Full Code Here

   public void testCalculationOnMultiThread() throws Throwable
   {
      final ConcurrentHashSet<Long> hashSet = new ConcurrentHashSet<Long>();

      final TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();

      System.out.println("Time = " + TimeAndCounterIDGeneratorTest.hex(System.currentTimeMillis()) + ", " + seq);

      final int NUMBER_OF_THREADS = 100;

      final int NUMBER_OF_IDS = 10;

      final CountDownLatch latchAlign = new CountDownLatch(NUMBER_OF_THREADS);

      final CountDownLatch latchStart = new CountDownLatch(1);

      class T1 extends Thread
      {
         Throwable e;

         @Override
         public void run()
         {
            try
            {
               latchAlign.countDown();
               latchStart.await();

               long lastValue = 0l;
               for (int i = 0; i < NUMBER_OF_IDS; i++)
               {
                  long value = seq.generateID();
                  Assert.assertTrue(TimeAndCounterIDGeneratorTest.hex(value) + " should be greater than " +
                                    TimeAndCounterIDGeneratorTest.hex(lastValue) +
                                    " on seq " +
                                    seq.toString(), value > lastValue);
                  lastValue = value;

                  hashSet.add(value);
               }
            }
View Full Code Here

   public void testWrapID() throws Throwable
   {
      final ConcurrentHashSet<Long> hashSet = new org.hornetq.utils.ConcurrentHashSet<Long>();

      TimeAndCounterIDGenerator seq = new TimeAndCounterIDGenerator();

      System.out.println("Current Time = " + TimeAndCounterIDGeneratorTest.hex(System.currentTimeMillis()) + " " + seq);

      seq.setInternalDate(System.currentTimeMillis() + 10000l); // 10 seconds in the future

      seq.setInternalID(TimeAndCounterIDGenerator.ID_MASK); // 1 ID about to explode

      try
      {
         // This is simulating a situation where we generated more than 268 million messages on the same time interval
         seq.generateID();
         Assert.fail("It was supposed to throw an exception, as the counter was set to explode on this test");
      }
      catch (Exception e)
      {
      }

      seq = new TimeAndCounterIDGenerator();

      seq.setInternalDate(System.currentTimeMillis() - 10000l); // 10 seconds in the past

      long timeMark = seq.getInternalTimeMark();

      seq.setInternalID(TimeAndCounterIDGenerator.ID_MASK); // 1 ID about to explode

      // This is ok... the time portion would be added to the next one generated 10 seconds ago
      seq.generateID();

      Assert.assertTrue(TimeAndCounterIDGeneratorTest.hex(timeMark) + " < " +
                                 TimeAndCounterIDGeneratorTest.hex(seq.getInternalTimeMark()),
                        timeMark < seq.getInternalTimeMark());
   }
View Full Code Here

    */
   protected void createJMSStorage() throws Exception
   {
      Configuration configuration = createDefaultConfig();

      jmsJournal = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(), configuration, null);

      jmsJournal.start();

      jmsJournal.load();
   }
View Full Code Here

   // Inner classes -------------------------------------------------

   public static void main(final String arg[])
   {
      TimeAndCounterIDGenerator idgenerator = new TimeAndCounterIDGenerator();
      try
      {
         SequentialFileFactory fileFactory = new AIOSequentialFileFactory("/tmp"); // any dir you want
         // SequentialFileFactory fileFactory = new NIOSequentialFileFactory("/tmp"); // any dir you want
         JournalImpl journalExample = new JournalImpl(10 * 1024 * 1024, // 10M.. we believe that's the usual cilinder
                                                      // bufferSize.. not an exact science here
                                                      2, // number of files pre-allocated
                                                      0,
                                                      0,
                                                      fileFactory, // AIO or NIO
                                                      "exjournal", // file name
                                                      "dat", // extension
                                                      10000); // it's like a semaphore for callback on the AIO layer

         ArrayList<RecordInfo> committedRecords = new ArrayList<RecordInfo>();
         ArrayList<PreparedTransactionInfo> preparedTransactions = new ArrayList<PreparedTransactionInfo>();
         journalExample.start();
         System.out.println("Loading records and creating data files");
         journalExample.load(committedRecords, preparedTransactions, null);

         System.out.println("Loaded Record List:");

         for (RecordInfo record : committedRecords)
         {
            System.out.println("Record id = " + record.id +
                               " userType = " +
                               record.userRecordType +
                               " with " +
                               record.data.length +
                               " bytes is stored on the journal");
         }

         System.out.println("Adding Records:");

         for (int i = 0; i < 10; i++)
         {
            journalExample.appendAddRecord(idgenerator.generateID(), (byte)1, new byte[] { 0,
                                                                                          1,
                                                                                          2,
                                                                                          0,
                                                                                          1,
                                                                                          2,
                                                                                          0,
                                                                                          1,
                                                                                          2,
                                                                                          0,
                                                                                          1,
                                                                                          2,
                                                                                          0,
                                                                                          1,
                                                                                          2,
                                                                                          0,
                                                                                          1,
                                                                                          2,
                                                                                          0,
                                                                                          1,
                                                                                          2 }, false);
         }

         long tx = idgenerator.generateID(); // some id generation system

         for (int i = 0; i < 100; i++)
         {
            journalExample.appendAddRecordTransactional(tx, idgenerator.generateID(), (byte)2, new byte[] { 0,
                                                                                                           1,
                                                                                                           2,
                                                                                                           0,
                                                                                                           1,
                                                                                                           2,
View Full Code Here

   {
      if (storage == null)
      {
         if (coreConfig.isPersistenceEnabled())
         {
            storage = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(),
                                                       server.getConfiguration(),
                                                       server.getReplicationManager());
         }
         else
         {
View Full Code Here

   {
      if (storage == null)
      {
         if (coreConfig.isPersistenceEnabled())
         {
            storage = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(),
                                                       server.getConfiguration(),
                                                       server.getReplicationManager());
         }
         else
         {
View Full Code Here

   {
      if (storage == null)
      {
         if (coreConfig.isPersistenceEnabled())
         {
            storage = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(),
                                                       server.getConfiguration(),
                                                       server.getReplicationManager());
         }
         else
         {
View Full Code Here

TOP

Related Classes of org.hornetq.utils.TimeAndCounterIDGenerator

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.