Common utilities, API classes, and shared functionality for Apache ActiveMQ Artemis message broker
—
The core API provides fundamental classes for queue configuration, high-performance string handling, buffer operations, and message routing in Apache ActiveMQ Artemis.
QueueConfiguration is the central class for defining queue properties with a fluent API and JSON serialization support.
class QueueConfiguration implements Serializable {
// Factory methods
static QueueConfiguration of(String name);
static QueueConfiguration of(SimpleString name);
static QueueConfiguration of(QueueConfiguration queueConfiguration);
static QueueConfiguration fromJSON(String jsonString);
// Core configuration setters (all return QueueConfiguration for chaining)
QueueConfiguration setName(SimpleString name);
QueueConfiguration setAddress(SimpleString address);
QueueConfiguration setRoutingType(RoutingType routingType);
QueueConfiguration setFilterString(SimpleString filterString);
QueueConfiguration setDurable(Boolean durable);
QueueConfiguration setAutoDelete(Boolean autoDelete);
QueueConfiguration setMaxConsumers(Integer maxConsumers);
QueueConfiguration setExclusive(Boolean exclusive);
QueueConfiguration setRingSize(Long ringSize);
QueueConfiguration setUser(SimpleString user);
QueueConfiguration setUser(String user);
// Group management setters
QueueConfiguration setGroupRebalance(Boolean groupRebalance);
QueueConfiguration setGroupRebalancePauseDispatch(Boolean groupRebalancePauseDispatch);
QueueConfiguration setGroupBuckets(Integer groupBuckets);
QueueConfiguration setGroupFirstKey(SimpleString groupFirstKey);
QueueConfiguration setGroupFirstKey(String groupFirstKey);
// Last value queue setters
QueueConfiguration setLastValue(Boolean lastValue);
QueueConfiguration setLastValueKey(SimpleString lastValueKey);
QueueConfiguration setLastValueKey(String lastValueKey);
// Advanced behavior setters
QueueConfiguration setNonDestructive(Boolean nonDestructive);
QueueConfiguration setPurgeOnNoConsumers(Boolean purgeOnNoConsumers);
QueueConfiguration setEnabled(Boolean enabled);
QueueConfiguration setConsumersBeforeDispatch(Integer consumersBeforeDispatch);
QueueConfiguration setDelayBeforeDispatch(Long delayBeforeDispatch);
QueueConfiguration setConsumerPriority(Integer consumerPriority);
// Auto-delete configuration setters
QueueConfiguration setAutoDeleteDelay(Long autoDeleteDelay);
QueueConfiguration setAutoDeleteMessageCount(Long autoDeleteMessageCount);
// Management and lifecycle setters
QueueConfiguration setConfigurationManaged(Boolean configurationManaged);
QueueConfiguration setTemporary(Boolean temporary);
QueueConfiguration setAutoCreateAddress(Boolean autoCreateAddress);
QueueConfiguration setInternal(Boolean internal);
QueueConfiguration setTransient(Boolean transient);
QueueConfiguration setAutoCreated(Boolean autoCreated);
// Generic key-value setter
QueueConfiguration set(String key, String value);
// Core property getters
SimpleString getName();
SimpleString getAddress();
RoutingType getRoutingType();
SimpleString getFilterString();
Boolean getDurable();
Boolean isAutoDelete();
Integer getMaxConsumers();
Boolean getExclusive();
Long getRingSize();
Long getId();
SimpleString getUser();
// Group management getters
Boolean isGroupRebalance();
Boolean isGroupRebalancePauseDispatch();
Integer getGroupBuckets();
SimpleString getGroupFirstKey();
// Last value queue getters
Boolean isLastValue();
SimpleString getLastValueKey();
// Advanced behavior getters
Boolean isNonDestructive();
Boolean isPurgeOnNoConsumers();
Boolean isEnabled();
Integer getConsumersBeforeDispatch();
Long getDelayBeforeDispatch();
Integer getConsumerPriority();
// Auto-delete configuration getters
Long getAutoDeleteDelay();
Long getAutoDeleteMessageCount();
// Management and lifecycle getters
Boolean isConfigurationManaged();
Boolean isTemporary();
Boolean isAutoCreateAddress();
Boolean isInternal();
Boolean isTransient();
Boolean isAutoCreated();
// Utility methods
boolean isAddressNull();
boolean isMirrorQueue();
// Object methods
boolean equals(Object obj);
int hashCode();
String toString();
// JSON serialization
String toJSON();
}// Create queue configuration with fluent API
QueueConfiguration config = QueueConfiguration.of("orderQueue")
.setAddress(SimpleString.of("orders"))
.setRoutingType(RoutingType.ANYCAST)
.setDurable(true)
.setMaxConsumers(5)
.setFilterString(SimpleString.of("priority > 5"));
// Serialize to JSON
String json = config.toJSON();
// Create from JSON
QueueConfiguration restored = QueueConfiguration.fromJSON(json);
// Copy configuration
QueueConfiguration copy = QueueConfiguration.of(config)
.setName(SimpleString.of("newQueueName"));SimpleString provides an efficient string implementation that stores data as byte arrays, minimizing object allocation and copying.
final class SimpleString implements CharSequence, Serializable, Comparable<SimpleString> {
// Constants
static final SimpleString EMPTY;
// Factory methods
static SimpleString of(String string);
static SimpleString of(byte[] data);
static SimpleString of(char c);
static SimpleString of(String string, StringSimpleStringPool pool);
// Buffer I/O operations
static SimpleString readNullableSimpleString(ByteBuf buffer);
static SimpleString readSimpleString(ByteBuf buffer);
static SimpleString readNullableSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool);
static SimpleString readSimpleString(ByteBuf buffer, ByteBufSimpleStringPool pool);
static void writeNullableSimpleString(ByteBuf buffer, SimpleString val);
static void writeSimpleString(ByteBuf buffer, SimpleString val);
// Static utility methods
static int sizeofString(SimpleString str);
static int sizeofNullableString(SimpleString str);
// Core data access
byte[] getData();
int sizeof();
// String validation
boolean isBlank();
boolean isEmpty();
// Comparison methods
int compareTo(SimpleString o);
boolean equals(Object obj);
boolean equals(ByteBuf byteBuf, int offset, int length);
int hashCode();
// String operations
boolean startsWith(SimpleString other);
boolean startsWith(char other);
boolean contains(char c);
SimpleString[] split(char delim);
SimpleString concat(String toAdd);
SimpleString concat(SimpleString toAdd);
SimpleString concat(char c);
SimpleString subSeq(int start, int end);
String[] getPaths(char separator);
// Character array operations
void getChars(int srcBegin, int srcEnd, char[] dst, int dstPos);
// CharSequence implementation
int length();
char charAt(int index);
CharSequence subSequence(int start, int end);
String toString();
}// Pool for reading SimpleString from ByteBuf with performance optimization
static final class ByteBufSimpleStringPool extends AbstractByteBufPool<SimpleString> {
// Constructors
ByteBufSimpleStringPool();
ByteBufSimpleStringPool(int capacity);
ByteBufSimpleStringPool(int capacity, int maxCharsLength);
// Pool operations
boolean isEqual(SimpleString entry, ByteBuf byteBuf, int offset, int length);
boolean canPool(ByteBuf byteBuf, int length);
SimpleString create(ByteBuf byteBuf, int length);
}
// Pool for creating SimpleString from String with performance optimization
static final class StringSimpleStringPool extends AbstractPool<String, SimpleString> {
// Constructors
StringSimpleStringPool();
StringSimpleStringPool(int capacity);
// Pool operations
SimpleString create(String value);
boolean isEqual(SimpleString entry, String value);
}// Create SimpleString instances
SimpleString name = SimpleString.of("user.queue.name");
SimpleString shortName = SimpleString.of('Q');
// String operations
boolean isUserQueue = name.startsWith(SimpleString.of("user."));
SimpleString[] parts = name.split('.');
SimpleString combined = name.concat(".backup");
// Performance optimizations with pooling
StringSimpleStringPool pool = new StringSimpleStringPool();
SimpleString pooled = SimpleString.of("frequently.used.name", pool);
// Buffer operations (typically used internally)
ByteBuf buffer = /* ... */;
SimpleString.writeSimpleString(buffer, name);
SimpleString restored = SimpleString.readSimpleString(buffer);
// Character array operations
char[] chars = new char[name.length()];
name.getChars(0, name.length(), chars, 0);Defines the routing behavior for messages in ActiveMQ Artemis.
enum RoutingType {
MULTICAST(0), // Publish-subscribe semantics
ANYCAST(1); // Point-to-point semantics
byte getType();
static RoutingType getType(byte type);
}ActiveMQBuffer provides a comprehensive interface for buffer operations, wrapping Netty's ByteBuf.
interface ActiveMQBuffer extends DataInput {
// Core buffer access
ByteBuf byteBuf();
// Buffer capacity and position
int capacity();
int readerIndex();
int writerIndex();
ActiveMQBuffer setIndex(int readerIndex, int writerIndex);
// Buffer state
int readableBytes();
int writableBytes();
boolean readable();
boolean writable();
ActiveMQBuffer clear();
// Mark and reset operations
ActiveMQBuffer markReaderIndex();
ActiveMQBuffer resetReaderIndex();
ActiveMQBuffer markWriterIndex();
ActiveMQBuffer resetWriterIndex();
// Random access get operations
byte getByte(int index);
short getShort(int index);
int getInt(int index);
long getLong(int index);
char getChar(int index);
float getFloat(int index);
double getDouble(int index);
// Random access set operations
ActiveMQBuffer setByte(int index, byte value);
ActiveMQBuffer setShort(int index, short value);
ActiveMQBuffer setInt(int index, int value);
ActiveMQBuffer setLong(int index, long value);
ActiveMQBuffer setChar(int index, char value);
ActiveMQBuffer setFloat(int index, float value);
ActiveMQBuffer setDouble(int index, double value);
// Sequential read operations
byte readByte();
short readShort();
int readInt();
long readLong();
char readChar();
float readFloat();
double readDouble();
boolean readBoolean();
// Sequential write operations
ActiveMQBuffer writeByte(byte value);
ActiveMQBuffer writeShort(short value);
ActiveMQBuffer writeInt(int value);
ActiveMQBuffer writeLong(long value);
ActiveMQBuffer writeChar(char value);
ActiveMQBuffer writeFloat(float value);
ActiveMQBuffer writeDouble(double value);
ActiveMQBuffer writeBoolean(boolean value);
// SimpleString operations
SimpleString readNullableSimpleString();
SimpleString readSimpleString();
ActiveMQBuffer writeNullableSimpleString(SimpleString value);
ActiveMQBuffer writeSimpleString(SimpleString value);
// Nullable primitive operations
int readNullableInt();
long readNullableLong();
boolean readNullableBoolean();
ActiveMQBuffer writeNullableInt(Integer value);
ActiveMQBuffer writeNullableLong(Long value);
ActiveMQBuffer writeNullableBoolean(Boolean value);
// String operations
String readString();
String readNullableString();
String readUTF();
ActiveMQBuffer writeString(String value);
ActiveMQBuffer writeUTF(String value);
// Buffer management
ActiveMQBuffer copy();
ActiveMQBuffer slice();
ActiveMQBuffer duplicate();
ByteBuffer toByteBuffer();
void release();
// Bulk transfer operations (multiple overloads)
ActiveMQBuffer getBytes(int index, byte[] dst);
ActiveMQBuffer setBytes(int index, byte[] src);
ActiveMQBuffer readBytes(byte[] dst);
ActiveMQBuffer writeBytes(byte[] src);
}Factory methods for creating various types of ActiveMQBuffer instances.
class ActiveMQBuffers {
// Dynamic buffers that can grow as needed
static ActiveMQBuffer dynamicBuffer(int size);
static ActiveMQBuffer dynamicBuffer(byte[] bytes);
// Pooled buffers for performance optimization
static ActiveMQBuffer pooledBuffer(int size);
// Fixed-size buffers
static ActiveMQBuffer fixedBuffer(int size);
// Wrapped buffer implementations
static ActiveMQBuffer wrappedBuffer(ByteBuffer underlying);
static ActiveMQBuffer wrappedBuffer(ByteBuf underlying);
static ActiveMQBuffer wrappedBuffer(byte[] underlying);
}// Generic pair for two related values
class Pair<A, B> implements Serializable {
public A a;
public B b;
public Pair(A a, B b);
// Standard equals, hashCode, toString methods
}
// Optimized pair for object + long combinations
class ObjLongPair<A> {
public A obj;
public long longValue;
public ObjLongPair(A obj, long longValue);
// Standard equals, hashCode, toString methods
}// Container for queue attribute information
class QueueAttributes {
// Queue attribute data and methods
}
// Address with parameters for advanced routing
class ParameterisedAddress {
// Parameterized address functionality
}
// Result information for auto-created queues/addresses
class AutoCreateResult {
// Auto-creation result data
}
// Reasons for client disconnections
enum DisconnectReason {
// Disconnection reason constants
}// Build complex configurations with method chaining
QueueConfiguration config = QueueConfiguration.of("processQueue")
.setAddress(SimpleString.of("process.orders"))
.setRoutingType(RoutingType.ANYCAST)
.setDurable(true)
.setMaxConsumers(3)
.setFilterString(SimpleString.of("priority >= 7"))
.setRingSize(1000L);// Use SimpleString for frequent operations to avoid string allocation
SimpleString baseName = SimpleString.of("queue.");
SimpleString fullName = baseName.concat("user.orders");
// Split once, reuse results
String[] paths = fullName.getPaths('.');
// paths = ["queue", "user", "orders"]// Create different types of buffers based on needs
ActiveMQBuffer dynamicBuffer = ActiveMQBuffers.dynamicBuffer(512); // Can grow
ActiveMQBuffer pooledBuffer = ActiveMQBuffers.pooledBuffer(1024); // From pool
ActiveMQBuffer fixedBuffer = ActiveMQBuffers.fixedBuffer(2048); // Fixed size
// Wrap existing data
ActiveMQBuffer wrappedBuffer = ActiveMQBuffers.wrappedBuffer(existingByteArray);
// Write structured data
dynamicBuffer.writeSimpleString(SimpleString.of("header"));
dynamicBuffer.writeInt(messageCount);
dynamicBuffer.writeLong(timestamp);
// Read back structured data
dynamicBuffer.resetReaderIndex();
SimpleString header = dynamicBuffer.readSimpleString();
int count = dynamicBuffer.readInt();
long time = dynamicBuffer.readLong();Install with Tessl CLI
npx tessl i tessl/maven-org-apache-activemq--artemis-commons