use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class NodeManager method setNodeID.
/**
* 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));
}
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class BackupSyncJournalTest method assertNodeIdWasSaved.
/**
* @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();
}
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class RealNodeManagerTest method testId.
@Test
public void testId() throws Exception {
NodeManager nodeManager = new FileLockNodeManager(new File(getTemporaryDir()), false);
nodeManager.start();
UUID id1 = nodeManager.getUUID();
nodeManager.stop();
nodeManager.start();
ActiveMQTestBase.assertEqualsByteArrays(id1.asBytes(), nodeManager.getUUID().asBytes());
nodeManager.stop();
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class JdbcNodeManager method readNodeId.
@Override
public SimpleString readNodeId() {
final UUID nodeId = this.sharedStateManager.readNodeId();
setUUID(nodeId);
return getNodeId();
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class JdbcSharedStateManager method initializeOrReadNodeId.
private UUID initializeOrReadNodeId(final UUID newNodeId) throws SQLException {
final UUID nodeId;
connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
connection.setAutoCommit(false);
try {
// optimistic try to initialize nodeId
if (rawInitializeNodeId(newNodeId)) {
nodeId = newNodeId;
} else {
nodeId = rawReadNodeId();
}
} catch (SQLException e) {
connection.rollback();
connection.setAutoCommit(true);
if (logger.isDebugEnabled()) {
logger.debug("Rollback while trying to update NodeId to " + newNodeId, e);
}
return null;
}
if (nodeId != null) {
connection.commit();
connection.setAutoCommit(true);
return nodeId;
} else {
// that means that the rawInitializeNodeId has failed just due to contention or the nodeId wasn't committed yet
connection.rollback();
connection.setAutoCommit(true);
if (logger.isDebugEnabled()) {
logger.debug("Rollback after failed to update NodeId to " + newNodeId + " and haven't found any NodeId");
}
return null;
}
}
Aggregations