use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.
the class OpenWireMessageConverter method toAMQMessageMapType.
private static byte[] toAMQMessageMapType(final ActiveMQBuffer buffer, final boolean isCompressed) throws IOException {
byte[] bytes = null;
// it could be a null map
if (buffer.readableBytes() > 0) {
TypedProperties mapData = new TypedProperties();
mapData.decode(buffer.byteBuf());
Map<String, Object> map = mapData.getMap();
ByteArrayOutputStream out = new ByteArrayOutputStream(mapData.getEncodeSize());
OutputStream os = out;
if (isCompressed) {
os = new DeflaterOutputStream(os, true);
}
try (DataOutputStream dataOut = new DataOutputStream(os)) {
MarshallingSupport.marshalPrimitiveMap(map, dataOut);
dataOut.flush();
}
bytes = out.toByteArray();
}
return bytes;
}
use of org.apache.activemq.artemis.utils.collections.TypedProperties 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.utils.collections.TypedProperties in project activemq-artemis by apache.
the class ServerSessionImpl method createConsumer.
@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
final SimpleString unPrefixedQueueName = removePrefix(queueName);
Binding binding = postOffice.getBinding(unPrefixedQueueName);
if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
}
SimpleString address = removePrefix(binding.getAddress());
if (browseOnly) {
try {
securityCheck(address, queueName, CheckType.BROWSE, this);
} catch (Exception e) {
securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
}
} else {
try {
securityCheck(address, queueName, CheckType.CONSUME, this);
} catch (Exception e) {
securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
}
}
Filter filter = FilterImpl.createFilter(filterString);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
}
ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
consumers.put(consumer.getID(), consumer);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
}
if (!browseOnly) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
Queue theQueue = (Queue) binding.getBindable();
props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
// HORNETQ-946
props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
if (filterString != null) {
props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
}
Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
if (logger.isDebugEnabled()) {
logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
}
managementService.sendNotification(notification);
}
return consumer;
}
use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.
the class LocalGroupingHandler method sendProposalResponse.
@Override
public void sendProposalResponse(final Response response, final int distance) throws Exception {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, response.getGroupId());
props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, response.getClusterName());
props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_ALT_VALUE, response.getAlternativeClusterName());
props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
Notification notification = new Notification(null, CoreNotificationType.PROPOSAL_RESPONSE, props);
managementService.sendNotification(notification);
}
use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.
the class RemoteGroupingHandler method receive.
@Override
public Response receive(final Proposal proposal, final int distance) throws Exception {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());
props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());
props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
Notification notification = new Notification(null, CoreNotificationType.PROPOSAL, props);
managementService.sendNotification(notification);
return null;
}
Aggregations