1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.netty.channel.socket.oio;
18
19 import org.jboss.netty.channel.AbstractChannelSink;
20 import org.jboss.netty.channel.Channel;
21 import org.jboss.netty.channel.ChannelEvent;
22 import org.jboss.netty.channel.ChannelFuture;
23 import org.jboss.netty.channel.ChannelPipeline;
24 import org.jboss.netty.channel.socket.ChannelRunnableWrapper;
25 import org.jboss.netty.channel.socket.Worker;
26
27 public abstract class AbstractOioChannelSink extends AbstractChannelSink {
28
29 @Override
30 public ChannelFuture execute(final ChannelPipeline pipeline, final Runnable task) {
31 Channel ch = pipeline.getChannel();
32 if (ch instanceof AbstractOioChannel) {
33 AbstractOioChannel channel = (AbstractOioChannel) ch;
34 Worker worker = channel.worker;
35 if (worker != null) {
36 ChannelRunnableWrapper wrapper = new ChannelRunnableWrapper(pipeline.getChannel(), task);
37 channel.worker.executeInIoThread(wrapper);
38 return wrapper;
39 }
40 }
41
42 return super.execute(pipeline, task);
43 }
44
45 @Override
46 protected boolean isFireExceptionCaughtLater(ChannelEvent event, Throwable actualCause) {
47 Channel channel = event.getChannel();
48 boolean fireLater = false;
49 if (channel instanceof AbstractOioChannel) {
50 fireLater = !AbstractOioWorker.isIoThread((AbstractOioChannel) channel);
51 }
52 return fireLater;
53 }
54
55 }