/** * @exclude * Constructs a new FlexClient instance. * * @param manager The FlexClientManager managing this instance. */ public FlexClient(FlexClientManager manager) { this(manager, UUIDUtils.createUUID()); }
private static String createInsecureUUID() { StringBuffer s = new StringBuffer(36); appendHexString(uniqueTOD(), false, 11, s); // Just use random padding characters, but ensure that the high bit // is set to eliminate chances of collision with an IEEE 802 address. s.append( alphaNum.charAt( _weakRand.nextInt(16) | 8 ) ); // Add random padding characters. appendRandomHexChars(32 - s.length(), _weakRand, s); //insert dashes in proper position. so the format matches CF s.insert(8,"-"); s.insert(13,"-"); s.insert(18,"-"); s.insert(23,"-"); return s.toString(); }
/** * @exclude */ public void writeExternal(ObjectOutput output) throws IOException { super.writeExternal(output); if (correlationIdBytes == null) correlationIdBytes = UUIDUtils.toByteArray(correlationId); short flags = 0; if (correlationId != null && correlationIdBytes == null) flags |= CORRELATION_ID_FLAG; if (correlationIdBytes != null) flags |= CORRELATION_ID_BYTES_FLAG; output.writeByte(flags); if (correlationId != null && correlationIdBytes == null) output.writeObject(correlationId); if (correlationIdBytes != null) output.writeObject(correlationIdBytes); }
clientId = UUIDUtils.fromByteArray(clientIdBytes); messageId = UUIDUtils.fromByteArray(messageIdBytes);
private static void appendRandomHexChars(int n, Random rand, StringBuffer result) { int digitsPerInt = DIGITS_PER_INT; while (n > 0) { int digitsToUse = Math.min(n, digitsPerInt); n -= digitsToUse; appendHexString(rand.nextInt(), true, digitsToUse, result); } }
/** * Converts a UID formatted String to a byte[]. The UID must be in the * format generated by createUID, otherwise null is returned. * * @param uid String representing a 128-bit UID. * * @return byte[] 16 bytes in length representing the 128-bits of the * UID or null if the uid could not be converted. */ public static byte[] toByteArray(String uid) { if (!isUID(uid)) return null; byte[] result = new byte[16]; char[] chars = uid.toCharArray(); int r = 0; for (int i = 0; i < chars.length; i++) { if (chars[i] == '-') continue; int h1 = Character.digit(chars[i], 16); i++; int h2 = Character.digit(chars[i], 16); result[r++] = (byte)(((h1 << 4) | h2) & 0xFF); } return result; }
/** * */ @Override public void writeExternal(ObjectOutput output) throws IOException { super.writeExternal(output); if (correlationIdBytes == null && correlationId != null) correlationIdBytes = UUIDUtils.toByteArray(correlationId); short flags = 0; if (correlationId != null && correlationIdBytes == null) flags |= CORRELATION_ID_FLAG; if (correlationIdBytes != null) flags |= CORRELATION_ID_BYTES_FLAG; output.writeByte(flags); if (correlationId != null && correlationIdBytes == null) output.writeObject(correlationId); if (correlationIdBytes != null) output.writeObject(correlationIdBytes); }
clientId = UUIDUtils.fromByteArray(clientIdBytes); messageId = UUIDUtils.fromByteArray(messageIdBytes);
private static void appendRandomHexChars(int n, Random rand, StringBuffer result) { int digitsPerInt = DIGITS_PER_INT; while (n > 0) { int digitsToUse = Math.min(n, digitsPerInt); n -= digitsToUse; appendHexString(rand.nextInt(), true, digitsToUse, result); } }
/** * Converts a UID formatted String to a byte[]. The UID must be in the * format generated by createUID, otherwise null is returned. * * @param uid String representing a 128-bit UID. * * @return byte[] 16 bytes in length representing the 128-bits of the * UID or null if the uid could not be converted. */ public static byte[] toByteArray(String uid) { if (isUID(uid)) { byte[] result = new byte[16]; char[] chars = uid.toCharArray(); int r = 0; for (int i = 0; i < chars.length; i++) { if (chars[i] == '-') continue; int h1 = Character.digit(chars[i], 16); i++; int h2 = Character.digit(chars[i], 16); result[r++] = (byte)(((h1 << 4) | h2) & 0xFF); } return result; } return null; }
/** * * Use the createUUID function when you need a unique string that you will * use as a persistent identifier in a distributed environment. To a very * high degree of certainty, this function returns a unique value; no other * invocation on the same or any other system should return the same value. * * @return a Universally Unique Identifier (UUID) * Proper Format: `XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' * where `X' stands for a hexadecimal digit (0-9 or A-F). */ public static String createUUID() { return createUUID(false); }
private static String createInsecureUUID() { StringBuffer s = new StringBuffer(36); appendHexString(uniqueTOD(), false, 11, s); // Just use random padding characters, but ensure that the high bit // is set to eliminate chances of collision with an IEEE 802 address. s.append( alphaNum.charAt( _weakRand.nextInt(16) | 8 ) ); // Add random padding characters. appendRandomHexChars(32 - s.length(), _weakRand, s); //insert dashes in proper position. so the format matches CF s.insert(8,"-"); s.insert(13,"-"); s.insert(18,"-"); s.insert(23,"-"); return s.toString(); }
/** * */ @Override public void writeExternal(ObjectOutput output) throws IOException { super.writeExternal(output); if (correlationIdBytes == null && correlationId != null) correlationIdBytes = UUIDUtils.toByteArray(correlationId); short flags = 0; if (correlationId != null && correlationIdBytes == null) flags |= CORRELATION_ID_FLAG; if (correlationIdBytes != null) flags |= CORRELATION_ID_BYTES_FLAG; output.writeByte(flags); if (correlationId != null && correlationIdBytes == null) output.writeObject(correlationId); if (correlationIdBytes != null) output.writeObject(correlationIdBytes); }
correlationId = UUIDUtils.fromByteArray(correlationIdBytes);
private static void appendRandomHexChars(int n, Random rand, StringBuffer result) { int digitsPerInt = DIGITS_PER_INT; while (n > 0) { int digitsToUse = Math.min(n, digitsPerInt); n -= digitsToUse; appendHexString(rand.nextInt(), true, digitsToUse, result); } }
/** * Converts a UID formatted String to a byte[]. The UID must be in the * format generated by createUID, otherwise null is returned. * * @param uid String representing a 128-bit UID. * * @return byte[] 16 bytes in length representing the 128-bits of the * UID or null if the uid could not be converted. */ public static byte[] toByteArray(String uid) { if (!isUID(uid)) return null; byte[] result = new byte[16]; char[] chars = uid.toCharArray(); int r = 0; for (int i = 0; i < chars.length; i++) { if (chars[i] == '-') continue; int h1 = Character.digit(chars[i], 16); i++; int h2 = Character.digit(chars[i], 16); result[r++] = (byte)(((h1 << 4) | h2) & 0xFF); } return result; }
/** * * Use the createUUID function when you need a unique string that you will * use as a persistent identifier in a distributed environment. To a very * high degree of certainty, this function returns a unique value; no other * invocation on the same or any other system should return the same value. * * @return a Universally Unique Identifier (UUID) * Proper Format: `XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' * where `X' stands for a hexadecimal digit (0-9 or A-F). */ public static String createUUID() { return createUUID(false); }
/** * @param secure Boolean indicating whether to create a secure UUID. * @see #createUUID() */ public static String createUUID(boolean secure) { Random rand = secure ? _rand : _weakRand; StringBuffer s = new StringBuffer(36); appendHexString(uniqueTOD(), false, 11, s); // Just use random padding characters, but ensure that the high bit // is set to eliminate chances of collision with an IEEE 802 address. s.append( alphaNum.charAt( rand.nextInt(16) | 8 ) ); // Add random padding characters. appendRandomHexChars(32 - s.length(), rand, s); //insert dashes in proper position. so the format matches CF s.insert(8,"-"); s.insert(13,"-"); s.insert(18,"-"); s.insert(23,"-"); return s.toString(); }
clientIdBytes = UUIDUtils.toByteArray((String)clientId); messageIdBytes = UUIDUtils.toByteArray(messageId);
clientId = UUIDUtils.fromByteArray(clientIdBytes); messageId = UUIDUtils.fromByteArray(messageIdBytes);