net.jini.id.Uuid类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中net.jini.id.Uuid类的一些代码示例,展示了Uuid类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uuid类的具体详情如下:
包路径:net.jini.id.Uuid
类名称:Uuid

Uuid介绍

[英]A 128-bit value to serve as a universally unique identifier. Two Uuids are equal if they have the same 128-bit value. Uuid instances can be created using the static methods of the UuidFactory class.

The design of this class is intended to support the use of universally unique identifiers that

  1. have a high likelihood of uniqueness over space and time and
  2. are computationally difficult to guess.
    The second goal is intended to support the treatment of data containing a Uuid as a capability. Note that not all defined Uuid values imply a generation algorithm that supports this goal.

The most significant 64 bits of the value can be decomposed into unsigned integer fields according to the following bit masks:

0xFFFFFFFF00000000	time_low 
0x00000000FFFF0000	time_mid 
0x000000000000F000	version 
0x0000000000000FFF	time_hi

The least significant 64 bits of the value can be decomposed into unsigned integer fields according to the following bit masks:

0xC000000000000000	variant 
0x3FFF000000000000	clock_seq 
0x0000FFFFFFFFFFFF	node

This specification defines the meaning (and implies aspects of the generation algorithm) of Uuid values if the variant field is 0x2 and the version field is either 0x1 or 0x4.

If the version field is 0x1, then

  • the time_low, time_mid, and time_hi fields are the least, middle, and most significant bits (respectively) of a 60-bit timestamp of 100-nanosecond intervals since midnight, October 15, 1582 UTC,
  • the clock_seq field is a 14-bit number chosen to help avoid duplicate Uuid values in the event of a changed node address or a backward system clock adjustment (such as a random number when in doubt, or the previously used number incremented by one if just a backward clock adjustment is detected), and
  • the node field is an IEEE 802 address (a 48-bit value).

As an alternative to an IEEE 802 address (such as if one is not available to the generation algorithm), the node field may also be a 48-bit number for which the most significant bit is set to 1 and the remaining bits were produced from a cryptographically strong random sequence.

If the version field is 0x4, then the time_low, time_mid, time_hi, clock_seq, and node fields are values that were produced from a cryptographically strong random sequence.

Only Uuid values with a version field of 0x4 are considered computationally difficult to guess. A Uuid value with a version field of 0x1 should not be treated as a capability.

A subclass of Uuid must not implement Externalizable; this restriction is enforced by this class's constructor and readObject methods.
[中]作为通用唯一标识符的128位值。如果两个Uuid具有相同的128位值,则它们相等。Uuid实例可以使用UUIFactory类的静态方法创建。
此类的设计旨在支持使用通用唯一标识符
1.在空间和时间上具有高度的唯一性
1.计算上很难猜测。
第二个目标旨在支持将包含Uuid的数据作为一种功能进行处理。请注意,并非所有定义的Uuid值都意味着支持此目标的生成算法。
值的最高有效64位可以根据以下位掩码分解为无符号整数字段:

0xFFFFFFFF00000000	time_low 
0x00000000FFFF0000	time_mid 
0x000000000000F000	version 
0x0000000000000FFF	time_hi

该值的最低有效64位可根据以下位掩码分解为无符号整数字段:

0xC000000000000000	variant 
0x3FFF000000000000	clock_seq 
0x0000FFFFFFFFFFFF	node

如果变量字段为0x2version字段为0x10x4,则本规范定义Uuid值的含义(并暗示生成算法的各个方面)。
如果version字段为0x1,则
*time_lowtime_midtime_hi字段分别是自1582年10月15日UTC午夜以来,间隔为100纳秒的60位时间戳的最低、中间和最高有效位,
*clock_seq字段是一个14位的数字,选择它有助于避免在节点地址更改或向后系统时钟调整的情况下出现重复的Uuid值(如有疑问时出现随机数,或者如果检测到向后时钟调整,则之前使用的数字增加1),以及
*node字段是IEEE 802地址(48位值)。
作为IEEE 802地址的替代(例如,如果生成算法没有可用的地址,node字段也可以是48位的数字,其中最高有效位设置为1,其余位由加密强随机序列生成。
如果version字段为0x4,则time_lowtime_midtime_hiclock_seqnode字段是从加密强随机序列生成的值。
只有Uuid字段为0x4Uuid值在计算上被认为是难以猜测的。Uuid值的version字段为0x1时,不应将其视为功能。
Uuid的子类不能实现Externalizable;此限制由此类的构造函数和readObject方法强制执行。

代码示例

代码示例来源:origin: au.net.zeus.jgdms/jgdms-lib-dl

public boolean canBatch(Lease lease) {
if (lease instanceof LandlordLease) {
   return landlordUuid.equals(((LandlordLease)lease).landlordUuid);
}
    return false;
}

代码示例来源:origin: xap/xap

/**
 * Proxies for servers with the same <code>proxyID</code> are considered equal.
 */
@Override
public boolean equals(Object o) {
  //return ReferentUuids.compare(this,o);
  if (this == o)
    return true;
  if (o instanceof TxnMgrProxy) {
    TxnMgrProxy other = (TxnMgrProxy) o;
    return proxyID.getLeastSignificantBits() == other.proxyID.getLeastSignificantBits() &&
        proxyID.getMostSignificantBits() == other.proxyID.getMostSignificantBits();
  } else
    return false;
}

代码示例来源:origin: au.net.zeus.jgdms.fiddler/fiddler-dl

/** 
 * For any instance of this class, returns the hashcode value generated
 * by the hashCode method of the registration ID associated with the
 * current instance of this proxy.
 *
 * @return <code>int</code> value representing the hashcode for an
 *         instance of this class.
 */
public int hashCode() {
return registrationID.hashCode();
}

代码示例来源:origin: xap/xap

private Uuid createLeaseUuid(long txnId) {
  return new Uuid(topUuid.getLeastSignificantBits(),
      txnId);
    /*return UuidFactory.create(
    topUuid.getLeastSignificantBits(),
    txnId);*/
}

代码示例来源:origin: xap/xap

_dummyLeaseUuid = new Uuid(topUuid.getLeastSignificantBits(),
    -1);
if (initLogger.isLoggable(Level.FINEST)) {
      new ServiceID(topUuid.getMostSignificantBits(),
          topUuid.getLeastSignificantBits()),
      attributesFor());

代码示例来源:origin: xap/xap

@Override
public String toString() {
  return "TxnMgrProxy [proxyId=" + proxyID.toString() + ", isDirect=" + (direct != null) + "]";
}

代码示例来源:origin: xap/xap

private Long getLeaseTid(Uuid uuid) {
  // Extract the txn id from the lower bits of the uuid
  return new Long(uuid.getLeastSignificantBits());
}

代码示例来源:origin: xap/xap

/**
 * @throws InvalidObjectException if the class of this object implements <code>Externalizable</code>
 **/
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException {
  if (!isValid()) {
    throw new InvalidObjectException("invalid class: " +
        this.getClass().getName());
  }
  in.defaultReadObject();
}

代码示例来源:origin: xap/xap

toHexString(bits0 >>> 32, 8) + "-" +
    toHexString(bits0 >>> 16, 4) + "-" +
    toHexString(bits0 >>> 0, 4) + "-" +
    toHexString(bits1 >>> 48, 4) + "-" +
    toHexString(bits1 >>> 0, 12);

代码示例来源:origin: xap/xap

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  if (in.readBoolean())
    backend = (TxnManager) in.readObject();
  proxyID = new Uuid(in.readLong(), in.readLong());
}

代码示例来源:origin: au.net.zeus.jgdms.mercury/mercury-service

/**
 * Utility method that returns the associated File object
 * for the given Uuid's persistence directory 
 */
static File getEventLogPath(String parent, Uuid uuid) {
  return new File(parent, uuid.toString());
}

代码示例来源:origin: au.net.zeus.jgdms/jgdms-platform

/**
 * @throws InvalidObjectException if the class of this object
 * implements <code>Externalizable</code>
 * @param in ObjectInputStream
 * @throws ClassNotFoundException if class not found.
 * @throws IOException if a problem occurs during de-serialization.
 **/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
if (!isValid()) {
  throw new InvalidObjectException("invalid class: " +
           this.getClass().getName());
}
in.defaultReadObject();
}

代码示例来源:origin: au.net.zeus.jgdms/jgdms-platform

toHexString(bits0 >>> 32, 8) + "-" +
toHexString(bits0 >>> 16, 4) + "-" +
toHexString(bits0 >>>  0, 4) + "-" +
toHexString(bits1 >>> 48, 4) + "-" +
toHexString(bits1 >>>  0, 12);

代码示例来源:origin: au.net.zeus.jgdms.mercury/mercury-service

/**
 * Primary sort by leaseExpiration, secondary by leaseID.  The
 * secondary sort is immaterial, except to ensure a total order
 * (required by TreeMap).
 */
public synchronized int compareTo(Object obj) {
  ServiceRegistration reg = (ServiceRegistration)obj;
  if (this == reg)
    return 0;
  if ( expiration < reg.expiration ||
     (expiration == reg.expiration &&
     (   (cookie.getMostSignificantBits() < 
     reg.cookie.getMostSignificantBits())
     && (cookie.getLeastSignificantBits() < 
     reg.cookie.getLeastSignificantBits()) ) ))
    return -1;
  return 1;
}

代码示例来源:origin: au.net.zeus.jgdms.mercury/mercury-service

@Override
public boolean equals(Object o){
if (this == o) return true;
if (!(o instanceof ServiceRegistration)) return false;
ServiceRegistration that = (ServiceRegistration) o;
if (!cookie.equals(that.cookie)) return false;
return (expiration == that.expiration);
}

代码示例来源:origin: xap/xap

/**
 * Constructor for use by getInstance(), ConstrainableAdminProxy.
 */
public ServiceAdminProxy(ServiceAdmin adminImpl, Uuid uuid) {
  //super(admin, uuid);
  this.adminImpl = adminImpl;
  this.uuid = uuid;
  this.hashCode = uuid.hashCode();
}

代码示例来源:origin: au.net.zeus.jgdms.mercury/mercury-service

@Override
public String toString () {
  return getClass().getName() + ":" + cookie.toString();
}

代码示例来源:origin: au.net.zeus.jgdms/jgdms-platform

/**
 * Creates a new <code>Uuid</code> with the specified 128-bit
 * value.
 *
 * @param bits0 the most significant 64 bits of the 128-bit value
 *
 * @param bits1 the least significant 64 bits of the 128-bit value
 *
 * @throws SecurityException if the class of this object
 * implements <code>Externalizable</code>
 **/
protected Uuid(long bits0, long bits1) { //This isn't the greatest security solution
if (!isValid()) {
  throw new SecurityException("invalid class: " +
        this.getClass().getName());
}
this.bits0 = bits0;
this.bits1 = bits1;
}

代码示例来源:origin: au.net.zeus.jgdms.norm/norm-service

@Override
public ServiceID serviceID() throws IOException {
return new ServiceID(serverUuid.getMostSignificantBits(),
      serverUuid.getLeastSignificantBits());
}

代码示例来源:origin: xap/xap

public boolean canBatch(Lease lease) {
  if (lease instanceof LandlordLease) {
    return landlordUuid.equals(((LandlordLease) lease).landlordUuid);
  }
  return false;
}

相关文章