本文整理汇总了Java中org.jboss.netty.channel.ChannelHandlerContext.sendUpstream方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelHandlerContext.sendUpstream方法的具体用法?Java ChannelHandlerContext.sendUpstream怎么用?Java ChannelHandlerContext.sendUpstream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.ChannelHandlerContext
的用法示例。
在下文中一共展示了ChannelHandlerContext.sendUpstream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleUpstream
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的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());
}
}
}
}
示例2: channelOpen
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
if (timeoutNanos > 0) {
timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx),
timeoutNanos, TimeUnit.NANOSECONDS);
}
ctx.sendUpstream(e);
}
示例3: channelOpen
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
if (timeoutNanos > 0) {
timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx),
timeoutNanos, TimeUnit.NANOSECONDS);
}
ctx.sendUpstream(e);
}
示例4: messageReceived
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的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());
}
}
示例5: exceptionCaught
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
ctx.sendUpstream(e);
}
示例6: handleUpstream
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的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());
}
}
示例7: handleUpstream
import org.jboss.netty.channel.ChannelHandlerContext; //导入方法依赖的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());
}
}