Search in sources :

Example 1 with NamedThreadFactory

use of org.jivesoftware.util.NamedThreadFactory in project Openfire by igniterealtime.

the class IQPEPHandler method startExecutor.

/**
 * Starts a new thread pool, unless an existing one is still running.
 */
private void startExecutor() {
    if (executor == null || executor.isShutdown()) {
        // keep the amount of workers low! See comment that goes with the
        // field named 'executor'.
        Log.debug("Starting executor service...");
        executor = new ThreadPoolExecutor(EXECUTOR_CORE_POOL_SIZE.getValue(), EXECUTOR_MAX_POOL_SIZE.getValue(), // TODO: replace with 'toSeconds()' when no longer supporting Java 8.
        EXECUTOR_POOL_KEEP_ALIVE.getValue().getSeconds(), TimeUnit.SECONDS, new SynchronousQueue<>(), new NamedThreadFactory("pep-worker-", null, null, null));
        executor = (ThreadPoolExecutor) Executors.newScheduledThreadPool(2, new NamedThreadFactory("pep-worker-", null, null, null));
        if (JMXManager.isEnabled()) {
            final ThreadPoolExecutorDelegateMBean mBean = new ThreadPoolExecutorDelegate(executor);
            objectName = JMXManager.tryRegister(mBean, ThreadPoolExecutorDelegateMBean.BASE_OBJECT_NAME + "pep");
        }
    }
}
Also used : NamedThreadFactory(org.jivesoftware.util.NamedThreadFactory) ThreadPoolExecutorDelegateMBean(org.jivesoftware.openfire.mbean.ThreadPoolExecutorDelegateMBean) ThreadPoolExecutorDelegate(org.jivesoftware.openfire.mbean.ThreadPoolExecutorDelegate)

Example 2 with NamedThreadFactory

use of org.jivesoftware.util.NamedThreadFactory in project Openfire by igniterealtime.

the class ArchiveManager method initialize.

/**
 * Initializes the manager, by instantiating a thread pool that is used to process archiving tasks.
 */
@Override
public void initialize(final XMPPServer server) {
    if (executor != null) {
        throw new IllegalStateException("Already initialized.");
    }
    executor = new ThreadPoolExecutor(EXECUTOR_CORE_POOL_SIZE.getValue(), EXECUTOR_MAX_POOL_SIZE.getValue(), // TODO: replace with 'toSeconds()' when no longer supporting Java 8.
    EXECUTOR_POOL_KEEP_ALIVE.getValue().getSeconds(), TimeUnit.SECONDS, new SynchronousQueue<>(), new NamedThreadFactory("archive-service-worker-", null, null, null));
    if (JMXManager.isEnabled()) {
        final ThreadPoolExecutorDelegateMBean mBean = new ThreadPoolExecutorDelegate(executor);
        objectName = JMXManager.tryRegister(mBean, ThreadPoolExecutorDelegateMBean.BASE_OBJECT_NAME + "archive-manager");
    }
}
Also used : NamedThreadFactory(org.jivesoftware.util.NamedThreadFactory) ThreadPoolExecutorDelegateMBean(org.jivesoftware.openfire.mbean.ThreadPoolExecutorDelegateMBean) ThreadPoolExecutorDelegate(org.jivesoftware.openfire.mbean.ThreadPoolExecutorDelegate)

Example 3 with NamedThreadFactory

use of org.jivesoftware.util.NamedThreadFactory in project Openfire by igniterealtime.

the class MINAConnectionAcceptor method start.

/**
 * Starts this acceptor by binding the socket acceptor. When the acceptor is already started, a warning will be
 * logged and the method invocation is otherwise ignored.
 */
@Override
public synchronized void start() {
    if (socketAcceptor != null) {
        Log.warn("Unable to start acceptor (it is already started!)");
        return;
    }
    try {
        // Configure the thread pool that is to be used.
        final int initialSize = (configuration.getMaxThreadPoolSize() / 4) + 1;
        final ExecutorFilter executorFilter = new ExecutorFilter(initialSize, configuration.getMaxThreadPoolSize(), 60, TimeUnit.SECONDS);
        final ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor) executorFilter.getExecutor();
        final ThreadFactory threadFactory = new NamedThreadFactory(name + "-thread-", eventExecutor.getThreadFactory(), true, null);
        eventExecutor.setThreadFactory(threadFactory);
        // Construct a new socket acceptor, and configure it.
        socketAcceptor = buildSocketAcceptor();
        if (JMXManager.isEnabled()) {
        // configureJMX( socketAcceptor, name );
        }
        final DefaultIoFilterChainBuilder filterChain = socketAcceptor.getFilterChain();
        filterChain.addFirst(ConnectionManagerImpl.EXECUTOR_FILTER_NAME, executorFilter);
        // Add the XMPP codec filter
        filterChain.addAfter(ConnectionManagerImpl.EXECUTOR_FILTER_NAME, ConnectionManagerImpl.XMPP_CODEC_FILTER_NAME, new ProtocolCodecFilter(new XMPPCodecFactory()));
        // Kill sessions whose outgoing queues keep growing and fail to send traffic
        filterChain.addAfter(ConnectionManagerImpl.XMPP_CODEC_FILTER_NAME, ConnectionManagerImpl.CAPACITY_FILTER_NAME, new StalledSessionsFilter());
        // Ports can be configured to start connections in SSL (as opposed to upgrade a non-encrypted socket to an encrypted one, typically using StartTLS)
        if (configuration.getTlsPolicy() == Connection.TLSPolicy.legacyMode) {
            final SslFilter sslFilter = encryptionArtifactFactory.createServerModeSslFilter();
            filterChain.addAfter(ConnectionManagerImpl.EXECUTOR_FILTER_NAME, ConnectionManagerImpl.TLS_FILTER_NAME, sslFilter);
        }
        // Throttle sessions who send data too fast
        if (configuration.getMaxBufferSize() > 0) {
            socketAcceptor.getSessionConfig().setMaxReadBufferSize(configuration.getMaxBufferSize());
            Log.debug("Throttling read buffer for connections to max={} bytes", configuration.getMaxBufferSize());
        }
        // Start accepting connections
        socketAcceptor.setHandler(connectionHandler);
        socketAcceptor.bind(new InetSocketAddress(configuration.getBindAddress(), configuration.getPort()));
    } catch (Exception e) {
        System.err.println("Error starting " + configuration.getPort() + ": " + e.getMessage());
        Log.error("Error starting: " + configuration.getPort(), e);
        // Reset for future use.
        if (socketAcceptor != null) {
            try {
                socketAcceptor.unbind();
            } finally {
                socketAcceptor = null;
            }
        }
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NamedThreadFactory(org.jivesoftware.util.NamedThreadFactory) SslFilter(org.apache.mina.filter.ssl.SslFilter) NamedThreadFactory(org.jivesoftware.util.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) ExecutorFilter(org.apache.mina.filter.executor.ExecutorFilter) DefaultIoFilterChainBuilder(org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder) StalledSessionsFilter(org.jivesoftware.openfire.net.StalledSessionsFilter) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyManagementException(java.security.KeyManagementException) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

NamedThreadFactory (org.jivesoftware.util.NamedThreadFactory)3 ThreadPoolExecutorDelegate (org.jivesoftware.openfire.mbean.ThreadPoolExecutorDelegate)2 ThreadPoolExecutorDelegateMBean (org.jivesoftware.openfire.mbean.ThreadPoolExecutorDelegateMBean)2 InetSocketAddress (java.net.InetSocketAddress)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 JMException (javax.management.JMException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)1 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)1 ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)1 SslFilter (org.apache.mina.filter.ssl.SslFilter)1 StalledSessionsFilter (org.jivesoftware.openfire.net.StalledSessionsFilter)1