Package com.fasterxml.uuid.impl

Examples of com.fasterxml.uuid.impl.TimeBasedGenerator


  @Test
  public void testMultithreaded() throws InterruptedException {
    final List<Thread> threads = new ArrayList<Thread>();

    final TimeBasedGenerator timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
    final ConcurrentSkipListSet<String> generatedIds = new ConcurrentSkipListSet<String>();
    final ConcurrentSkipListSet<String> duplicatedIds = new ConcurrentSkipListSet<String>();

    for (int i = 0; i < THREAD_COUNT; i++) {
      Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
          for (int j = 0; j < LOOP_COUNT; j++) {

            String id = timeBasedGenerator.generate().toString();
            boolean wasAdded = generatedIds.add(id);
            if (!wasAdded) {
              duplicatedIds.add(id);
            }
          }
View Full Code Here


        String id = TimebasedOrderFilter.extractId(new DefaultEntry());
        assertThat(id, nullValue());
    }

    private Entry newEntryWithId() throws Exception {
        TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
        Entry e = new DefaultEntry();
        e.add(SchemaConstants.OBJECT_CLASS_ATTRIBUTE, uniqueOc);
        e.add(idAttribute, uuidGenerator.generate().toString());
        return e;
    }
View Full Code Here

    public static String extractId(Entry entry) {
        return LdapUtils.extractAttributeNoEmptyCheck(entry, TimebasedOrderFilter.ID_ATTRIBUTE);
    }

    private static UUID newUUID() {
        TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
        return uuidGenerator.generate();
    }
View Full Code Here

    {
        // this test will attempt to check for reasonable behavior of the
        // generateTimeBasedUUID method
       
        // we need a instance to use
        TimeBasedGenerator uuid_gen = Generators.timeBasedGenerator();
       
        // first check that given a number of calls to generateTimeBasedUUID,
        // all returned UUIDs order after the last returned UUID
        // we'll check this by generating the UUIDs into one array and sorting
        // then in another and checking the order of the two match
        // change the number in the array statement if you want more or less
        // UUIDs to be generated and tested
        UUID uuid_array[] = new UUID[SIZE_OF_TEST_ARRAY];
       
        // before we generate all the uuids, lets get the start time
        long start_time = System.currentTimeMillis();
       
        // now create the array of uuids
        for (int i = 0; i < uuid_array.length; i++)
        {
            uuid_array[i] = uuid_gen.generate();
        }
       
        // now capture the end time
        long end_time = System.currentTimeMillis();
       
View Full Code Here

        // generateTimeBasedUUID(EthernetAddress) method
        EthernetAddress ethernet_address =
            new EthernetAddress("87:F5:93:06:D3:0C");
       
        // we need a instance to use
        TimeBasedGenerator uuid_gen = Generators.timeBasedGenerator(ethernet_address);
       
        // check that given a number of calls to generateTimeBasedUUID,
        // all returned UUIDs order after the last returned UUID
        // we'll check this by generating the UUIDs into one array and sorting
        // then in another and checking the order of the two match
        // change the number in the array statement if you want more or less
        // UUIDs to be generated and tested
        UUID uuid_array[] = new UUID[SIZE_OF_TEST_ARRAY];
       
        // before we generate all the uuids, lets get the start time
        long start_time = System.currentTimeMillis();
       
        // now create the array of uuids
        for (int i = 0; i < uuid_array.length; i++) {
            uuid_array[i] = uuid_gen.generate();
        }
       
        // now capture the end time
        long end_time = System.currentTimeMillis();
       
View Full Code Here

            UUIDTimer timer)
    {
        if (timer == null) {
            timer = sharedTimer();
        }
        return new TimeBasedGenerator(ethernetAddress, timer);
    }
View Full Code Here

//        UUID namespaceForNamed = NAMESPACE;
        UUID namespaceForNamed = null;

        final RandomBasedGenerator secureRandomGen = Generators.randomBasedGenerator();
        final RandomBasedGenerator utilRandomGen = Generators.randomBasedGenerator(new java.util.Random(123));
        final TimeBasedGenerator timeGenPlain = Generators.timeBasedGenerator(nic);
        final TimeBasedGenerator timeGenSynced = Generators.timeBasedGenerator(nic,
                new com.fasterxml.uuid.ext.FileBasedTimestampSynchronizer());
        final StringArgGenerator nameGen = Generators.nameBasedGenerator(namespaceForNamed);
       
        while (true) {
            try Thread.sleep(100L); } catch (InterruptedException ie) { }
View Full Code Here

        // Let's stress-test it...
        sync.setUpdateInterval(2000L);

        // must have a NIC for this to work, should be ok:
        EthernetAddress eth = EthernetAddress.fromInterface();
        TimeBasedGenerator gen = Generators.timeBasedGenerator(eth, sync);

        int counter = 1;
        while (true) {
            UUID uuid = gen.generate();
      // Default one is for convenient output
            System.out.println("#"+counter+" -> "+uuid);

      /* This allows lexical sorting by uuid... (not very useful,
       * since 'real' UUID ordering is not lexical)
View Full Code Here

TOP

Related Classes of com.fasterxml.uuid.impl.TimeBasedGenerator

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.