use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class JdbcNodeManager method start.
@Override
public void start() throws Exception {
try {
synchronized (this) {
if (isStarted()) {
return;
}
this.sharedStateManager = sharedStateManagerFactory.get();
if (!replicatedBackup) {
final UUID nodeId = sharedStateManager.setup(UUIDGenerator.getInstance()::generateUUID);
setUUID(nodeId);
}
this.scheduledLiveLock = scheduledLiveLockFactory.get();
this.scheduledBackupLock = scheduledBackupLockFactory.get();
super.start();
}
} catch (IllegalStateException e) {
this.sharedStateManager = null;
this.scheduledLiveLock = null;
this.scheduledBackupLock = null;
if (this.ioCriticalErrorListener != null) {
this.ioCriticalErrorListener.onIOException(e, "Failed to setup the JdbcNodeManager", null);
}
throw e;
}
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class JdbcNodeManager method stopBackup.
@Override
public void stopBackup() throws Exception {
if (replicatedBackup) {
final UUID nodeId = getUUID();
sharedStateManager.writeNodeId(nodeId);
}
releaseBackup();
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class JdbcSharedStateManager method readNodeId.
@Override
public UUID readNodeId() {
synchronized (connection) {
try {
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
connection.setAutoCommit(true);
final UUID nodeId = rawReadNodeId();
return nodeId;
} catch (SQLException e) {
throw new IllegalStateException(e);
}
}
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class UUIDTest method testStringToUuidConversion.
@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());
}
}
use of org.apache.activemq.artemis.utils.UUID in project activemq-artemis by apache.
the class NodeManager method createNodeId.
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));
}
}
}
Aggregations