コード例 #1
0
        /**
         * Method that can (and should) be called once right after getting
         * the instance, to ensure that system time stamp values used are
         * valid (with respect to values used earlier by JUG instances), and
         * to use file-lock based synchronization mechanism to prevent multiple
         * JVMs from running conflicting instances of JUG (first one to be
         * started wins on contention). It can also be called to stop
         * synchronization by calling it with argument null, although such
         * usage is strongly discouraged (ie. it's a good idea to either never
         * use synchronization, or always; but not to mix modes).
         *<p>
         * Caller needs to instantiate an instance of
         * {@link TimestampSynchronizer}; currently the only standard
         * implementation is
         * {@link org.safehaus.uuid.ext.FileBasedTimestampSynchronizer} (which
         * is JDK 1.4+).
         *<p>
         * Note: since the generator instance is a singleton, calling this
         * method will always cause all generation to be synchronized using
         * the specified method.
         *
         * @param sync Synchronizer instance to use for synchronization.
         */

        public void SynchronizeExternally(TimestampSynchronizer sync)
        {
            lock (mTimerLock)
            {
                if (mTimer == null)
                {
                    mTimer = new UUIDTimer(GetRandomNumberGenerator());
                }
                mTimer.SetSynchronizer(sync);
            }
        }
コード例 #2
0
        /**
         * Method for generating time based UUIDs.
         *
         * @param addr Hardware address (802.1) to use for generating
         *   spatially unique part of UUID. If system has more than one NIC,
         *   any address is usable. If no NIC is available (or its address
         *   not accessible; often the case with java apps), a randomly
         *   generated broadcast address is acceptable. If so, use the
         *   alternative method that takes no arguments.
         *
         * @return UUID generated using time based method
         */
        public UUID GenerateTimeBasedUUID(PhysicalAddress addr)
        {
            byte[] contents = new byte[16];

            addr.GetAddressBytes();

            lock (mTimerLock)
            {
                if (mTimer == null)
                {
                    mTimer = new UUIDTimer(GetRandomNumberGenerator());
                }

                mTimer.GetTimestamp(contents);
            }

            return(new UUID(UUID.TYPE_TIME_BASED, contents));
        }
コード例 #3
0
 /**
  * Method that can (and should) be called once right after getting
  * the instance, to ensure that system time stamp values used are
  * valid (with respect to values used earlier by JUG instances), and
  * to use file-lock based synchronization mechanism to prevent multiple
  * JVMs from running conflicting instances of JUG (first one to be
  * started wins on contention). It can also be called to stop
  * synchronization by calling it with argument null, although such
  * usage is strongly discouraged (ie. it's a good idea to either never
  * use synchronization, or always; but not to mix modes).
  *<p>
  * Caller needs to instantiate an instance of
  * {@link TimestampSynchronizer}; currently the only standard
  * implementation is
  * {@link org.safehaus.uuid.ext.FileBasedTimestampSynchronizer} (which
  * is JDK 1.4+).
  *<p>
  * Note: since the generator instance is a singleton, calling this
  * method will always cause all generation to be synchronized using
  * the specified method.
  *
  * @param sync Synchronizer instance to use for synchronization.
  */
 public void SynchronizeExternally(TimestampSynchronizer sync)
 {
     lock (mTimerLock)
     {
         if (mTimer == null)
         {
             mTimer = new UUIDTimer(GetRandomNumberGenerator());
         }
         mTimer.SetSynchronizer(sync);
     }
 }
コード例 #4
0
        /**
         * Method for generating time based UUIDs.
         *
         * @param addr Hardware address (802.1) to use for generating
         *   spatially unique part of UUID. If system has more than one NIC,
         *   any address is usable. If no NIC is available (or its address
         *   not accessible; often the case with java apps), a randomly
         *   generated broadcast address is acceptable. If so, use the
         *   alternative method that takes no arguments.
         *
         * @return UUID generated using time based method
         */
        public UUID GenerateTimeBasedUUID(PhysicalAddress addr)
        {
            byte[] contents = new byte[16];

              var addrBytes = addr.GetAddressBytes();
                Array.ConstrainedCopy(addrBytes, 0, contents, 10, addrBytes.Length);

            lock (mTimerLock)
            {
                if (mTimer == null)
                {
                    mTimer = new UUIDTimer(GetRandomNumberGenerator());
                }

                mTimer.GetTimestamp(contents);
            }

            return new UUID(UUID.TYPE_TIME_BASED, contents);
        }
コード例 #5
0
        /**
         * Method for generating time based UUIDs.
         *
         * @param addr Hardware address (802.1) to use for generating
         *   spatially unique part of UUID. If system has more than one NIC,
         *   any address is usable. If no NIC is available (or its address
         *   not accessible; often the case with java apps), a randomly
         *   generated broadcast address is acceptable. If so, use the
         *   alternative method that takes no arguments.
         *
         * @return UUID generated using time based method
         */
        public UUID GenerateTimeBasedUUID(PhysicalAddress addr)
        {
            byte[] contents = new byte[16];

            addr.GetAddressBytes().CopyTo(contents, 10);

            lock (mTimerLock)
            {
                if (mTimer == null)
                {
                    mTimer = new UUIDTimer(GetRandomNumberGenerator());
                }

                mTimer.GetTimestamp(contents);
            }

            return new UUID(UUID.TYPE_TIME_BASED, contents);
        }