Search in sources :

Example 11 with TypedProperties

use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.

the class TypedPropertiesTest method testCopyingWhileMessingUp.

@Test
public void testCopyingWhileMessingUp() throws Exception {
    TypedProperties properties = new TypedProperties();
    AtomicBoolean running = new AtomicBoolean(true);
    AtomicLong copies = new AtomicLong(0);
    AtomicBoolean error = new AtomicBoolean(false);
    Thread t = new Thread() {

        @Override
        public void run() {
            while (running.get() && !error.get()) {
                try {
                    copies.incrementAndGet();
                    TypedProperties copiedProperties = new TypedProperties(properties);
                } catch (Throwable e) {
                    e.printStackTrace();
                    error.set(true);
                }
            }
        }
    };
    t.start();
    for (int i = 0; !error.get() && (i < 100 || copies.get() < 50); i++) {
        properties.putIntProperty(SimpleString.toSimpleString("key" + i), i);
    }
    running.set(false);
    t.join();
    Assert.assertFalse(error.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Test(org.junit.Test)

Example 12 with TypedProperties

use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.

the class CoreMessage method decodeHeadersAndProperties.

private void decodeHeadersAndProperties(final ByteBuf buffer, boolean lazyProperties) {
    messageIDPosition = buffer.readerIndex();
    messageID = buffer.readLong();
    address = SimpleString.readNullableSimpleString(buffer, coreMessageObjectPools == null ? null : coreMessageObjectPools.getAddressDecoderPool());
    if (buffer.readByte() == DataConstants.NOT_NULL) {
        byte[] bytes = new byte[16];
        buffer.readBytes(bytes);
        userID = new UUID(UUID.TYPE_TIME_BASED, bytes);
    } else {
        userID = null;
    }
    type = buffer.readByte();
    durable = buffer.readBoolean();
    expiration = buffer.readLong();
    timestamp = buffer.readLong();
    priority = buffer.readByte();
    if (lazyProperties) {
        properties = null;
        propertiesLocation = buffer.readerIndex();
    } else {
        properties = new TypedProperties();
        properties.decode(buffer, coreMessageObjectPools == null ? null : coreMessageObjectPools.getPropertiesDecoderPools());
    }
}
Also used : UUID(org.apache.activemq.artemis.utils.UUID) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties)

Example 13 with TypedProperties

use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.

the class SecurityStoreImpl method authenticate.

@Override
public String authenticate(final String user, final String password, RemotingConnection connection) throws Exception {
    if (securityEnabled) {
        if (managementClusterUser.equals(user)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Authenticating cluster admin user");
            }
            /*
             * The special user cluster user is used for creating sessions that replicate management
             * operation between nodes
             */
            if (!managementClusterPassword.equals(password)) {
                throw ActiveMQMessageBundle.BUNDLE.unableToValidateClusterUser(user);
            } else {
                return managementClusterUser;
            }
        }
        String validatedUser = null;
        boolean userIsValid = false;
        if (securityManager instanceof ActiveMQSecurityManager3) {
            validatedUser = ((ActiveMQSecurityManager3) securityManager).validateUser(user, password, connection);
        } else if (securityManager instanceof ActiveMQSecurityManager2) {
            userIsValid = ((ActiveMQSecurityManager2) securityManager).validateUser(user, password, CertificateUtil.getCertsFromConnection(connection));
        } else {
            userIsValid = securityManager.validateUser(user, password);
        }
        if (!userIsValid && validatedUser == null) {
            if (notificationService != null) {
                TypedProperties props = new TypedProperties();
                Notification notification = new Notification(null, CoreNotificationType.SECURITY_AUTHENTICATION_VIOLATION, props);
                notificationService.sendNotification(notification);
            }
            String certSubjectDN = "unavailable";
            X509Certificate[] certs = CertificateUtil.getCertsFromConnection(connection);
            if (certs != null && certs.length > 0 && certs[0] != null) {
                certSubjectDN = certs[0].getSubjectDN().getName();
            }
            throw ActiveMQMessageBundle.BUNDLE.unableToValidateUser(connection.getRemoteAddress(), user, certSubjectDN);
        }
        return validatedUser;
    }
    return null;
}
Also used : ActiveMQSecurityManager2(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager2) ActiveMQSecurityManager3(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager3) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification) X509Certificate(javax.security.cert.X509Certificate)

Example 14 with TypedProperties

use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.

the class NettyAcceptor method start.

@Override
public synchronized void start() throws Exception {
    if (channelClazz != null) {
        // Already started
        return;
    }
    String acceptorType;
    if (useInvm) {
        acceptorType = INVM_ACCEPTOR_TYPE;
        channelClazz = LocalServerChannel.class;
        eventLoopGroup = new DefaultEventLoopGroup();
    } else {
        if (remotingThreads == -1) {
            // Default to number of cores * 3
            remotingThreads = Runtime.getRuntime().availableProcessors() * 3;
        }
        if (useEpoll && Epoll.isAvailable()) {
            channelClazz = EpollServerSocketChannel.class;
            eventLoopGroup = new EpollEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {

                @Override
                public ActiveMQThreadFactory run() {
                    return new ActiveMQThreadFactory("activemq-netty-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
                }
            }));
            acceptorType = EPOLL_ACCEPTOR_TYPE;
            logger.debug("Acceptor using native epoll");
        } else if (useKQueue && KQueue.isAvailable()) {
            channelClazz = KQueueServerSocketChannel.class;
            eventLoopGroup = new KQueueEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {

                @Override
                public ActiveMQThreadFactory run() {
                    return new ActiveMQThreadFactory("activemq-netty-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
                }
            }));
            acceptorType = KQUEUE_ACCEPTOR_TYPE;
            logger.debug("Acceptor using native kqueue");
        } else {
            channelClazz = NioServerSocketChannel.class;
            eventLoopGroup = new NioEventLoopGroup(remotingThreads, AccessController.doPrivileged(new PrivilegedAction<ActiveMQThreadFactory>() {

                @Override
                public ActiveMQThreadFactory run() {
                    return new ActiveMQThreadFactory("activemq-netty-threads", true, ClientSessionFactoryImpl.class.getClassLoader());
                }
            }));
            acceptorType = NIO_ACCEPTOR_TYPE;
            logger.debug("Acceptor using nio");
        }
    }
    bootstrap = new ServerBootstrap();
    bootstrap.group(eventLoopGroup);
    bootstrap.channel(channelClazz);
    ChannelInitializer<Channel> factory = new ChannelInitializer<Channel>() {

        @Override
        public void initChannel(Channel channel) throws Exception {
            ChannelPipeline pipeline = channel.pipeline();
            if (sslEnabled) {
                pipeline.addLast("ssl", getSslHandler(channel.alloc()));
                pipeline.addLast("sslHandshakeExceptionHandler", new SslHandshakeExceptionHandler());
            }
            pipeline.addLast(protocolHandler.getProtocolDecoder());
        }
    };
    bootstrap.childHandler(factory);
    // Bind
    bootstrap.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay);
    if (tcpReceiveBufferSize != -1) {
        bootstrap.childOption(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize);
    }
    if (tcpSendBufferSize != -1) {
        bootstrap.childOption(ChannelOption.SO_SNDBUF, tcpSendBufferSize);
    }
    final int writeBufferLowWaterMark = this.writeBufferLowWaterMark != -1 ? this.writeBufferLowWaterMark : WriteBufferWaterMark.DEFAULT.low();
    final int writeBufferHighWaterMark = this.writeBufferHighWaterMark != -1 ? this.writeBufferHighWaterMark : WriteBufferWaterMark.DEFAULT.high();
    final WriteBufferWaterMark writeBufferWaterMark = new WriteBufferWaterMark(writeBufferLowWaterMark, writeBufferHighWaterMark);
    bootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, writeBufferWaterMark);
    if (backlog != -1) {
        bootstrap.option(ChannelOption.SO_BACKLOG, backlog);
    }
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    channelGroup = new DefaultChannelGroup("activemq-accepted-channels", GlobalEventExecutor.INSTANCE);
    serverChannelGroup = new DefaultChannelGroup("activemq-acceptor-channels", GlobalEventExecutor.INSTANCE);
    if (httpUpgradeEnabled) {
    // the channel will be bound by the Web container and hand over after the HTTP Upgrade
    // handshake is successful
    } else {
        startServerChannels();
        paused = false;
        if (notificationService != null) {
            TypedProperties props = new TypedProperties();
            props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(NettyAcceptorFactory.class.getName()));
            props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
            props.putIntProperty(new SimpleString("port"), port);
            Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STARTED, props);
            notificationService.sendNotification(notification);
        }
        ActiveMQServerLogger.LOGGER.startedAcceptor(acceptorType, host, port, protocolsString);
    }
    if (batchDelay > 0) {
        flusher = new BatchFlusher();
        batchFlusherFuture = scheduledThreadPool.scheduleWithFixedDelay(flusher, batchDelay, batchDelay, TimeUnit.MILLISECONDS);
    }
}
Also used : ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) Notification(org.apache.activemq.artemis.core.server.management.Notification) ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) PrivilegedAction(java.security.PrivilegedAction) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) ChannelInitializer(io.netty.channel.ChannelInitializer) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) LocalServerChannel(io.netty.channel.local.LocalServerChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) Channel(io.netty.channel.Channel) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup)

Example 15 with TypedProperties

use of org.apache.activemq.artemis.utils.collections.TypedProperties in project activemq-artemis by apache.

the class NettyAcceptor method stop.

@Override
public synchronized void stop() {
    if (channelClazz == null) {
        return;
    }
    if (protocolHandler != null) {
        protocolHandler.close();
    }
    if (batchFlusherFuture != null) {
        batchFlusherFuture.cancel(false);
        flusher.cancel();
        flusher = null;
        batchFlusherFuture = null;
    }
    // serverChannelGroup has been unbound in pause()
    if (serverChannelGroup != null) {
        serverChannelGroup.close().awaitUninterruptibly();
    }
    if (channelGroup != null) {
        ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly();
        if (!future.isSuccess()) {
            ActiveMQServerLogger.LOGGER.nettyChannelGroupError();
            for (Channel channel : future.group()) {
                if (channel.isActive()) {
                    ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress());
                }
            }
        }
    }
    // Shutdown the EventLoopGroup if no new task was added for 100ms or if
    // 3000ms elapsed.
    eventLoopGroup.shutdownGracefully(100, 3000, TimeUnit.MILLISECONDS);
    eventLoopGroup = null;
    channelClazz = null;
    for (Connection connection : connections.values()) {
        listener.connectionDestroyed(connection.getID());
    }
    connections.clear();
    if (notificationService != null) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(new SimpleString("factory"), new SimpleString(NettyAcceptorFactory.class.getName()));
        props.putSimpleStringProperty(new SimpleString("host"), new SimpleString(host));
        props.putIntProperty(new SimpleString("port"), port);
        Notification notification = new Notification(null, CoreNotificationType.ACCEPTOR_STOPPED, props);
        try {
            notificationService.sendNotification(notification);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.failedToSendNotification(e);
        }
    }
    paused = false;
}
Also used : ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture) LocalServerChannel(io.netty.channel.local.LocalServerChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) KQueueServerSocketChannel(io.netty.channel.kqueue.KQueueServerSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) Channel(io.netty.channel.Channel) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Notification(org.apache.activemq.artemis.core.server.management.Notification) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

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