• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WebSocketFrameAggregator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator的典型用法代码示例。如果您正苦于以下问题:Java WebSocketFrameAggregator类的具体用法?Java WebSocketFrameAggregator怎么用?Java WebSocketFrameAggregator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebSocketFrameAggregator类属于io.netty.handler.codec.http.websocketx包,在下文中一共展示了WebSocketFrameAggregator类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: channelRead0

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext context, Object message) throws Exception {
	final Channel channel = context.channel();
	if (!handshaker.isHandshakeComplete()) {
		handshaker.finishHandshake(channel, (FullHttpResponse) message);
		channel.pipeline().addBefore(HANDLER_NAME, "websocket-frame-aggregator", new WebSocketFrameAggregator(64 * 1024));
		subscriber.onStart();
		return;
	}

	if (message instanceof FullHttpResponse) {
		final FullHttpResponse response = (FullHttpResponse) message;
		throw new IllegalStateException(
				"Unexpected FullHttpResponse (getStatus=" + response.getStatus() +
						", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
	}

	final WebSocketFrame frame = (WebSocketFrame) message;
	if (frame instanceof PingWebSocketFrame) {
		context.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame)frame).retain().content()));
	} else if (frame instanceof BinaryWebSocketFrame) {
		final ByteBufInputStream input = new ByteBufInputStream(((BinaryWebSocketFrame)message).content());
		final Envelope envelope = Envelope.ADAPTER.decode(input);
		subscriber.onNext(envelope);
	}
}
 
开发者ID:cloudfoundry-community,项目名称:snotel,代码行数:27,代码来源:NettyFirehoseOnSubscribe.java


示例2: handshake

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
private void handshake(final ChannelHandlerContext ctx, final FullHttpRequest req, final String requestPath) {
  WebSocketServerHandshakerFactory wsFactory =
      new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true, maxWebSocketFrameSize);
  WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
  if (handshaker != null) {
    handshaker.handshake(ctx.channel(), req).addListener(
        new ChannelFutureListener() {
          @Override
          public void operationComplete(ChannelFuture future) throws Exception {
            final String sessionId = PipelineUtils.getSessionId(requestPath);
            if (future.isSuccess()) {
              ctx.channel().pipeline().addBefore(
                  SocketIOChannelInitializer.SOCKETIO_WEBSOCKET_HANDLER,
                  SocketIOChannelInitializer.WEBSOCKET_FRAME_AGGREGATOR,
                  new WebSocketFrameAggregator(maxWebSocketFrameSize));
              connect(ctx, req, sessionId);
            } else {
              log.error("Can't handshake: {}", sessionId, future.cause());
            }
          }
        });
  } else {
    WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
  }
}
 
开发者ID:scalecube,项目名称:socketio,代码行数:26,代码来源:WebSocketHandler.java


示例3: handleWebSocketRequest

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
private void handleWebSocketRequest(@NotNull final ChannelHandlerContext context, @NotNull FullHttpRequest request, @NotNull final QueryStringDecoder uriDecoder) {
  WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory("ws://" + request.headers().getAsString(HttpHeaderNames.HOST) + uriDecoder.path(), null, false, NettyUtil.MAX_CONTENT_LENGTH);
  WebSocketServerHandshaker handshaker = factory.newHandshaker(request);
  if (handshaker == null) {
    WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(context.channel());
    return;
  }

  if (!context.channel().isOpen()) {
    return;
  }

  final Client client = new WebSocketClient(context.channel(), handshaker);
  context.attr(ClientManager.CLIENT).set(client);
  handshaker.handshake(context.channel(), request).addListener(new ChannelFutureListener() {
    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
      if (future.isSuccess()) {
        ClientManager clientManager = WebSocketHandshakeHandler.this.clientManager.getValue();
        clientManager.addClient(client);
        MessageChannelHandler messageChannelHandler = new MessageChannelHandler(clientManager, getMessageServer());
        BuiltInServer.replaceDefaultHandler(context, messageChannelHandler);
        ChannelHandlerContext messageChannelHandlerContext = context.pipeline().context(messageChannelHandler);
        context.pipeline().addBefore(messageChannelHandlerContext.name(), "webSocketFrameAggregator", new WebSocketFrameAggregator(NettyUtil.MAX_CONTENT_LENGTH));
        messageChannelHandlerContext.attr(ClientManager.CLIENT).set(client);
        connected(client, uriDecoder.parameters());
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:WebSocketHandshakeHandler.java


示例4: initChannel

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  decoder = new WebsocketProtostuffDecoder(handShaker);
  final ChannelPipeline pipeline = ch.pipeline();
  pipeline.addLast("http-client", new HttpClientCodec());
  pipeline.addLast("aggregator", new HttpObjectAggregator(C5Constants.MAX_RESPONSE_SIZE));
  pipeline.addLast("websec-codec", new WebsocketProtostuffEncoder(handShaker));
  pipeline.addLast("websocket-aggregator", new WebSocketFrameAggregator(C5Constants.MAX_RESPONSE_SIZE));
  pipeline.addLast("message-codec", decoder);
  pipeline.addLast("message-handler", new FutureBasedMessageHandler());
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:12,代码来源:C5ConnectionInitializer.java


示例5: upgradePipelineForWebSockets

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) {
    pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true));
    pipeline.addBefore(AHC_WS_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize()));
    pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize()));
    pipeline.remove(HTTP_CLIENT_CODEC);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:7,代码来源:ChannelManager.java


示例6: doStart

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
@Override
protected void doStart() {
  fiber.start();

  fiber.execute(() -> {
    // we need the tablet module:
    ListenableFuture<C5Module> f = server.getModule(ModuleType.Tablet);
    Futures.addCallback(f, new FutureCallback<C5Module>() {
      @Override
      public void onSuccess(final C5Module result) {
        tabletModule = (TabletModule) result;
        bootstrap.group(acceptGroup, workerGroup)
            .option(ChannelOption.SO_REUSEADDR, true)
            .childOption(ChannelOption.TCP_NODELAY, true)
            .channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
              @Override
              protected void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                p.addLast("http-server-codec", new HttpServerCodec());
                p.addLast("http-agg", new HttpObjectAggregator(C5ServerConstants.MAX_CALL_SIZE));
                p.addLast("websocket-agg", new WebSocketFrameAggregator(C5ServerConstants.MAX_CALL_SIZE));
                p.addLast("decoder", new WebsocketProtostuffDecoder("/websocket"));
                p.addLast("encoder", new WebsocketProtostuffEncoder());
                p.addLast("handler", new RegionServerHandler(RegionServerService.this));
              }
            }
            );

        bootstrap.bind(port).addListener(new ChannelFutureListener() {
          @Override
          public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
              listenChannel = future.channel();
              notifyStarted();
            } else {
              LOG.error("Unable to find Region Server to {} {}", port, future.cause());
              notifyFailed(future.cause());
            }
          }
        });
      }

      @Override
      public void onFailure(Throwable t) {
        notifyFailed(t);
      }
    }, fiber);
  });
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:51,代码来源:RegionServerService.java


示例7: aggregateFrames

import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; //导入依赖的package包/类
/**
 * Turn this {@link WebsocketInbound} into aggregating mode which will only produce
 * fully formed frame that have been received fragmented.
 *
 * @param maxContentLength the maximum frame length
 *
 * @return this inbound
 */
default WebsocketInbound aggregateFrames(int maxContentLength) {
	context().addHandlerLast(new WebSocketFrameAggregator(maxContentLength));
	return this;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:13,代码来源:WebsocketInbound.java



注:本文中的io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IncrementalSAXSource类代码示例发布时间:2022-05-23
下一篇:
Java CPacketClientStatus类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap