use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ManagementServiceImpl method sendNotification.
@Override
public void sendNotification(final Notification notification) throws Exception {
if (logger.isTraceEnabled()) {
logger.trace("Sending Notification = " + notification + ", notificationEnabled=" + notificationsEnabled + " messagingServerControl=" + messagingServerControl);
}
// This needs to be synchronized since we need to ensure notifications are processed in strict sequence
synchronized (this) {
if (messagingServerControl != null && notificationsEnabled) {
// if a notification occurs at same time as sendQueueInfoToQueue is processed
synchronized (postOffice.getNotificationLock()) {
// First send to any local listeners
for (NotificationListener listener : listeners) {
try {
listener.onNotification(notification);
} catch (Exception e) {
// Exception thrown from one listener should not stop execution of others
ActiveMQServerLogger.LOGGER.errorCallingNotifListener(e);
}
}
// https://jira.jboss.org/jira/browse/HORNETQ-317
if (messagingServer == null || !messagingServer.isActive()) {
if (logger.isDebugEnabled()) {
logger.debug("ignoring message " + notification + " as the server is not initialized");
}
return;
}
long messageID = storageManager.generateID();
Message notificationMessage = new CoreMessage(messageID, 512);
// Notification messages are always durable so the user can choose whether to add a durable queue to
// consume them in
notificationMessage.setDurable(true);
notificationMessage.setAddress(managementNotificationAddress);
if (notification.getProperties() != null) {
TypedProperties props = notification.getProperties();
for (SimpleString name : notification.getProperties().getPropertyNames()) {
notificationMessage.putObjectProperty(name, props.getProperty(name));
}
}
notificationMessage.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(notification.getType().toString()));
notificationMessage.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
if (notification.getUID() != null) {
notificationMessage.putStringProperty(new SimpleString("foobar"), new SimpleString(notification.getUID()));
}
postOffice.route(notificationMessage, false);
}
}
}
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class FilterTest method testAMQDurable.
@Test
public void testAMQDurable() throws Exception {
filter = FilterImpl.createFilter(new SimpleString("AMQDurable='DURABLE'"));
message.setDurable(true);
Assert.assertTrue(filter.match(message));
message.setDurable(false);
Assert.assertFalse(filter.match(message));
filter = FilterImpl.createFilter(new SimpleString("AMQDurable='NON_DURABLE'"));
message = new CoreMessage();
message.setDurable(true);
Assert.assertFalse(filter.match(message));
message.setDurable(false);
Assert.assertTrue(filter.match(message));
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class FilterTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
message = new CoreMessage().initBuffer(1024).setMessageID(1);
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class EmbedMessageUtil method embedAsCoreMessage.
public static ICoreMessage embedAsCoreMessage(Message source) {
if (source instanceof ICoreMessage) {
return (ICoreMessage) source;
} else {
Persister persister = source.getPersister();
CoreMessage message = new CoreMessage(source.getMessageID(), persister.getEncodeSize(source) + signature.length + CoreMessage.BODY_OFFSET).setType(Message.EMBEDDED_TYPE);
ActiveMQBuffer buffer = message.getBodyBuffer();
buffer.writeBytes(signature);
persister.encode(buffer, source);
return message;
}
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class PageCursorStressTest method pgMessages.
/**
* @param storage
* @param pageStore
* @param pgParameter
* @param start
* @param NUM_MESSAGES
* @param messageSize
* @throws Exception
*/
private Transaction pgMessages(StorageManager storage, PagingStoreImpl pageStore, long pgParameter, int start, final int NUM_MESSAGES, final int messageSize) throws Exception {
TransactionImpl txImpl = new TransactionImpl(pgParameter, null, storage);
RoutingContext ctx = generateCTX(txImpl);
for (int i = start; i < start + NUM_MESSAGES; i++) {
ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
Message msg = new CoreMessage(storage.generateID(), buffer.writerIndex());
msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
msg.putIntProperty("key", i);
pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock);
}
return txImpl;
}
Aggregations