當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageEvent.getChannel方法代碼示例

本文整理匯總了Java中org.jboss.netty.channel.MessageEvent.getChannel方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageEvent.getChannel方法的具體用法?Java MessageEvent.getChannel怎麽用?Java MessageEvent.getChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.channel.MessageEvent的用法示例。


在下文中一共展示了MessageEvent.getChannel方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: messageReceived

import org.jboss.netty.channel.MessageEvent; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
    throws Exception {
  ChannelBuffer buf = (ChannelBuffer) e.getMessage();
  ByteBuffer b = buf.toByteBuffer().asReadOnlyBuffer();
  XDR in = new XDR(b, XDR.State.READING);

  RpcInfo info = null;
  try {
    RpcCall callHeader = RpcCall.read(in);
    ChannelBuffer dataBuffer = ChannelBuffers.wrappedBuffer(in.buffer()
        .slice());
    info = new RpcInfo(callHeader, dataBuffer, ctx, e.getChannel(),
        e.getRemoteAddress());
  } catch (Exception exc) {
    LOG.info("Malformed RPC request from " + e.getRemoteAddress());
  }

  if (info != null) {
    Channels.fireMessageReceived(ctx, info);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:RpcUtil.java

示例2: messageReceived

import org.jboss.netty.channel.MessageEvent; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
  // Get handle from create response
  ChannelBuffer buf = (ChannelBuffer) e.getMessage();
  XDR rsp = new XDR(buf.array());
  if (rsp.getBytes().length == 0) {
    LOG.info("rsp length is zero, why?");
    return;
  }
  LOG.info("rsp length=" + rsp.getBytes().length);

  RpcReply reply = RpcReply.read(rsp);
  int xid = reply.getXid();
  // Only process the create response
  if (xid != 0x8000004c) {
    return;
  }
  int status = rsp.readInt();
  if (status != Nfs3Status.NFS3_OK) {
    LOG.error("Create failed, status =" + status);
    return;
  }
  LOG.info("Create succeeded");
  rsp.readBoolean(); // value follow
  handle = new FileHandle();
  handle.deserialize(rsp);
  channel = e.getChannel();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:29,代碼來源:TestOutOfOrderWrite.java

示例3: messageReceived

import org.jboss.netty.channel.MessageEvent; //導入方法依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception 
{
	// Cast to a String first.
	// We know it is a String because we put some codec in TelnetPipelineFactory.
	Channel channel = e.getChannel();
	String packet = (String)e.getMessage();
	
	System.out.println("Payload processed:"+packet.length());
	channel.write("status=200\r\n");
}
 
開發者ID:ZalemSoftware,項目名稱:OpenMobster,代碼行數:12,代碼來源:TextProtocolHandler.java

示例4: handleRequest

import org.jboss.netty.channel.MessageEvent; //導入方法依賴的package包/類
/**
	 * Processes an HTTP request
	 * @param ctx The channel handler context
	 * @param req The HTTP request
	 * @param me The message event that will be sent upstream if not handled here
	 */
	public void handleRequest(ChannelHandlerContext ctx, HttpRequest req, MessageEvent me) {
		log.warn("HTTP Request: {}", req);
        if (req.getMethod() != GET) {
            sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN));
            return;
        }
        String uri = req.getUri();
        if(!"/ws".equals(uri)) {
        	ctx.sendUpstream(me);
        	return;
        }
        final Channel channel = me.getChannel();
        // Handshake
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, false);
        WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            wsFactory.sendUnsupportedWebSocketVersionResponse(channel);
        } else {
        	wsHandShaker.set(channel, handshaker);
        	ChannelFuture cf = handshaker.handshake(channel, req); 
            cf.addListener(WebSocketServerHandshaker.HANDSHAKE_LISTENER);
            cf.addListener(new ChannelFutureListener() {
				@Override
				public void operationComplete(ChannelFuture f) throws Exception {
					if(f.isSuccess()) {
						final Channel wsChannel = f.getChannel();
//						RPCSessionManager.getInstance().getSession(wsChannel).addSessionAttribute(RPCSessionAttribute.Protocol, "WebSocket");
//						SharedChannelGroup.getInstance().add(
//								f.getChannel(), 
//								ChannelType.WEBSOCKET_REMOTE, 
//								"WebSocketClient-" + f.getChannel().getId(), 
//								((InetSocketAddress)wsChannel.getRemoteAddress()).getAddress().getCanonicalHostName(), 
//								"WebSock[" + wsChannel.getId() + "]"
//						);
						//wsChannel.write(new JSONObject(Collections.singletonMap("sessionid", wsChannel.getId())));
						
						wsChannel.write(marshaller.getNodeFactory().objectNode().put("sessionid", "" + wsChannel.getId()));
						//wsChannel.getPipeline().remove(DefaultChannelHandler.NAME);
					}
				}
			});
        }
	}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:50,代碼來源:WebSocketServiceHandler.java


注:本文中的org.jboss.netty.channel.MessageEvent.getChannel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。