use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class PostOfficeImpl method sendQueueInfoToQueue.
@Override
public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception {
// We send direct to the queue so we can send it to the same queue that is bound to the notifications address -
// this is crucial for ensuring
// that queue infos and notifications are received in a contiguous consistent stream
Binding binding = addressManager.getBinding(queueName);
if (binding == null) {
throw new IllegalStateException("Cannot find queue " + queueName);
}
if (logger.isDebugEnabled()) {
logger.debug("PostOffice.sendQueueInfoToQueue on server=" + this.server + ", queueName=" + queueName + " and address=" + address);
}
Queue queue = (Queue) binding.getBindable();
// Need to lock to make sure all queue info and notifications are in the correct order with no gaps
synchronized (notificationLock) {
// First send a reset message
Message message = new CoreMessage(storageManager.generateID(), 50);
message.setAddress(queueName);
message.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA, true);
routeQueueInfo(message, queue, false);
for (QueueInfo info : queueInfos.values()) {
if (logger.isTraceEnabled()) {
logger.trace("QueueInfo on sendQueueInfoToQueue = " + info);
}
if (info.matchesAddress(address)) {
message = createQueueInfoMessage(CoreNotificationType.BINDING_ADDED, queueName);
message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
message.putLongProperty(ManagementHelper.HDR_BINDING_ID, info.getID());
message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, info.getFilterString());
message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
routeQueueInfo(message, queue, true);
int consumersWithFilters = info.getFilterStrings() != null ? info.getFilterStrings().size() : 0;
for (int i = 0; i < info.getNumberOfConsumers() - consumersWithFilters; i++) {
message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
routeQueueInfo(message, queue, true);
}
if (info.getFilterStrings() != null) {
for (SimpleString filterString : info.getFilterStrings()) {
message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
routeQueueInfo(message, queue, true);
}
}
}
}
Message completeMessage = new CoreMessage(storageManager.generateID(), 50);
completeMessage.setAddress(queueName);
completeMessage.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA_COMPLETE, true);
routeQueueInfo(completeMessage, queue, false);
}
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class MemorySizeTest method testObjectSizes.
@Test
public void testObjectSizes() throws Exception {
UnitTestLogger.LOGGER.info("Server message size is " + MemorySize.calculateSize(new MemorySize.ObjectFactory() {
@Override
public Object createObject() {
return new CoreMessage(1, 1000);
}
}));
UnitTestLogger.LOGGER.info("Message reference size is " + MemorySize.calculateSize(new MemorySize.ObjectFactory() {
@Override
public Object createObject() {
return new MessageReferenceImpl();
}
}));
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class MessageImplTest method internalMessageCopy.
private void internalMessageCopy() throws Exception {
final long RUNS = 2;
final CoreMessage msg = new CoreMessage(123, 18);
msg.setMessageID(RandomUtil.randomLong());
msg.setAddress(new SimpleString("Batatantkashf aksjfh aksfjh askfdjh askjfh "));
final AtomicInteger errors = new AtomicInteger(0);
int T1_number = 10;
int T2_number = 10;
final CountDownLatch latchAlign = new CountDownLatch(T1_number + T2_number);
final CountDownLatch latchReady = new CountDownLatch(1);
class T1 extends Thread {
@Override
public void run() {
latchAlign.countDown();
try {
latchReady.await();
} catch (Exception ignored) {
}
for (int i = 0; i < RUNS; i++) {
try {
Message newMsg = msg.copy();
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
}
}
final String bigString;
{
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 500; i++) {
buffer.append(" ");
}
bigString = buffer.toString();
}
class T2 extends Thread {
@Override
public void run() {
latchAlign.countDown();
try {
latchReady.await();
} catch (Exception ignored) {
}
for (int i = 0; i < RUNS; i++) {
ActiveMQBuffer buf = null;
try {
SessionSendMessage ssm = new SessionSendMessage(msg);
buf = ssm.encode(null);
simulateRead(buf);
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
} finally {
if (buf != null) {
buf.release();
}
}
}
}
}
ArrayList<Thread> threads = new ArrayList<>();
for (int i = 0; i < T1_number; i++) {
T1 t = new T1();
threads.add(t);
t.start();
}
for (int i = 0; i < T2_number; i++) {
T2 t2 = new T2();
threads.add(t2);
t2.start();
}
latchAlign.await();
latchReady.countDown();
for (Thread t : threads) {
t.join();
}
Assert.assertEquals(0, errors.get());
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class CoreMessageTest method testPassThroughMultipleThreads.
@Test
public void testPassThroughMultipleThreads() throws Throwable {
CoreMessage coreMessage = new CoreMessage();
coreMessage.receiveBuffer(BYTE_ENCODE);
LinkedList<Throwable> errors = new LinkedList<>();
Thread[] threads = new Thread[50];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
try {
for (int j = 0; j < 50; j++) {
Assert.assertEquals(ADDRESS, coreMessage.getAddressSimpleString());
Assert.assertEquals(PROP1_VALUE.toString(), coreMessage.getStringProperty(PROP1_NAME));
ByteBuf destinedBuffer = Unpooled.buffer(BYTE_ENCODE.array().length);
coreMessage.sendBuffer(destinedBuffer, 0);
byte[] destinedArray = destinedBuffer.array();
byte[] sourceArray = BYTE_ENCODE.array();
Assert.assertArrayEquals(sourceArray, destinedArray);
Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(coreMessage.getReadOnlyBodyBuffer()).toString());
}
} catch (Throwable e) {
e.printStackTrace();
errors.add(e);
}
});
}
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
for (Throwable e : errors) {
throw e;
}
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class CoreMessageTest method testPassThrough.
/**
* The message is received, then sent to the other side untouched
*/
@Test
public void testPassThrough() {
CoreMessage decodedMessage = decodeMessage();
Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(decodedMessage.getReadOnlyBodyBuffer()).toString());
}
Aggregations