Package org.hornetq.utils

Examples of org.hornetq.utils.TimeAndCounterIDGenerator


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

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

      jmsJournal.start();
     
      jmsJournal.load();
   }
View Full Code Here


      conf.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
      server = HornetQServers.newHornetQServer(conf, mbeanServer, false);

      context = new InVMContext();
     
      JMSStorageManager storage = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(),
                                                 server.getConfiguration(),
                                                 server.getReplicationManager());
     
      serverManager = new JMSServerManagerImpl(server, null, storage);
      serverManager.setContext(context);
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

   {
      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

   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

   // 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

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.