本文整理汇总了Java中org.jboss.netty.channel.Channels.fireMessageReceived方法的典型用法代码示例。如果您正苦于以下问题:Java Channels.fireMessageReceived方法的具体用法?Java Channels.fireMessageReceived怎么用?Java Channels.fireMessageReceived使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.Channels
的用法示例。
在下文中一共展示了Channels.fireMessageReceived方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: messageReceived
import org.jboss.netty.channel.Channels; //导入方法依赖的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: handleUpstream
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
@Override
public void handleUpstream(
ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
if (!(evt instanceof MessageEvent)) {
ctx.sendUpstream(evt);
return;
}
MessageEvent e = (MessageEvent) evt;
Object originalMessage = e.getMessage();
Object decodedMessage = decode(e.getChannel(), e.getRemoteAddress(), originalMessage);
onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage, decodedMessage);
if (originalMessage == decodedMessage) {
ctx.sendUpstream(evt);
} else {
if (decodedMessage == null) {
decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
}
if (decodedMessage != null) {
if (decodedMessage instanceof Collection) {
for (Object o : (Collection) decodedMessage) {
saveOriginal(o, originalMessage);
Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
}
} else {
saveOriginal(decodedMessage, originalMessage);
Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
}
}
}
示例3: messageReceived
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
this.cumulation = new ArrayList<WebSocketFrame>();
super.messageReceived(ctx, e);
// batch FireMessageReceived
if (this.cumulation.size() > 0) {
Channels.fireMessageReceived(ctx, cumulation, e.getRemoteAddress());
}
}
示例4: handleIncr
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
protected void handleIncr(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
Channel channel) throws DatabaseException, Exception {
Integer incrDecrResp = cache.get_add(command.keys.get(0), command.incrAmount); // TODO
// support
// default
// value
// and
// expiry!!
Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command)
.withIncrDecrResponse(incrDecrResp), channel.getRemoteAddress());
}
示例5: handlePrepend
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
protected void handlePrepend(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
Channel channel) throws DatabaseException, Exception {
Cache.StoreResponse ret;
ret = cache.prepend(command.element);
Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel
.getRemoteAddress());
}
示例6: handleReplace
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
protected void handleReplace(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
Channel channel) throws DatabaseException, Exception {
Cache.StoreResponse ret;
ret = cache.replace(command.element);
Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel
.getRemoteAddress());
}
示例7: handleAdd
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
protected void handleAdd(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
Channel channel) throws DatabaseException, Exception {
Cache.StoreResponse ret;
ret = cache.add(command.element);
Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel
.getRemoteAddress());
}
示例8: handleCas
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
protected void handleCas(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
Channel channel) throws DatabaseException, Exception {
Cache.StoreResponse ret;
ret = cache.cas(command.cas_key, command.element);
Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel
.getRemoteAddress());
}
示例9: handleSet
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
protected void handleSet(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
Channel channel) throws DatabaseException, Exception {
Cache.StoreResponse ret;
ret = cache.set(command.element);
Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel
.getRemoteAddress());
}
示例10: messageReceived
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
Object o = event.getMessage();
if (! (o instanceof ChannelBuffer)) {
ctx.sendUpstream(event);
return;
}
ChannelBuffer input = (ChannelBuffer) o;
int readable = input.readableBytes();
if (readable <= 0) {
return;
}
com.alibaba.dubbo.remoting.buffer.ChannelBuffer message;
if (buffer.readable()) {
if (buffer instanceof DynamicChannelBuffer) {
buffer.writeBytes(input.toByteBuffer());
message = buffer;
} else {
int size = buffer.readableBytes() + input.readableBytes();
message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.dynamicBuffer(
size > bufferSize ? size : bufferSize);
message.writeBytes(buffer, buffer.readableBytes());
message.writeBytes(input.toByteBuffer());
}
} else {
message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.wrappedBuffer(
input.toByteBuffer());
}
NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
Object msg;
int saveReaderIndex;
try {
// decode object.
do {
saveReaderIndex = message.readerIndex();
try {
msg = codec.decode(channel, message);
} catch (IOException e) {
buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER;
throw e;
}
if (msg == Codec2.DecodeResult.NEED_MORE_INPUT) {
message.readerIndex(saveReaderIndex);
break;
} else {
if (saveReaderIndex == message.readerIndex()) {
buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER;
throw new IOException("Decode without read data.");
}
if (msg != null) {
Channels.fireMessageReceived(ctx, msg, event.getRemoteAddress());
}
}
} while (message.readable());
} finally {
if (message.readable()) {
message.discardReadBytes();
buffer = message;
} else {
buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER;
}
NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
}
}
示例11: handleUpstream
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
@Override
public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
if (!(evt instanceof MessageEvent)) {
ctx.sendUpstream(evt);
return;
}
final MessageEvent event = (MessageEvent) evt;
Object message = event.getMessage();
if (message instanceof Position) {
final Position position = (Position) message;
if ((position.getOutdated() || processInvalidPositions && !position.getValid())
&& position.getNetwork() != null) {
Context.getStatisticsManager().registerGeolocationRequest();
geolocationProvider.getLocation(position.getNetwork(),
new GeolocationProvider.LocationProviderCallback() {
@Override
public void onSuccess(double latitude, double longitude, double accuracy) {
position.set(Position.KEY_APPROXIMATE, true);
position.setValid(true);
position.setFixTime(position.getDeviceTime());
position.setLatitude(latitude);
position.setLongitude(longitude);
position.setAccuracy(accuracy);
position.setAltitude(0);
position.setSpeed(0);
position.setCourse(0);
position.set(Position.KEY_RSSI, 0);
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
@Override
public void onFailure(Throwable e) {
Log.warning(e);
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
});
} else {
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
} else {
Channels.fireMessageReceived(ctx, message, event.getRemoteAddress());
}
}
示例12: handleUpstream
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
@Override
public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
if (!(evt instanceof MessageEvent)) {
ctx.sendUpstream(evt);
return;
}
final MessageEvent event = (MessageEvent) evt;
Object message = event.getMessage();
if (message instanceof Position) {
final Position position = (Position) message;
if (processInvalidPositions || position.getValid()) {
if (geocoderReuseDistance != 0) {
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
if (lastPosition != null && lastPosition.getAddress() != null
&& position.getDouble(Position.KEY_DISTANCE) <= geocoderReuseDistance) {
position.setAddress(lastPosition.getAddress());
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
return;
}
}
Context.getStatisticsManager().registerGeocoderRequest();
geocoder.getAddress(addressFormat, position.getLatitude(), position.getLongitude(),
new Geocoder.ReverseGeocoderCallback() {
@Override
public void onSuccess(String address) {
position.setAddress(address);
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
@Override
public void onFailure(Throwable e) {
Log.warning("Geocoding failed", e);
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
});
} else {
Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
}
} else {
Channels.fireMessageReceived(ctx, message, event.getRemoteAddress());
}
}
示例13: sendRpcResponse
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
public static void sendRpcResponse(ChannelHandlerContext ctx,
RpcResponse response) {
Channels.fireMessageReceived(ctx, response);
}
示例14: messageReceived
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
Object o = event.getMessage();
if (! (o instanceof ChannelBuffer)) {
ctx.sendUpstream(event);
return;
}
// FIXME 获取netty的channel add by jileng
ChannelBuffer input = (ChannelBuffer) o;
int readable = input.readableBytes();
if (readable <= 0) {
return;
}
com.alibaba.dubbo.remoting.buffer.ChannelBuffer message;
if (buffer.readable()) {
if (buffer instanceof DynamicChannelBuffer) {
//FIXME 读取netty buf的数据到 com.alibaba.dubbo.remoting.buffer.ChannelBuffer add by jileng
buffer.writeBytes(input.toByteBuffer());
message = buffer;
} else {
int size = buffer.readableBytes() + input.readableBytes();
message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.dynamicBuffer(
size > bufferSize ? size : bufferSize);
message.writeBytes(buffer, buffer.readableBytes());
message.writeBytes(input.toByteBuffer());
}
} else {
message = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.wrappedBuffer(
input.toByteBuffer());
}
NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
Object msg;
int saveReaderIndex;
try {
// decode object.
do {
saveReaderIndex = message.readerIndex();
try {
msg = codec.decode(channel, message);
} catch (IOException e) {
buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER;
throw e;
}
if (msg == Codec2.DecodeResult.NEED_MORE_INPUT) {
message.readerIndex(saveReaderIndex);
break;
} else {
if (saveReaderIndex == message.readerIndex()) {
buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER;
throw new IOException("Decode without read data.");
}
//FIXME 一个完整的consumer消息已经接收完成 add by jileng
if (msg != null) {
//FIXME fireMessageReceived => NettyHandler中的messageReceived()被触发 add by jileng
Channels.fireMessageReceived(ctx, msg, event.getRemoteAddress());
}
}
} while (message.readable());
} finally {
if (message.readable()) {
message.discardReadBytes();
buffer = message;
} else {
buffer = com.alibaba.dubbo.remoting.buffer.ChannelBuffers.EMPTY_BUFFER;
}
NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
}
}
示例15: fireMessageReceived
import org.jboss.netty.channel.Channels; //导入方法依赖的package包/类
private void fireMessageReceived(ChannelHandlerContext context, SocketAddress remoteAddress, Object result) {
Channels.fireMessageReceived(context, result, remoteAddress);
}