Search in sources :

Example 11 with UUID

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));
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UUID(org.apache.activemq.artemis.utils.UUID)

Example 12 with UUID

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();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UUID(org.apache.activemq.artemis.utils.UUID) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) ByteBuffer(java.nio.ByteBuffer)

Example 13 with UUID

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();
}
Also used : FileLockNodeManager(org.apache.activemq.artemis.core.server.impl.FileLockNodeManager) NodeManager(org.apache.activemq.artemis.core.server.NodeManager) FileLockNodeManager(org.apache.activemq.artemis.core.server.impl.FileLockNodeManager) UUID(org.apache.activemq.artemis.utils.UUID) File(java.io.File) Test(org.junit.Test)

Example 14 with UUID

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();
}
Also used : UUID(org.apache.activemq.artemis.utils.UUID)

Example 15 with UUID

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;
    }
}
Also used : SQLException(java.sql.SQLException) UUID(org.apache.activemq.artemis.utils.UUID)

Aggregations

UUID (org.apache.activemq.artemis.utils.UUID)16 ByteBuffer (java.nio.ByteBuffer)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 File (java.io.File)2 SQLException (java.sql.SQLException)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 Test (org.junit.Test)2 RandomAccessFile (java.io.RandomAccessFile)1 FileChannel (java.nio.channels.FileChannel)1 BytesMessage (javax.jms.BytesMessage)1 IllegalStateException (javax.jms.IllegalStateException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 ObjectMessage (javax.jms.ObjectMessage)1 StreamMessage (javax.jms.StreamMessage)1 TextMessage (javax.jms.TextMessage)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1