Search in sources :

Example 6 with UUID

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

Example 7 with UUID

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

Example 8 with UUID

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

Example 9 with UUID

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

Example 10 with UUID

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

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