public UUID generateTimeBasedUUID(final byte[] byteAddr) { byte[] contents = new byte[16]; int pos = 10; System.arraycopy(byteAddr, 0, contents, pos, 6); synchronized (mTimerLock) { if (mTimer == null) { mTimer = new UUIDTimer(getRandomNumberGenerator()); } mTimer.getTimestamp(contents); } return new UUID(UUID.TYPE_TIME_BASED, contents); }
@Override public String getJMSMessageID() { if (msgID == null) { UUID uid = (UUID)message.getUserID(); msgID = uid == null ? null : "ID:" + uid.toString(); } return msgID; }
public void encodeHeadersAndProperties(final ByteBuf buffer) { checkProperties(); messageIDPosition = buffer.writerIndex(); buffer.writeLong(messageID); SimpleString.writeNullableSimpleString(buffer, address); if (userID == null) { buffer.writeByte(DataConstants.NULL); } else { buffer.writeByte(DataConstants.NOT_NULL); buffer.writeBytes(userID.asBytes()); } buffer.writeByte(type); buffer.writeBoolean(durable); buffer.writeLong(expiration); buffer.writeLong(timestamp); buffer.writeByte(priority); properties.encode(buffer); }
@Test public void testStringToUuidConversion() { UUIDGenerator gen = UUIDGenerator.getInstance(); for (int i = 0; i < MANY_TIMES; i++) { final UUID uuid = gen.generateUUID(); final String uuidString = uuid.toString(); byte[] data2 = UUID.stringToBytes(uuidString); final UUID uuid2 = new UUID(UUID.TYPE_TIME_BASED, data2); assertEqualsByteArrays(uuid.asBytes(), data2); assertEquals(uuidString, uuid, uuid2); assertEquals(uuidString, uuidString, uuid2.toString()); } } }
protected final synchronized void createNodeId() throws IOException { synchronized (nodeIDGuard) { ByteBuffer id = ByteBuffer.allocateDirect(16); int read = channel.read(id, 3); if (replicatedBackup) { id.position(0); id.put(getUUID().asBytes(), 0, 16); id.position(0); channel.write(id, 3); channel.force(true); } else if (read != 16) { setUUID(UUIDGenerator.getInstance().generateUUID()); id.put(getUUID().asBytes(), 0, 16); id.position(0); channel.write(id, 3); channel.force(true); } else { byte[] bytes = new byte[16]; id.position(0); id.get(bytes); setUUID(new UUID(UUID.TYPE_TIME_BASED, bytes)); } } }
private UUID rawReadNodeId() throws SQLException { final PreparedStatement preparedStatement = this.readNodeId; try (ResultSet resultSet = preparedStatement.executeQuery()) { if (!resultSet.next()) { return null; } else { final String nodeId = resultSet.getString(1); if (nodeId != null) { return new UUID(UUID.TYPE_TIME_BASED, UUID.stringToBytes(nodeId)); } else { return null; } } } }
/** * @throws java.io.FileNotFoundException * @throws java.io.IOException * @throws InterruptedException */ private void assertNodeIdWasSaved() throws Exception { assertTrue("backup initialized", backupServer.getServer().waitForActivation(5, TimeUnit.SECONDS)); // assert that nodeID was saved (to the right file!) String journalDirectory = backupConfig.getJournalDirectory(); File serverLockFile = new File(journalDirectory, "server.lock"); assertTrue("server.lock must exist!\n " + serverLockFile, serverLockFile.exists()); RandomAccessFile raFile = new RandomAccessFile(serverLockFile, "r"); try { // verify the nodeID was written correctly FileChannel channel = raFile.getChannel(); final int size = 16; ByteBuffer id = ByteBuffer.allocateDirect(size); int read = channel.read(id, 3); assertEquals("tried to read " + size + " bytes", size, read); byte[] bytes = new byte[16]; id.position(0); id.get(bytes); UUID uuid = new UUID(UUID.TYPE_TIME_BASED, bytes); SimpleString storedNodeId = new SimpleString(uuid.toString()); assertEquals("nodeId must match", backupServer.getServer().getNodeID(), storedNodeId); } finally { raFile.close(); } }
/** * Sets the nodeID. * <p> * Only used by replicating backups. * * @param nodeID */ public void setNodeID(String nodeID) { synchronized (nodeIDGuard) { this.nodeID = new SimpleString(nodeID); this.uuid = new UUID(UUID.TYPE_TIME_BASED, UUID.stringToBytes(nodeID)); } }
public String generateStringUUID() { byte[] address = getAddressBytes(); if (address == null) { return java.util.UUID.randomUUID().toString(); } else { return generateTimeBasedUUID(address).toString(); } }
private void decodeHeadersAndProperties(final ByteBuf buffer, boolean lazyProperties) { messageIDPosition = buffer.readerIndex(); messageID = buffer.readLong(); address = SimpleString.readNullableSimpleString(buffer, coreMessageObjectPools == null ? null : coreMessageObjectPools.getAddressDecoderPool()); if (buffer.readByte() == DataConstants.NOT_NULL) { byte[] bytes = new byte[16]; buffer.readBytes(bytes); userID = new UUID(UUID.TYPE_TIME_BASED, bytes); } else { userID = null; } type = buffer.readByte(); durable = buffer.readBoolean(); expiration = buffer.readLong(); timestamp = buffer.readLong(); priority = buffer.readByte(); if (lazyProperties) { properties = null; propertiesLocation = buffer.readerIndex(); } else { properties = new TypedProperties(); properties.decode(buffer, coreMessageObjectPools == null ? null : coreMessageObjectPools.getPropertiesDecoderPools()); } }
public static final byte[] getDuplicateBytes(final UUID nodeUUID, final long messageID) { byte[] bytes = new byte[24]; ByteBuffer bb = ByteBuffer.wrap(bytes); bb.put(nodeUUID.asBytes()); bb.putLong(messageID); return bytes; }
private boolean rawInitializeNodeId(UUID nodeId) throws SQLException { final PreparedStatement preparedStatement = this.initializeNodeId; preparedStatement.setString(1, nodeId.toString()); final int rows = preparedStatement.executeUpdate(); assert rows <= 1; return rows > 0; }
@Override public final SimpleString readNodeId() throws ActiveMQIllegalStateException, IOException { ByteBuffer id = ByteBuffer.allocateDirect(16); int read = channel.read(id, 3); if (read != 16) { throw new ActiveMQIllegalStateException("live server did not write id to file"); } byte[] bytes = new byte[16]; id.position(0); id.get(bytes); setUUID(new UUID(UUID.TYPE_TIME_BASED, bytes)); return getNodeId(); }
public void encodeHeadersAndProperties(final ByteBuf buffer) { final TypedProperties properties = getProperties(); messageIDPosition = buffer.writerIndex(); buffer.writeLong(messageID); SimpleString.writeNullableSimpleString(buffer, address); if (userID == null) { buffer.writeByte(DataConstants.NULL); } else { buffer.writeByte(DataConstants.NOT_NULL); buffer.writeBytes(userID.asBytes()); } buffer.writeByte(type); buffer.writeBoolean(durable); buffer.writeLong(expiration); buffer.writeLong(timestamp); buffer.writeByte(priority); properties.encode(buffer); }
private void rawWriteNodeId(UUID nodeId) throws SQLException { final PreparedStatement preparedStatement = this.writeNodeId; preparedStatement.setString(1, nodeId.toString()); if (preparedStatement.executeUpdate() != 1) { throw new IllegalStateException("can't write NodeId on the JDBC Node Manager Store!"); } }
public UUID generateTimeBasedUUID(final byte[] byteAddr) { byte[] contents = new byte[16]; int pos = 10; System.arraycopy(byteAddr, 0, contents, pos, 6); synchronized (mTimerLock) { if (mTimer == null) { mTimer = new UUIDTimer(getRandomNumberGenerator()); } mTimer.getTimestamp(contents); } return new UUID(UUID.TYPE_TIME_BASED, contents); }
public void encodeHeadersAndProperties(final ByteBuf buffer) { checkProperties(); messageIDPosition = buffer.writerIndex(); buffer.writeLong(messageID); SimpleString.writeNullableSimpleString(buffer, address); if (userID == null) { buffer.writeByte(DataConstants.NULL); } else { buffer.writeByte(DataConstants.NOT_NULL); buffer.writeBytes(userID.asBytes()); } buffer.writeByte(type); buffer.writeBoolean(durable); buffer.writeLong(expiration); buffer.writeLong(timestamp); buffer.writeByte(priority); properties.encode(buffer); }
/** * @param generateUUID */ protected void setUUID(UUID generateUUID) { synchronized (nodeIDGuard) { uuid = generateUUID; nodeID = new SimpleString(uuid.toString()); } }
public UUID generateTimeBasedUUID(final byte[] byteAddr) { byte[] contents = new byte[16]; int pos = 10; System.arraycopy(byteAddr, 0, contents, pos, 6); synchronized (mTimerLock) { if (mTimer == null) { mTimer = new UUIDTimer(getRandomNumberGenerator()); } mTimer.getTimestamp(contents); } return new UUID(UUID.TYPE_TIME_BASED, contents); }