当前位置: 首页>>代码示例>>Java>>正文


Java WebSocketFrame.isFinalFragment方法代码示例

本文整理汇总了Java中io.netty.handler.codec.http.websocketx.WebSocketFrame.isFinalFragment方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketFrame.isFinalFragment方法的具体用法?Java WebSocketFrame.isFinalFragment怎么用?Java WebSocketFrame.isFinalFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.handler.codec.http.websocketx.WebSocketFrame的用法示例。


在下文中一共展示了WebSocketFrame.isFinalFragment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
@Override
protected void decode(final ChannelHandlerContext ctx, final WebSocketFrame msg, final List<Object> out)
    throws Exception {
    if (msg instanceof BinaryWebSocketFrame) {
        ByteBuf content = msg.content();
        // the content is passed to other handlers so they need to be retained.
        content.retain();
        fragments.add(content);
        if (msg.isFinalFragment()) {
            if (fragments.size() == 1) {
                out.add(fragments.get(0));
            } else {
                ByteBuf[] array = fragments.toArray(BYTE_BUF_TYPE);
                out.add(Unpooled.wrappedBuffer(array));
            }
            fragments.clear();
        }
    } else if (msg instanceof TextWebSocketFrame) {
        LOG.warn("Recieved a Websocket text frame. This was not expected. Ignoring it.");
    }
}
 
开发者ID:saxsys,项目名称:SynchronizeFX,代码行数:22,代码来源:ByteBufToWebSocketFrameCodec.java

示例2: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
   logger.debug("Received incoming frame [{}]", frame.getClass().getName());
   // Check for closing frame
   if (frame instanceof CloseWebSocketFrame) {
      if (frameBuffer != null) {
          handleMessageCompleted(ctx, frameBuffer.toString());
      }
      handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
      return;
   }

   if (frame instanceof PingWebSocketFrame) {
      ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
      return;
   }

   if (frame instanceof PongWebSocketFrame) {
      logger.info("Pong frame received");
      return;
   }

   if (frame instanceof TextWebSocketFrame) {
      frameBuffer = new StringBuilder();
      frameBuffer.append(((TextWebSocketFrame)frame).text());
   } else if (frame instanceof ContinuationWebSocketFrame) {
      if (frameBuffer != null) {
         frameBuffer.append(((ContinuationWebSocketFrame)frame).text());
      } else {
         logger.warn("Continuation frame received without initial frame.");
      }
   } else {
      throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName()));
   }

   // Check if Text or Continuation Frame is final fragment and handle if needed.
   if (frame.isFinalFragment()) {
      handleMessageCompleted(ctx, frameBuffer.toString());
      frameBuffer = null;
   }
}
 
开发者ID:jwboardman,项目名称:khs-stockticker,代码行数:41,代码来源:StockTickerServerHandler.java

示例3: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

        // Check for closing frame
        if (frame instanceof CloseWebSocketFrame) {
            handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
            return;
        }
        
        if (frame instanceof PingWebSocketFrame) {
            ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
            return;
        }

        //pfdm.getToPronghornPipe(pipeIdx)
        
        Attribute<ContentToPronghornPipe> attrib = ctx.channel().attr(PRONGHORN_KEY);
        Pipe toPronghornPipe = pfdm.getToPronghornPipe(attrib.get().pipeId);
        MemberHolder subscriptionHolder = pfdm.getMemberHolder(attrib.get().pipeId);
  
        if (!frame.isFinalFragment()) {
            attrib.get().partialSendToPipe(frame.content(), continuationInProgress, toPronghornPipe, subscriptionHolder);    
            continuationInProgress = true;
        } else {
            attrib.get().sendToPipe(frame.content(), continuationDataPos, continuationInProgress, toPronghornPipe, subscriptionHolder);
            //finished final fragment so capture this now
            continuationDataPos = Pipe.getBlobWorkingHeadPosition( toPronghornPipe);
            
            continuationInProgress = false;
        }      
        
    }
 
开发者ID:oci-pronghorn,项目名称:NettyStages,代码行数:32,代码来源:WebSocketServerHandlerPronghornAdapter.java

示例4: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame)
{
    logger.debug("Received incoming frame [{}]", frame.getClass().getName());
    // Check for closing frame
    if ( frame instanceof CloseWebSocketFrame) {
        if ( frameBuffer != null) {
            handleMessageCompleted( ctx, frameBuffer.toString());
        }
        handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
        return;
    }

    if (frame instanceof PingWebSocketFrame) {
        ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
        return;
    }

    if (frame instanceof PongWebSocketFrame) {
        logger.info("Pong frame received");
        return;
    }

    if (frame instanceof TextWebSocketFrame) {
        frameBuffer = new StringBuilder();
        frameBuffer.append(((TextWebSocketFrame)frame).text());
    }
    else if (frame instanceof ContinuationWebSocketFrame) {
        if (frameBuffer != null) {
            frameBuffer.append(((ContinuationWebSocketFrame)frame).text());
        }
        else {
            logger.warn("Continuation frame received without initial frame.");
        }
    }
    else {
        throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName()));
    }

    // Check if Text or Continuation Frame is final fragment and handle if needed.
    if (frame.isFinalFragment()) {
        handleMessageCompleted(ctx, frameBuffer.toString());
        frameBuffer = null;
    }
}
 
开发者ID:SpreadServe,项目名称:TFWebSock,代码行数:45,代码来源:WebSocketHandler.java

示例5: handleWebSocketFrame

import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
/**
 * Handle web socket frame.
 *
 * @param ctx the ctx
 * @param frame the frame
 */
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {

	try{

		// Check for closing frame
		if (frame instanceof CloseWebSocketFrame) {
			dominoServer.onClose(this.newWrapper(ctx));
			handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
			return;

		}
		if (frame instanceof PingWebSocketFrame) {
			ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
			return;
		}


		if(frame instanceof PongWebSocketFrame){
			return;//do nothing.
			
		}


		if(frame instanceof TextWebSocketFrame){
			String message = ((TextWebSocketFrame) frame).text();
			textBuffer.append(message);
		}else if(frame instanceof ContinuationWebSocketFrame){
			textBuffer.append(((ContinuationWebSocketFrame) frame).text());
		}
		

		if(frame.isFinalFragment()){
			dominoServer.onMessage(this.newWrapper(ctx), textBuffer.toString());
			textBuffer = new StringBuilder();
		}
		

	}catch(Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:mwambler,项目名称:xockets.io,代码行数:48,代码来源:WebSocketServerHandler.java


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