org.xnio.StreamConnection Java Examples

The following examples show how to use org.xnio.StreamConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketChannel.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new {@link WebSocketChannel}
 * 8
 *
 * @param connectedStreamChannel The {@link org.xnio.channels.ConnectedStreamChannel} over which the WebSocket Frames should get send and received.
 *                               Be aware that it already must be "upgraded".
 * @param bufferPool             The {@link org.xnio.Pool} which will be used to acquire {@link java.nio.ByteBuffer}'s from.
 * @param version                The {@link WebSocketVersion} of the {@link WebSocketChannel}
 * @param wsUrl                  The url for which the channel was created.
 * @param client
 * @param peerConnections        The concurrent set that is used to track open connections associtated with an endpoint
 */
protected WebSocketChannel(final StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, WebSocketVersion version, String wsUrl, String subProtocol, final boolean client, boolean extensionsSupported, final ExtensionFunction extensionFunction, Set<WebSocketChannel> peerConnections, OptionMap options) {
    super(connectedStreamChannel, bufferPool, new WebSocketFramePriority(), null, options);
    this.client = client;
    this.version = version;
    this.wsUrl = wsUrl;
    this.extensionsSupported = extensionsSupported;
    this.extensionFunction = extensionFunction;
    this.hasReservedOpCode = extensionFunction.hasExtensionOpCode();
    this.subProtocol = subProtocol;
    this.peerConnections = peerConnections;
    addCloseTask(new ChannelListener<WebSocketChannel>() {
        @Override
        public void handleEvent(WebSocketChannel channel) {
            extensionFunction.dispose();
            WebSocketChannel.this.peerConnections.remove(WebSocketChannel.this);
        }
    });
}
 
Example #2
Source File: AjpClientProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress,final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
Example #3
Source File: AjpClientProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
Example #4
Source File: RemotingServices.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Deprecated
public static void installConnectorServicesForNetworkInterfaceBinding(final ServiceTarget serviceTarget,
                                                                      final ServiceName endpointName,
                                                                      final String connectorName,
                                                                      final ServiceName networkInterfaceBindingName,
                                                                      final int port,
                                                                      final OptionMap connectorPropertiesOptionMap,
                                                                      final ServiceName securityRealm,
                                                                      final ServiceName saslAuthenticationFactory,
                                                                      final ServiceName sslContext,
                                                                      final ServiceName socketBindingManager) {
    final ServiceName serviceName= serverServiceName(connectorName);
    final ServiceBuilder<?> builder = serviceTarget.addService(serviceName);
    final Consumer<AcceptingChannel<StreamConnection>> streamServerConsumer = builder.provides(serviceName);
    final Supplier<Endpoint> eSupplier = builder.requires(endpointName);
    final Supplier<SecurityRealm> srSupplier = securityRealm != null ? builder.requires(securityRealm) : null;
    final Supplier<SaslAuthenticationFactory> safSupplier = saslAuthenticationFactory != null ? builder.requires(saslAuthenticationFactory) : null;
    final Supplier<SSLContext> scSupplier = sslContext != null ? builder.requires(sslContext): null;
    final Supplier<SocketBindingManager> sbmSupplier = socketBindingManager != null ? builder.requires(socketBindingManager) : null;
    final Supplier<NetworkInterfaceBinding> ibSupplier = builder.requires(networkInterfaceBindingName);
    builder.setInstance(new InjectedNetworkBindingStreamServerService(streamServerConsumer,
            eSupplier, srSupplier, safSupplier, scSupplier, sbmSupplier, ibSupplier, connectorPropertiesOptionMap, port));
    builder.install();
}
 
Example #5
Source File: HttpClientConnection.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected void doHttp2Upgrade() {
    try {
        StreamConnection connectedStreamChannel = this.performUpgrade();
        Http2Channel http2Channel = new Http2Channel(connectedStreamChannel, null, bufferPool, null, true, true, options);
        Http2ClientConnection http2ClientConnection = new Http2ClientConnection(http2Channel, currentRequest.getResponseCallback(), currentRequest.getRequest(), currentRequest.getRequest().getRequestHeaders().getFirst(Headers.HOST), clientStatistics, false);
        http2ClientConnection.getCloseSetter().set(new ChannelListener<ClientConnection>() {
            @Override
            public void handleEvent(ClientConnection channel) {
                ChannelListeners.invokeChannelListener(HttpClientConnection.this, HttpClientConnection.this.closeSetter.get());
            }
        });
        http2Delegate = http2ClientConnection;
        connectedStreamChannel.getSourceChannel().wakeupReads(); //make sure the read listener is immediately invoked, as it may not happen if data is pushed back
        currentRequest = null;
        pendingResponse = null;
    } catch (IOException e) {
        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
        safeClose(this);
    }
}
 
Example #6
Source File: RemotingServices.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void installConnectorServicesForSocketBinding(final ServiceTarget serviceTarget,
                                                            final ServiceName endpointName,
                                                            final String connectorName,
                                                            final ServiceName socketBindingName,
                                                            final OptionMap connectorPropertiesOptionMap,
                                                            final ServiceName securityRealm,
                                                            final ServiceName saslAuthenticationFactory,
                                                            final ServiceName sslContext,
                                                            final ServiceName socketBindingManager) {
    final ServiceName serviceName = serverServiceName(connectorName);
    final ServiceBuilder<?> builder = serviceTarget.addService(serviceName);
    final Consumer<AcceptingChannel<StreamConnection>> streamServerConsumer = builder.provides(serviceName);
    final Supplier<Endpoint> eSupplier = builder.requires(endpointName);
    final Supplier<SecurityRealm> srSupplier = securityRealm != null ? builder.requires(securityRealm) : null;
    final Supplier<SaslAuthenticationFactory> safSupplier = saslAuthenticationFactory != null ? builder.requires(saslAuthenticationFactory) : null;
    final Supplier<SSLContext> scSupplier = sslContext != null ? builder.requires(sslContext) : null;
    final Supplier<SocketBindingManager> sbmSupplier = builder.requires(socketBindingManager);
    final Supplier<SocketBinding> sbSupplier = builder.requires(socketBindingName);
    builder.setInstance(new InjectedSocketBindingStreamServerService(streamServerConsumer,
            eSupplier, srSupplier, safSupplier, scSupplier, sbmSupplier, sbSupplier, connectorPropertiesOptionMap));
    builder.install();
}
 
Example #7
Source File: HttpServerConnection.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public HttpServerConnection(StreamConnection channel, final ByteBufferPool bufferPool, final HttpHandler rootHandler, final OptionMap undertowOptions, final int bufferSize, final ConnectorStatisticsImpl connectorStatistics) {
    super(channel, bufferPool, rootHandler, undertowOptions, bufferSize);
    if (channel instanceof SslChannel) {
        sslSessionInfo = new ConnectionSSLSessionInfo(((SslChannel) channel), this);
    }
    this.responseConduit = new HttpResponseConduit(channel.getSinkChannel().getConduit(), bufferPool, this);

    fixedLengthStreamSinkConduit = new ServerFixedLengthStreamSinkConduit(responseConduit, false, false);
    readDataStreamSourceConduit = new ReadDataStreamSourceConduit(channel.getSourceChannel().getConduit(), this);
    //todo: do this without an allocation
    addCloseListener(new CloseListener() {
        @Override
        public void closed(ServerConnection connection) {
            if(connectorStatistics != null) {
                connectorStatistics.decrementConnectionCount();
            }
            responseConduit.freeBuffers();
        }
    });
}
 
Example #8
Source File: HttpReadListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void sendBadRequestAndClose(final StreamConnection connection, final Throwable exception) {
    UndertowLogger.REQUEST_IO_LOGGER.failedToParseRequest(exception);
    connection.getSourceChannel().suspendReads();
    new StringWriteChannelListener(BAD_REQUEST) {
        @Override
        protected void writeDone(final StreamSinkChannel c) {
            super.writeDone(c);
            c.suspendWrites();
            IoUtils.safeClose(connection);
        }

        @Override
        protected void handleError(StreamSinkChannel channel, IOException e) {
            IoUtils.safeClose(connection);
        }
    }.setup(connection.getSinkChannel());
}
 
Example #9
Source File: UndertowAcceptingSslChannel.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
UndertowAcceptingSslChannel(final UndertowXnioSsl ssl, final AcceptingChannel<? extends StreamConnection> tcpServer, final OptionMap optionMap, final ByteBufferPool applicationBufferPool, final boolean startTls) {
    this.tcpServer = tcpServer;
    this.ssl = ssl;
    this.applicationBufferPool = applicationBufferPool;
    this.startTls = startTls;
    clientAuthMode = optionMap.get(Options.SSL_CLIENT_AUTH_MODE);
    useClientMode = optionMap.get(Options.SSL_USE_CLIENT_MODE, false) ? 1 : 0;
    enableSessionCreation = optionMap.get(Options.SSL_ENABLE_SESSION_CREATION, true) ? 1 : 0;
    final Sequence<String> enabledCipherSuites = optionMap.get(Options.SSL_ENABLED_CIPHER_SUITES);
    cipherSuites = enabledCipherSuites != null ? enabledCipherSuites.toArray(new String[enabledCipherSuites.size()]) : null;
    final Sequence<String> enabledProtocols = optionMap.get(Options.SSL_ENABLED_PROTOCOLS);
    protocols = enabledProtocols != null ? enabledProtocols.toArray(new String[enabledProtocols.size()]) : null;
    //noinspection ThisEscapedInObjectConstruction
    closeSetter = ChannelListeners.<AcceptingChannel<SslConnection>>getDelegatingSetter(tcpServer.getCloseSetter(), this);
    //noinspection ThisEscapedInObjectConstruction
    acceptSetter = ChannelListeners.<AcceptingChannel<SslConnection>>getDelegatingSetter(tcpServer.getAcceptSetter(), this);
    useCipherSuitesOrder = optionMap.get(UndertowOptions.SSL_USER_CIPHER_SUITES_ORDER, false);
}
 
Example #10
Source File: HttpReadListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private boolean doHttp2PriRead(StreamConnection connection, ByteBuffer buffer, HttpServerConnection serverConnection, PooledByteBuffer extraData) throws IOException {
    if(buffer.hasRemaining()) {
        int res = connection.getSourceChannel().read(buffer);
        if (res == -1) {
            return true; //fail
        }
        if (buffer.hasRemaining()) {
            return false;
        }
    }
    buffer.flip();
    for(int i = 0; i < PRI_EXPECTED.length; ++i) {
        if(buffer.get() != PRI_EXPECTED[i]) {
            throw UndertowMessages.MESSAGES.http2PriRequestFailed();
        }
    }

    Http2Channel channel = new Http2Channel(connection, null, serverConnection.getByteBufferPool(), extraData, false, false, false, serverConnection.getUndertowOptions());
    Http2ReceiveListener receiveListener = new Http2ReceiveListener(serverConnection.getRootHandler(), serverConnection.getUndertowOptions(), serverConnection.getBufferSize(), null);
    channel.getReceiveSetter().set(receiveListener);
    channel.resumeReceives();
    return true;
}
 
Example #11
Source File: ReadTimeoutStreamSourceConduit.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public ReadTimeoutStreamSourceConduit(final StreamSourceConduit delegate, StreamConnection connection, OpenListener openListener) {
    super(delegate);
    this.connection = connection;
    this.openListener = openListener;
    final ReadReadyHandler handler = new ReadReadyHandler.ChannelListenerHandler<>(connection.getSourceChannel());
    delegate.setReadReadyHandler(new ReadReadyHandler() {
        @Override
        public void readReady() {
            handler.readReady();
        }

        @Override
        public void forceTermination() {
            cleanup();
            handler.forceTermination();
        }

        @Override
        public void terminated() {
            cleanup();
            handler.terminated();
        }
    });
}
 
Example #12
Source File: WebSocket13ClientHandshake.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public WebSocketChannel createChannel(final StreamConnection channel, final String wsUri, final ByteBufferPool bufferPool, OptionMap options) {
    if (negotiation != null && negotiation.getSelectedExtensions() != null && !negotiation.getSelectedExtensions().isEmpty()) {

        List<WebSocketExtension> selected = negotiation.getSelectedExtensions();
        List<ExtensionFunction> negotiated = new ArrayList<>();
        if (selected != null && !selected.isEmpty()) {
            for (WebSocketExtension ext : selected) {
                for (ExtensionHandshake extHandshake : extensions) {
                    if (ext.getName().equals(extHandshake.getName())) {
                        negotiated.add(extHandshake.create());
                    }
                }
            }
        }
        return new WebSocket13Channel(channel, bufferPool, wsUri, negotiation.getSelectedSubProtocol(), true, !negotiated.isEmpty(), CompositeExtensionFunction.compose(negotiated), new HashSet<WebSocketChannel>(), options);
    } else {
        return new WebSocket13Channel(channel, bufferPool, wsUri, negotiation != null ? negotiation.getSelectedSubProtocol() : "", true, false, NoopExtensionFunction.INSTANCE, new HashSet<WebSocketChannel>(), options);
    }
}
 
Example #13
Source File: WrappingXnioSocketChannel.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link WrappingXnioSocketChannel} which was created via the given {@link AcceptingChannel} and uses
 * the given {@link StreamConnection} under the covers.
 */
public WrappingXnioSocketChannel(AcceptingChannel<StreamConnection> parent, StreamConnection channel) {
    this(new WrappingXnioServerSocketChannel(parent), channel);
    // register a EventLoop and start read
    unsafe().register(new XnioEventLoop(thread), unsafe().voidPromise());
    read();
}
 
Example #14
Source File: Light4jHttpClientProvider.java    From light-4j with Apache License 2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #15
Source File: WebSocketServlet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {

    final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp, peerConnections);
    Handshake handshaker = null;
    for (Handshake method : handshakes) {
        if (method.matches(facade)) {
            handshaker = method;
            break;
        }
    }

    if (handshaker == null) {
        UndertowLogger.REQUEST_LOGGER.debug("Could not find hand shaker for web socket request");
        resp.sendError(StatusCodes.BAD_REQUEST);
        return;
    }
    final Handshake selected = handshaker;
    facade.upgradeChannel(new HttpUpgradeListener() {
        @Override
        public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) {
            WebSocketChannel channel = selected.createChannel(facade, streamConnection, facade.getBufferPool());
            peerConnections.add(channel);
            callback.onConnect(facade, channel);
        }
    });
    handshaker.handshake(facade);
}
 
Example #16
Source File: HttpClientProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #17
Source File: HttpClientProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final URI uri) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, uri);
        }
    };
}
 
Example #18
Source File: Light4jHttpClientProvider.java    From light-4j with Apache License 2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final URI uri) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, uri);
        }
    };
}
 
Example #19
Source File: AbstractXnioSocketChannel.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
private void closeOnRead() {
    StreamConnection connection = connection();
    suspend(connection);
    if (isOpen()) {
        unsafe().close(unsafe().voidPromise());
    }
}
 
Example #20
Source File: Undertow.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ListenerInfo(String protcol, SocketAddress address, OpenListener openListener, UndertowXnioSsl ssl, AcceptingChannel<? extends StreamConnection> channel) {
    this.protcol = protcol;
    this.address = address;
    this.openListener = openListener;
    this.ssl = ssl;
    this.channel = channel;
}
 
Example #21
Source File: AbstractXnioSocketChannel.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
protected void doBeginRead() throws Exception {
    StreamConnection conn = connection();
    if (conn == null) {
        return;
    }
    ConduitStreamSourceChannel source = conn.getSourceChannel();
    if (!source.isReadResumed()) {
        source.resumeReads();
    }
}
 
Example #22
Source File: AbstractXnioSocketChannel.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
protected SocketAddress localAddress0() {
    StreamConnection conn = connection();
    if (conn == null) {
        return null;
    }
    return conn.getLocalAddress();
}
 
Example #23
Source File: InjectedSocketBindingStreamServerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
InjectedSocketBindingStreamServerService(
        final Consumer<AcceptingChannel<StreamConnection>> streamServerConsumer,
        final Supplier<Endpoint> endpointSupplier,
        final Supplier<SecurityRealm> securityRealmSupplier,
        final Supplier<SaslAuthenticationFactory> saslAuthenticationFactorySupplier,
        final Supplier<SSLContext> sslContextSupplier,
        final Supplier<SocketBindingManager> socketBindingManagerSupplier,
        final Supplier<SocketBinding> socketBindingSupplier,
        final OptionMap connectorPropertiesOptionMap) {
    super(streamServerConsumer, endpointSupplier, securityRealmSupplier, saslAuthenticationFactorySupplier,
            sslContextSupplier, socketBindingManagerSupplier, connectorPropertiesOptionMap);
    this.socketBindingSupplier = socketBindingSupplier;
}
 
Example #24
Source File: AbstractXnioSocketChannel.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
protected SocketAddress remoteAddress0() {
    StreamConnection conn = connection();
    if (conn == null) {
        return null;
    }
    return conn.getPeerAddress();
}
 
Example #25
Source File: InjectedNetworkBindingStreamServerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
InjectedNetworkBindingStreamServerService(
        final Consumer<AcceptingChannel<StreamConnection>> streamServerConsumer,
        final Supplier<Endpoint> endpointSupplier,
        final Supplier<SecurityRealm> securityRealmSupplier,
        final Supplier<SaslAuthenticationFactory> saslAuthenticationFactorySupplier,
        final Supplier<SSLContext> sslContextSupplier,
        final Supplier<SocketBindingManager> socketBindingManagerSupplier,
        final Supplier<NetworkInterfaceBinding> interfaceBindingSupplier,
        final OptionMap connectorPropertiesOptionMap, int port) {
    super(streamServerConsumer, endpointSupplier, securityRealmSupplier, saslAuthenticationFactorySupplier,
            sslContextSupplier, socketBindingManagerSupplier, connectorPropertiesOptionMap);
    this.interfaceBindingSupplier = interfaceBindingSupplier;
    this.port = port;
}
 
Example #26
Source File: JaxRsServer.java    From testfun with Apache License 2.0 5 votes vote down vote up
public int getJaxrsPort() {
    try {
        Field channelsField = server.getClass().getDeclaredField("channels");
        List<AcceptingChannel<? extends StreamConnection>> channels = InjectionUtils.readObjectFromField(server, channelsField);
        return ((InetSocketAddress)channels.get(0).getLocalAddress()).getPort();
    } catch (NoSuchFieldException e) {
        throw new JaxRsException("Failed getting listener port", e);
    }

}
 
Example #27
Source File: ProxyProtocolReadListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
AddressWrappedConnection(StreamConnection delegate, SocketAddress source, SocketAddress dest) {
    super(delegate.getIoThread());
    this.delegate = delegate;
    this.source = source;
    this.dest = dest;
    setSinkConduit(delegate.getSinkChannel().getConduit());
    setSourceConduit(delegate.getSourceChannel().getConduit());
}
 
Example #28
Source File: HttpServerConnection.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected StreamConnection upgradeChannel() {
    clearChannel();
    if (extraBytes != null) {
        channel.getSourceChannel().setConduit(new ReadDataStreamSourceConduit(channel.getSourceChannel().getConduit(), this));
    }
    return channel;
}
 
Example #29
Source File: ChannelServer.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ChannelServer(final Endpoint endpoint,
        final Registration registration,
        final AcceptingChannel<StreamConnection> streamServer) {
    this.endpoint = endpoint;
    this.registration = registration;
    this.streamServer = streamServer;
}
 
Example #30
Source File: AbstractFramedChannel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@link io.undertow.server.protocol.framed.AbstractFramedChannel}
 * 8
 *  @param connectedStreamChannel The {@link org.xnio.channels.ConnectedStreamChannel} over which the Frames should get send and received.
 *                               Be aware that it already must be "upgraded".
 * @param bufferPool             The {@link ByteBufferPool} which will be used to acquire {@link ByteBuffer}'s from.
 * @param framePriority
 * @param settings               The settings
 */
protected AbstractFramedChannel(final StreamConnection connectedStreamChannel, ByteBufferPool bufferPool, FramePriority<C, R, S> framePriority, final PooledByteBuffer readData, OptionMap settings) {
    this.framePriority = framePriority;
    this.maxQueuedBuffers = settings.get(UndertowOptions.MAX_QUEUED_READ_BUFFERS, 10);
    this.settings = settings;
    if (readData != null) {
        if(readData.getBuffer().hasRemaining()) {
            this.readData = new ReferenceCountedPooled(readData, 1);
        } else {
            readData.close();
        }
    }
    if(bufferPool == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("bufferPool");
    }
    if(connectedStreamChannel == null) {
        throw UndertowMessages.MESSAGES.argumentCannotBeNull("connectedStreamChannel");
    }
    IdleTimeoutConduit idle = createIdleTimeoutChannel(connectedStreamChannel);
    connectedStreamChannel.getSourceChannel().setConduit(idle);
    connectedStreamChannel.getSinkChannel().setConduit(idle);
    this.idleTimeoutConduit = idle;
    this.channel = connectedStreamChannel;
    this.bufferPool = bufferPool;

    closeSetter = new ChannelListener.SimpleSetter<>();
    receiveSetter = new ChannelListener.SimpleSetter<>();
    channel.getSourceChannel().getReadSetter().set(null);
    channel.getSourceChannel().suspendReads();

    channel.getSourceChannel().getReadSetter().set(new FrameReadListener());
    connectedStreamChannel.getSinkChannel().getWriteSetter().set(new FrameWriteListener());
    FrameCloseListener closeListener = new FrameCloseListener();
    connectedStreamChannel.getSinkChannel().getCloseSetter().set(closeListener);
    connectedStreamChannel.getSourceChannel().getCloseSetter().set(closeListener);
}