本文整理汇总了Java中org.jboss.netty.channel.MessageEvent类的典型用法代码示例。如果您正苦于以下问题:Java MessageEvent类的具体用法?Java MessageEvent怎么用?Java MessageEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageEvent类属于org.jboss.netty.channel包,在下文中一共展示了MessageEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
Object msg = e.getMessage();
if (!(msg instanceof RpcRequest)) {
logger.error("not RpcRequest received!");
return;
}
RpcRequest request = (RpcRequest) msg;
ctx.setAttachment(request);
RpcResponse response = new RpcResponse(request.getRequestID());
try {
Object result = handle(request);
response.setResult(result);
} catch (Throwable t) {
logger.error("handle rpc request fail! request:"+request, t);
response.setException(t);
}
e.getChannel().write(response);
}
示例2: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception
{
if (LOG.isTraceEnabled()) {
LOG.trace("message received called " + e.getMessage());
}
try {
if (LOG.isDebugEnabled()) {
LOG.debug("New message " + e.toString()
+ " from " + ctx.getChannel());
}
NettyServerCnxn cnxn = (NettyServerCnxn)ctx.getAttachment();
synchronized(cnxn) {
processMessage(e, cnxn);
}
} catch(Exception ex) {
LOG.error("Unexpected exception in receive", ex);
throw ex;
}
}
示例3: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
public static void messageReceived(MessageEvent e) {
String msgName = e.getMessage().getClass().getName();
if (msgName.equals(SLoginMsg.class.getName())) {
sendToLogin(e);
} else if (msgName.equals(SRecommendListMsg.class.getName())) {
sendToRecommend(e);
} else if (msgName.equals(SHelpMeMsg.class.getName())) {
sendToHelpMeMsg(e);
} else if (msgName.equals(SMeHelpMsg.class.getName())) {
sendToMeHelpMsg(e);
} else if (msgName.equals(SFriendList.class.getName())) {
sendToFriend(e);
} else if (msgName.equals(SChatMessage.class.getName())) {
sendToChat(e);
} else if (msgName.equals(SSelectReqMsg.class.getName())) {
sendToQuery(e);
} else if (msgName.equals(SRegisterMsg.class.getName())) {
sendToRegister(e);
} else if (msgName.equals(SPhotoRequestMsg.class.getName())) {
sendToPhoto(e);
} else if (msgName.equals(SUserInfoRequest.class.getName())) {
sendToInformation(e);
} else if(msgName.equals(SOrderMsg.class.getName())) {
sendToInformation1(e);
}
}
示例4: sendToInformation1
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
private static void sendToInformation1(MessageEvent e) {
SOrderMsg msg = (SOrderMsg) e.getMessage();
if (isCurrUI(Config.TAG_InformationActivity)) {
sOrderMsgListener.onSOrderMsgReceived(msg);
} else {
Intent intent = new Intent(currContext, InformationActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("TAG", Config.TAG_SOrderMsg);
bundle.putSerializable("SOrderMsg", msg);
intent.putExtras(bundle);
String content = "";
String title = msg.getReqDetail();
if(msg.getOrderType() == OrderMsgType.REQUEST) {
content = "嗨,有人帮助你啦,快来看吧!";
} else {
if(msg.isbOrdered()) {
content = "嗨,你们已经正在交易中了";
}
}
myNotifi(1000,intent, title, content);
}
}
示例5: sendToHelpMeMsg
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
public static void sendToHelpMeMsg(MessageEvent e) {
SHelpMeMsg msg = (SHelpMeMsg) e.getMessage();
synchronized (String.class) {
if(DataHiBang.sHelpMeMsgList.size()>=10) {
DataHiBang.sHelpMeMsgList.remove(0);
}
DataHiBang.sHelpMeMsgList.add(msg);
}
if (isCurrUI(Config.TAG_MessageActivity)) {
sHelpMeMsgListener.onHelpMeMsgReveived(msg);
} else {
// Intent intent = new Intent(currContext, MessageActivity.class);
myMainTabListener.onMsgReveived(msg);
Intent intent = new Intent(currContext, InformationActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("TAG", Config.TAG_HelpMeMessage);
MySHelpMeMsg helpMeMsg = new MySHelpMeMsg(msg);
bundle.putSerializable("helpMeMessage", helpMeMsg);
intent.putExtras(bundle);
myNotifi(1002,intent, msg.getHelpName(), msg.getReqItem());
}
}
示例6: sendToChat
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
public static void sendToChat(MessageEvent e) {
SChatMessage msg = (SChatMessage) e.getMessage();
if (msg.getSenderID() == chattingUserId) {
DBManage.addSChatMsg(msg, false);
myChattingListener.onMsgReceived(msg);
} else {
DBManage.addSChatMsg(msg, true);
Intent intent = new Intent(currContext, ChatActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("friendId", msg.getSenderID());
bundle.putString("friendName", msg.getReceiverName());
intent.putExtras(bundle);
String title = "嗨帮-聊天消息 (共1条未读)";
myNotifi(1003,intent,title,msg.getChatContent());
// sChatMessageListener.onMsgReveived(msg);
}
}
示例7: sendToRecommend
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
public static void sendToRecommend(MessageEvent e) {
SRecommendListMsg msg = (SRecommendListMsg) e.getMessage();
// DBManage.addRequirement(msg.getRecommendList(), true);
synchronized (String.class) {
if(DataHiBang.sRecommMsgList.size()>25) {
int n = DataHiBang.sRecommMsgList.size() - 25;
for(int i=0;i<n;i++) {
DataHiBang.sRecommMsgList.remove(i);
}
}
DataHiBang.sRecommMsgList.addAll(msg.getRecommendList());
}
if (isCurrUI(Config.TAG_RecommendActivity)) {
sRlMsgListener.onMsgReveived(msg);
} else {
Intent intent = new Intent(currContext, MainTabActivity.class);
myNotifi(1004,intent, "快来帮助别人吧······", msg.getRecommendList().get(0).getReqDetail());
}
}
示例8: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (e.getMessage() instanceof ChannelBuffer) {
ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
int bytesToRead = Math.min(currentChunkSize - bytesRead, buffer.readableBytes());
buffer.readBytes(getMailEnvelope().getMessageOutputStream(), bytesToRead);
bytesRead += bytesToRead;
if (bytesRead == currentChunkSize) {
stopCapturingData();
}
return;
}
super.messageReceived(ctx, e);
}
示例9: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
RpcInfo info = (RpcInfo) e.getMessage();
RpcCall call = (RpcCall) info.header();
SocketAddress remoteAddress = info.remoteAddress();
if (LOG.isTraceEnabled()) {
LOG.trace(program + " procedure #" + call.getProcedure());
}
if (this.progNumber != call.getProgram()) {
LOG.warn("Invalid RPC call program " + call.getProgram());
sendAcceptedReply(call, remoteAddress, AcceptState.PROG_UNAVAIL, ctx);
return;
}
int ver = call.getVersion();
if (ver < lowProgVersion || ver > highProgVersion) {
LOG.warn("Invalid RPC call version " + ver);
sendAcceptedReply(call, remoteAddress, AcceptState.PROG_MISMATCH, ctx);
return;
}
handleInternal(ctx, info);
}
示例10: 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);
}
}
示例11: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
if (e.getMessage() instanceof List) {
@SuppressWarnings("unchecked")
List<OFMessage> msglist = (List<OFMessage>) e.getMessage();
for (OFMessage ofm : msglist) {
// Do the actual packet processing
state.processOFMessage(this, ofm);
}
} else {
state.processOFMessage(this, (OFMessage) e.getMessage());
}
}
示例12: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx,
MessageEvent e) throws Exception {
Object message = e.getMessage();
if (message instanceof SyncMessage) {
handleSyncMessage((SyncMessage)message, ctx.getChannel());
} else if (message instanceof List) {
for (Object i : (List<?>)message) {
if (i instanceof SyncMessage) {
try {
handleSyncMessage((SyncMessage)i,
ctx.getChannel());
} catch (Exception ex) {
Channels.fireExceptionCaught(ctx, ex);
}
}
}
} else {
handleUnknownMessage(ctx, message);
}
}
示例13: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
if (e.getMessage() instanceof List) {
@SuppressWarnings("unchecked")
List<OFMessage> msglist = (List<OFMessage>)e.getMessage();
for (OFMessage ofm : msglist) {
try {
// Do the actual packet processing
state.processOFMessage(ofm);
}
catch (Exception ex) {
// We are the last handler in the stream, so run the
// exception through the channel again by passing in
// ctx.getChannel().
Channels.fireExceptionCaught(ctx.getChannel(), ex);
}
}
}
else {
Channels.fireExceptionCaught(ctx.getChannel(),
new AssertionError("Message received from channel is not a list"));
}
}
示例14: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
lock.lock();
try {
// construct response
if( e.getMessage() instanceof Request) {
Request req = (Request) e.getMessage();
resp =req;
logger.info("receive "+ req.toString() +" from "+e.getRemoteAddress().toString() );
}
else {
logger.info( e.getMessage().getClass().getName()+" len " + e.getMessage().toString().length()
+" "+ e.getChannel().getRemoteAddress().toString() );
resp = null;
}
//throw new RuntimeException( e.getMessage().getClass().getName()+" is not supported");
} finally {
cleanUp();
lock.unlock();
}
// Server is supposed to send nothing. Therefore, do nothing.
}
示例15: messageReceived
import org.jboss.netty.channel.MessageEvent; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
Request req = (Request) e.getMessage();
logger.info("receive " + req.toString()+" from "+e.getRemoteAddress().toString());
// it might need to create a different copy
Header header = new Header( req.getHeader().getName(), req.getHeader().getVersion(), req.getHeader().getRelease(),
req.getHeader().getNodeId());
Response response = null;
try {
Invoker invoker = (Invoker) serializer.toObject( req.getPayload() );
response = invoke( invoker );
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
response = new Response( ex.getMessage(), true);
} finally {
byte[] payload = serializer.toBytes( response);
Request request = new Request(header, payload , Request.RequestType.Response );
ctx.getChannel().write(request);
}
}