All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.reactivex.netty.protocol.http.websocket.WebSocketServerBuilder Maven / Gradle / Ivy

There is a newer version: 0.3.18
Show newest version
/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.reactivex.netty.protocol.http.websocket;

import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.reactivex.netty.channel.ConnectionHandler;
import io.reactivex.netty.metrics.MetricEventsListener;
import io.reactivex.netty.metrics.MetricEventsListenerFactory;
import io.reactivex.netty.pipeline.PipelineConfigurator;
import io.reactivex.netty.server.ConnectionBasedServerBuilder;
import io.reactivex.netty.server.RxServer;
import io.reactivex.netty.server.ServerMetricsEvent;

/**
 * @author Tomasz Bak
 */
public class WebSocketServerBuilder extends ConnectionBasedServerBuilder> {
    private String webSocketURI;
    private String subprotocols;
    private boolean allowExtensions;
    private int maxFramePayloadLength = 65536;
    private boolean messageAggregator;

    public WebSocketServerBuilder(int port, ConnectionHandler connectionHandler) {
        super(port, connectionHandler);
    }

    @Override
    public WebSocketServer build() {
        return (WebSocketServer) super.build();
    }

    @Override
    protected RxServer createServer() {
        PipelineConfigurator webSocketPipeline = new WebSocketServerPipelineConfigurator(webSocketURI,
                subprotocols, allowExtensions, maxFramePayloadLength, messageAggregator);
        if (getPipelineConfigurator() != null) {
            appendPipelineConfigurator(webSocketPipeline);
        } else {
            pipelineConfigurator(webSocketPipeline);
        }
        return new WebSocketServer(serverBootstrap, port, pipelineConfigurator, connectionHandler, eventExecutorGroup);
    }

    public WebSocketServerBuilder withWebSocketURI(String uri) {
        webSocketURI = uri;
        return this;
    }

    public WebSocketServerBuilder withSubprotocol(String subprotocols) {
        this.subprotocols = subprotocols;
        return this;
    }

    public WebSocketServerBuilder withAllowExtensions(boolean allowExtensions) {
        this.allowExtensions = allowExtensions;
        return this;
    }

    public WebSocketServerBuilder withMaxFramePayloadLength(int maxFramePayloadLength) {
        this.maxFramePayloadLength = maxFramePayloadLength;
        return this;
    }

    public WebSocketServerBuilder withMessageAggregator(boolean messageAggregator) {
        this.messageAggregator = messageAggregator;
        return this;
    }

    @Override
    protected MetricEventsListener> newMetricsListener(MetricEventsListenerFactory factory, RxServer server) {
        return factory.forWebSocketServer((WebSocketServer) server);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy