当前位置: 首页>>代码示例>>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;未经允许,请勿转载。