當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。