本文整理汇总了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);
}
}
示例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();
}
示例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");
}
示例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);
}
}
});
}
}