本文整理汇总了Java中com.fasterxml.uuid.Generators类的典型用法代码示例。如果您正苦于以下问题:Java Generators类的具体用法?Java Generators怎么用?Java Generators使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Generators类属于com.fasterxml.uuid包,在下文中一共展示了Generators类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureGeneratorInitialized
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
private static void ensureGeneratorInitialized() {
if (timeGenerator == null) {
synchronized (UUIDUtils.class) {
if (timeGenerator == null) {
timeGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
}
}
}
if (randomGenerator == null) {
synchronized (com.fasterxml.uuid.UUIDGenerator.class) {
if (randomGenerator == null) {
randomGenerator = Generators.randomBasedGenerator();
}
}
}
}
示例2: shortUuid
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
/**
* Generate short version random UUID
*
* @return UUID
*/
public static String shortUuid() {
RandomBasedGenerator generator = Generators.randomBasedGenerator();
UUID uuid = generator.generate();
// https://gist.github.com/LeeSanghoon/5811136
long l = ByteBuffer.wrap(uuid.toString().getBytes()).getLong();
return Long.toString(l, Character.MAX_RADIX);
}
示例3: toJSONObject
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
public JSONObject toJSONObject() throws JSONException {
JSONObject object = new JSONObject();
object.put("type", type);
object.put("name", name);
object.put("failures", failuresToJSON());
object.put("status", status);
if ( index == null ) {
globalID++;
index = Generators.timeBasedGenerator().generate();
}
object.put("tindex", index);
object.put("series", getSeries());
if(parent != null)
object.put("parent",parent.toJSONObject());
object.put("transplantationPoint", CtElemToJSON(transplantationPoint));
return object;
}
示例4: toJSONObject
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
public JSONObject toJSONObject() throws JSONException {
JSONObject object = new JSONObject();
object.put("type", type);
object.put("name", name);
object.put("failures", failuresToJSON());
object.put("status", status);
if ( index == null ) {
globalID++;
index = Generators.timeBasedGenerator().generate();
}
object.put("tindex", index);
object.put("series", getSeries());
if(parent != null)
object.put("parent",parent.toJSONObject());
return object;
}
示例5: preStart
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
/**
* Establishes a connection with the webtrends stream api
* @see akka.actor.UntypedActor#preStart()
*/
public void preStart() throws Exception {
// initialize the uuid generator which is based on time and ethernet address
this.uuidGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
// authenticate with the webtrends service
WebtrendsTokenRequest tokenRequest = new WebtrendsTokenRequest(this.authUrl, this.authAudience, this.authScope, this.clientId, this.clientSecret);
this.oAuthToken = tokenRequest.execute();
// initialize the webtrends stream socket client and connect the listener
this.webtrendsStreamSocketClient = new WebSocketClient();
try {
this.webtrendsStreamSocketClient.start();
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
this.webtrendsStreamSocketClient.connect(this, new URI(this.eventStreamUrl), upgradeRequest);
await(5, TimeUnit.SECONDS);
} catch(Exception e) {
throw new RuntimeException("Unable to connect to web socket: " + e.getMessage(), e);
}
this.componentRegistryRef.tell(new ComponentRegistrationMessage(EVENT_SOURCE_ID, ComponentType.STREAM_LISTENER, getSelf()), getSelf());
}
示例6: getUuid
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
/**
*
* @return a time-based UUID, reorganized so that the time-based bits are at the front, , i.e., a bunch of UUIDs
* coming from the same server are more or less sequential in the first four bytes, for better insertion speeds.
*
* @see <a href="https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/">
* https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/
* </a>
*
*/
public static UUID getUuid()
{
String baseUuidString = Generators.timeBasedGenerator().generate().toString();
String[] parts = baseUuidString.split("-");
String sortedUuidString = new StringBuilder(36).
append(parts[2]).
append(parts[1]).
append("-").
append(parts[0].substring(0, 4)).
append("-").
append(parts[0].substring(4, 8)).
append("-").
append(parts[3]).
append("-").
append(parts[4]).
toString();
return UUID.fromString(sortedUuidString);
}
示例7: shortUuid
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
/**
* Generate short version UUID from given uri
*
* @param uri Uri/Url
* @return UUID
*/
public static String shortUuid(URI uri) {
NameBasedGenerator generator = Generators.nameBasedGenerator(NameBasedGenerator.NAMESPACE_URL);
UUID uuid = generator.generate(uri.toString());
// https://gist.github.com/LeeSanghoon/5811136
long l = ByteBuffer.wrap(uuid.toString().getBytes()).getLong();
return Long.toString(l, Character.MAX_RADIX);
}
示例8: ensureGeneratorInitialized
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
protected void ensureGeneratorInitialized() {
if (timeBasedGenerator == null) {
synchronized (UuidIdGenerator.class) {
if (timeBasedGenerator == null) {
timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
}
}
}
}
示例9: ensureGeneratorInitialized
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
protected void ensureGeneratorInitialized() {
if (timeBasedGenerator == null) {
synchronized (StrongUuidGenerator.class) {
if (timeBasedGenerator == null) {
timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
}
}
}
}
示例10: ensureGeneratorInitialized
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
protected void ensureGeneratorInitialized() {
if (timeBasedGenerator == null) {
synchronized (StrongUuidGenerator.class) {
if (timeBasedGenerator == null) {
timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
}
}
}
}
示例11: CoordinationEntryEvent
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
/**
* Constructor.
* @param cacheId - cacheId
* @param entityName - entityName
* @param key - key
* @param eventType - eventType
* @param uuidUtils - uuidUtils
*/
public CoordinationEntryEvent(UUID cacheId, final String entityName,
final K key, final EventType eventType,
final UuidUtils uuidUtils) {
this.cacheId = cacheId;
this.entityName = entityName;
this.eventType = eventType;
this.key = key;
uniqueIdType1 = Generators.timeBasedGenerator().generate(); // TimeUUID
uniqueIdTime = new Date(uuidUtils.toUnixTimestamp(uniqueIdType1));
}
示例12: testTimestamps
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
@Test
public void testTimestamps() throws Exception {
final UUID uuid = Generators.timeBasedGenerator().generate();
final long unixTimestamp = uuidUtils.toUnixTimestamp(uuid);
final long nowTime = System.currentTimeMillis();
LOG.info("UnixMsFromUUID=" + unixTimestamp + ", nowMs=" + nowTime + ", delta=" + (nowTime - unixTimestamp));
final long deltaNowEvent1 = Math.abs(nowTime - unixTimestamp);
assertTrue(deltaNowEvent1 <= 5);
}
示例13: getUuid
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
@Test
public void getUuid() {
UUID uuid = Generators.randomBasedGenerator().generate();
System.out.println(uuid.toString());
uuid = Generators.timeBasedGenerator().generate();
System.out.println(uuid.toString());
}
示例14: getValidUUI
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
/**
* Takes a string and returns a valid UUI from the string if such string is a valid
* UUI. Otherwise, generates a new UUI
*
* @param uuid
* @return
*/
private UUID getValidUUI(String uuid) {
if (uuid == null) return Generators.timeBasedGenerator().generate();
try {
UUID fromStringUUID = UUID.fromString(uuid);
String toStringUUID = fromStringUUID.toString();
if (toStringUUID.equals(uuid)) return fromStringUUID;
} catch (IllegalArgumentException e) {
return Generators.timeBasedGenerator().generate();
}
return Generators.timeBasedGenerator().generate();
}
示例15: getUuidGenerator
import com.fasterxml.uuid.Generators; //导入依赖的package包/类
@Override
public TimeBasedGenerator getUuidGenerator() {
if (uuidGenerator == null) {
EthernetAddress nic = EthernetAddress.fromInterface();
if (nic == null) {
// construct address with a random number
nic = EthernetAddress.constructMulticastAddress();
}
uuidGenerator = Generators.timeBasedGenerator(nic);
}
return uuidGenerator;
}