Search in sources :

Example 1 with SocketChannelDispatcher

use of org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher in project nifi by apache.

the class ListenTCP method createDispatcher.

@Override
protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<StandardEvent> events) throws IOException {
    final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    // initialize the buffer pool based on max number of connections and the buffer size
    final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    SSLContext sslContext = null;
    SslContextFactory.ClientAuth clientAuth = null;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        final String clientAuthValue = context.getProperty(CLIENT_AUTH).getValue();
        sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.valueOf(clientAuthValue));
        clientAuth = SslContextFactory.ClientAuth.valueOf(clientAuthValue);
    }
    final EventFactory<StandardEvent> eventFactory = new StandardEventFactory();
    final ChannelHandlerFactory<StandardEvent<SocketChannel>, AsyncChannelDispatcher> handlerFactory = new SocketChannelHandlerFactory<>();
    return new SocketChannelDispatcher(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, clientAuth, charSet);
}
Also used : SocketChannelHandlerFactory(org.apache.nifi.processor.util.listen.handler.socket.SocketChannelHandlerFactory) Charset(java.nio.charset.Charset) SSLContext(javax.net.ssl.SSLContext) ByteBuffer(java.nio.ByteBuffer) StandardEvent(org.apache.nifi.processor.util.listen.event.StandardEvent) SslContextFactory(org.apache.nifi.security.util.SslContextFactory) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) StandardEventFactory(org.apache.nifi.processor.util.listen.event.StandardEventFactory) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher)

Example 2 with SocketChannelDispatcher

use of org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher in project nifi by apache.

the class ListenRELP method createDispatcher.

@Override
protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<RELPEvent> events) throws IOException {
    final EventFactory<RELPEvent> eventFactory = new RELPEventFactory();
    final ChannelHandlerFactory<RELPEvent, AsyncChannelDispatcher> handlerFactory = new RELPSocketChannelHandlerFactory<>();
    final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    // initialize the buffer pool based on max number of connections and the buffer size
    final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    SSLContext sslContext = null;
    SslContextFactory.ClientAuth clientAuth = null;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        final String clientAuthValue = context.getProperty(CLIENT_AUTH).getValue();
        sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.valueOf(clientAuthValue));
        clientAuth = SslContextFactory.ClientAuth.valueOf(clientAuthValue);
    }
    // if we decide to support SSL then get the context and pass it in here
    return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, clientAuth, charSet);
}
Also used : RELPSocketChannelHandlerFactory(org.apache.nifi.processors.standard.relp.handler.RELPSocketChannelHandlerFactory) RELPEventFactory(org.apache.nifi.processors.standard.relp.event.RELPEventFactory) Charset(java.nio.charset.Charset) SSLContext(javax.net.ssl.SSLContext) ByteBuffer(java.nio.ByteBuffer) SslContextFactory(org.apache.nifi.security.util.SslContextFactory) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher) RELPEvent(org.apache.nifi.processors.standard.relp.event.RELPEvent)

Example 3 with SocketChannelDispatcher

use of org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher in project nifi by apache.

the class ListenSyslog method createChannelReader.

// visible for testing to be overridden and provide a mock ChannelDispatcher if desired
protected ChannelDispatcher createChannelReader(final ProcessContext context, final String protocol, final BlockingQueue<ByteBuffer> bufferPool, final BlockingQueue<RawSyslogEvent> events, final int maxConnections, final SSLContextService sslContextService, final Charset charset) throws IOException {
    final EventFactory<RawSyslogEvent> eventFactory = new RawSyslogEventFactory();
    if (UDP_VALUE.getValue().equals(protocol)) {
        return new DatagramChannelDispatcher(eventFactory, bufferPool, events, getLogger());
    } else {
        // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
        SSLContext sslContext = null;
        SslContextFactory.ClientAuth clientAuth = null;
        if (sslContextService != null) {
            final String clientAuthValue = context.getProperty(CLIENT_AUTH).getValue();
            sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.valueOf(clientAuthValue));
            clientAuth = SslContextFactory.ClientAuth.valueOf(clientAuthValue);
        }
        final ChannelHandlerFactory<RawSyslogEvent<SocketChannel>, AsyncChannelDispatcher> handlerFactory = new SocketChannelHandlerFactory<>();
        return new SocketChannelDispatcher(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, clientAuth, charset);
    }
}
Also used : SslContextFactory(org.apache.nifi.security.util.SslContextFactory) DatagramChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.DatagramChannelDispatcher) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher) SocketChannelHandlerFactory(org.apache.nifi.processor.util.listen.handler.socket.SocketChannelHandlerFactory) SSLContext(javax.net.ssl.SSLContext)

Example 4 with SocketChannelDispatcher

use of org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher in project nifi by apache.

the class ListenLumberjack method createDispatcher.

@Override
protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<LumberjackEvent> events) throws IOException {
    final EventFactory<LumberjackEvent> eventFactory = new LumberjackEventFactory();
    final ChannelHandlerFactory<LumberjackEvent, AsyncChannelDispatcher> handlerFactory = new LumberjackSocketChannelHandlerFactory<>();
    final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    // initialize the buffer pool based on max number of connections and the buffer size
    final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    SSLContext sslContext = null;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    }
    // if we decide to support SSL then get the context and pass it in here
    return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, charSet);
}
Also used : LumberjackEventFactory(org.apache.nifi.processors.lumberjack.event.LumberjackEventFactory) LumberjackSocketChannelHandlerFactory(org.apache.nifi.processors.lumberjack.handler.LumberjackSocketChannelHandlerFactory) Charset(java.nio.charset.Charset) SSLContext(javax.net.ssl.SSLContext) ByteBuffer(java.nio.ByteBuffer) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) LumberjackEvent(org.apache.nifi.processors.lumberjack.event.LumberjackEvent) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher)

Example 5 with SocketChannelDispatcher

use of org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher in project nifi by apache.

the class ListenBeats method createDispatcher.

@Override
protected ChannelDispatcher createDispatcher(final ProcessContext context, final BlockingQueue<BeatsEvent> events) throws IOException {
    final EventFactory<BeatsEvent> eventFactory = new BeatsEventFactory();
    final ChannelHandlerFactory<BeatsEvent, AsyncChannelDispatcher> handlerFactory = new BeatsSocketChannelHandlerFactory<>();
    final int maxConnections = context.getProperty(MAX_CONNECTIONS).asInteger();
    final int bufferSize = context.getProperty(RECV_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final Charset charSet = Charset.forName(context.getProperty(CHARSET).getValue());
    // initialize the buffer pool based on max number of connections and the buffer size
    final BlockingQueue<ByteBuffer> bufferPool = createBufferPool(maxConnections, bufferSize);
    // if an SSLContextService was provided then create an SSLContext to pass down to the dispatcher
    SSLContext sslContext = null;
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
    }
    // if we decide to support SSL then get the context and pass it in here
    return new SocketChannelDispatcher<>(eventFactory, handlerFactory, bufferPool, events, getLogger(), maxConnections, sslContext, charSet);
}
Also used : BeatsEventFactory(org.apache.nifi.processors.beats.event.BeatsEventFactory) BeatsEvent(org.apache.nifi.processors.beats.event.BeatsEvent) Charset(java.nio.charset.Charset) SSLContext(javax.net.ssl.SSLContext) ByteBuffer(java.nio.ByteBuffer) AsyncChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher) BeatsSocketChannelHandlerFactory(org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory) SSLContextService(org.apache.nifi.ssl.SSLContextService) RestrictedSSLContextService(org.apache.nifi.ssl.RestrictedSSLContextService) SocketChannelDispatcher(org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher)

Aggregations

SSLContext (javax.net.ssl.SSLContext)5 AsyncChannelDispatcher (org.apache.nifi.processor.util.listen.dispatcher.AsyncChannelDispatcher)5 SocketChannelDispatcher (org.apache.nifi.processor.util.listen.dispatcher.SocketChannelDispatcher)5 ByteBuffer (java.nio.ByteBuffer)4 Charset (java.nio.charset.Charset)4 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)4 SSLContextService (org.apache.nifi.ssl.SSLContextService)4 SslContextFactory (org.apache.nifi.security.util.SslContextFactory)3 SocketChannelHandlerFactory (org.apache.nifi.processor.util.listen.handler.socket.SocketChannelHandlerFactory)2 DatagramChannelDispatcher (org.apache.nifi.processor.util.listen.dispatcher.DatagramChannelDispatcher)1 StandardEvent (org.apache.nifi.processor.util.listen.event.StandardEvent)1 StandardEventFactory (org.apache.nifi.processor.util.listen.event.StandardEventFactory)1 BeatsEvent (org.apache.nifi.processors.beats.event.BeatsEvent)1 BeatsEventFactory (org.apache.nifi.processors.beats.event.BeatsEventFactory)1 BeatsSocketChannelHandlerFactory (org.apache.nifi.processors.beats.handler.BeatsSocketChannelHandlerFactory)1 LumberjackEvent (org.apache.nifi.processors.lumberjack.event.LumberjackEvent)1 LumberjackEventFactory (org.apache.nifi.processors.lumberjack.event.LumberjackEventFactory)1 LumberjackSocketChannelHandlerFactory (org.apache.nifi.processors.lumberjack.handler.LumberjackSocketChannelHandlerFactory)1 RELPEvent (org.apache.nifi.processors.standard.relp.event.RELPEvent)1 RELPEventFactory (org.apache.nifi.processors.standard.relp.event.RELPEventFactory)1