Search in sources :

Example 36 with TypedProperties

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;
}
Also used : DataOutputStream(java.io.DataOutputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InflaterOutputStream(java.util.zip.InflaterOutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) OutputStream(java.io.OutputStream) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties)

Example 37 with TypedProperties

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);
            }
        }
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) InvocationTargetException(java.lang.reflect.InvocationTargetException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) NotificationListener(org.apache.activemq.artemis.core.server.management.NotificationListener)

Example 38 with TypedProperties

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;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 39 with TypedProperties

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);
}
Also used : TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 40 with TypedProperties

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;
}
Also used : TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Aggregations

TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)43 Notification (org.apache.activemq.artemis.core.server.management.Notification)24 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)23 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 Test (org.junit.Test)5 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)3 ByteBuf (io.netty.buffer.ByteBuf)2 Channel (io.netty.channel.Channel)2 ServerChannel (io.netty.channel.ServerChannel)2 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)2 KQueueServerSocketChannel (io.netty.channel.kqueue.KQueueServerSocketChannel)2 LocalServerChannel (io.netty.channel.local.LocalServerChannel)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)2 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)2 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)2 Connection (org.apache.activemq.artemis.spi.core.remoting.Connection)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1