Java Code Examples for org.jboss.netty.channel.MessageEvent#getChannel()

The following examples show how to use org.jboss.netty.channel.MessageEvent#getChannel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RpcUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 2
Source File: RpcUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example 3
Source File: MyServerHandler.java    From whiteboard with Apache License 2.0 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	Channel channel = e.getChannel();
	SerializablePath newPath = (SerializablePath) e.getMessage();
	Commons.myUUID = newPath.getMyUUID();

	recordMyUUID(Commons.myUUID, channel);
	System.out.println("������յ���Ϣ,�豸��ʾ��--" + Commons.myUUID);
	if ("send_uuid".equals(newPath.getOPType()))
		return;

	if ("clear".equals(newPath.getOPType())) {
		if (MetadataRepositories.getInstance().getBufferShapes().size() != 0) {
			System.out.println("������������ͼ������");
			MetadataRepositories.getInstance().getBufferShapes().clear();
		}
		return;
	}

	MetadataRepositories.getInstance().getBufferShapes().add(newPath);
	// // ��DZ��͑���д����ͼ������
	sendNewShapeToClient(newPath);
}
 
Example 4
Source File: HttpRequestFrameworkHandler.java    From zuul-netty with Apache License 2.0 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    if (e.getMessage() instanceof HttpRequest) {
        HttpRequest request = (HttpRequest) e.getMessage();
        InterruptsImpl callback = new InterruptsImpl(request, e.getChannel());
        LOG.debug("handler: {} is calling request-handler: {}", tag, requestHandler.getClass().getSimpleName());
        requestHandler.requestReceived(new HttpRequestFrameworkAdapter(request));


        if (callback.isInterrupted()) {
            //plugin requested that execution is interrupted i.e. not passed down the pipeline
            return;
        }
    } else if (e.getMessage() instanceof HttpChunk) {
        LOG.debug("encountered a chunk, not passed to handler");
    }

    super.messageReceived(ctx, e);
}
 
Example 5
Source File: TestOutOfOrderWrite.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 6
Source File: TestOutOfOrderWrite.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 7
Source File: PinpointServerAcceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    final Channel channel = e.getChannel();

    DefaultPinpointServer pinpointServer = (DefaultPinpointServer) channel.getAttachment();
    if (pinpointServer != null) {
        Object message = e.getMessage();

        pinpointServer.messageReceived(message);
    }

    super.messageReceived(ctx, e);
}
 
Example 8
Source File: MemcachedCommandHandler.java    From fqueue with Apache License 2.0 4 votes vote down vote up
/**
 * The actual meat of the matter. Turn CommandMessages into executions
 * against the physical cache, and then pass on the downstream messages.
 * 
 * @param channelHandlerContext
 * @param messageEvent
 * @throws Exception
 */

@Override
@SuppressWarnings("unchecked")
public void messageReceived(ChannelHandlerContext channelHandlerContext, MessageEvent messageEvent)
		throws Exception {
	if (!(messageEvent.getMessage() instanceof CommandMessage)) {
		// Ignore what this encoder can't encode.
		channelHandlerContext.sendUpstream(messageEvent);
		return;
	}

	CommandMessage<CACHE_ELEMENT> command = (CommandMessage<CACHE_ELEMENT>) messageEvent.getMessage();
	Command cmd = command.cmd;
	int cmdKeysSize = command.keys.size();

	// first process any messages in the delete queue
	cache.asyncEventPing();

	// now do the real work
	if (this.verbose) {
		StringBuilder log = new StringBuilder();
		log.append(cmd);
		if (command.element != null) {
			log.append(" ").append(command.element.getKeystring());
		}
		for (int i = 0; i < cmdKeysSize; i++) {
			log.append(" ").append(command.keys.get(i));
		}
		logger.info(log.toString());
	}

	Channel channel = messageEvent.getChannel();
	if (cmd == Command.GET || cmd == Command.GETS) {
		handleGets(channelHandlerContext, command, channel);
	} else if (cmd == Command.SET) {
		handleSet(channelHandlerContext, command, channel);
	} else if (cmd == Command.CAS) {
		handleCas(channelHandlerContext, command, channel);
	} else if (cmd == Command.ADD) {
		handleAdd(channelHandlerContext, command, channel);
	} else if (cmd == Command.REPLACE) {
		handleReplace(channelHandlerContext, command, channel);
	} else if (cmd == Command.APPEND) {
		handleAppend(channelHandlerContext, command, channel);
	} else if (cmd == Command.PREPEND) {
		handlePrepend(channelHandlerContext, command, channel);
	} else if (cmd == Command.INCR) {
		handleIncr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DECR) {
		handleDecr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DELETE) {
		handleDelete(channelHandlerContext, command, channel);
	} else if (cmd == Command.STATS) {
		handleStats(channelHandlerContext, command, cmdKeysSize, channel);
	} else if (cmd == Command.VERSION) {
		handleVersion(channelHandlerContext, command, channel);
	} else if (cmd == Command.QUIT) {
		handleQuit(channel);
	} else if (cmd == Command.FLUSH_ALL) {
		handleFlush(channelHandlerContext, command, channel);
	} else if (cmd == null) {
		// NOOP
		handleNoOp(channelHandlerContext, command);
	} else {
		throw new UnknownCommandException("unknown command:" + cmd);

	}

}
 
Example 9
Source File: MemcachedCommandHandler.java    From fqueue with Apache License 2.0 4 votes vote down vote up
/**
 * The actual meat of the matter. Turn CommandMessages into executions
 * against the physical cache, and then pass on the downstream messages.
 * 
 * @param channelHandlerContext
 * @param messageEvent
 * @throws Exception
 */

@Override
@SuppressWarnings("unchecked")
public void messageReceived(ChannelHandlerContext channelHandlerContext, MessageEvent messageEvent)
		throws Exception {
	if (!(messageEvent.getMessage() instanceof CommandMessage)) {
		// Ignore what this encoder can't encode.
		channelHandlerContext.sendUpstream(messageEvent);
		return;
	}

	CommandMessage<CACHE_ELEMENT> command = (CommandMessage<CACHE_ELEMENT>) messageEvent.getMessage();
	Command cmd = command.cmd;
	int cmdKeysSize = command.keys.size();

	// first process any messages in the delete queue
	cache.asyncEventPing();

	// now do the real work
	if (this.verbose) {
		StringBuilder log = new StringBuilder();
		log.append(cmd);
		if (command.element != null) {
			log.append(" ").append(command.element.getKeystring());
		}
		for (int i = 0; i < cmdKeysSize; i++) {
			log.append(" ").append(command.keys.get(i));
		}
		logger.info(log.toString());
	}

	Channel channel = messageEvent.getChannel();
	if (cmd == Command.GET || cmd == Command.GETS) {
		handleGets(channelHandlerContext, command, channel);
	} else if (cmd == Command.SET) {
		handleSet(channelHandlerContext, command, channel);
	} else if (cmd == Command.CAS) {
		handleCas(channelHandlerContext, command, channel);
	} else if (cmd == Command.ADD) {
		handleAdd(channelHandlerContext, command, channel);
	} else if (cmd == Command.REPLACE) {
		handleReplace(channelHandlerContext, command, channel);
	} else if (cmd == Command.APPEND) {
		handleAppend(channelHandlerContext, command, channel);
	} else if (cmd == Command.PREPEND) {
		handlePrepend(channelHandlerContext, command, channel);
	} else if (cmd == Command.INCR) {
		handleIncr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DECR) {
		handleDecr(channelHandlerContext, command, channel);
	} else if (cmd == Command.DELETE) {
		handleDelete(channelHandlerContext, command, channel);
	} else if (cmd == Command.STATS) {
		handleStats(channelHandlerContext, command, cmdKeysSize, channel);
	} else if (cmd == Command.VERSION) {
		handleVersion(channelHandlerContext, command, channel);
	} else if (cmd == Command.QUIT) {
		handleQuit(channel);
	} else if (cmd == Command.FLUSH_ALL) {
		handleFlush(channelHandlerContext, command, channel);
	} else if (cmd == null) {
		// NOOP
		handleNoOp(channelHandlerContext, command);
	} else {
		throw new UnknownCommandException("unknown command:" + cmd);

	}

}