1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.execution;
17
18 import org.jboss.netty.channel.Channel;
19 import org.jboss.netty.channel.ChannelEvent;
20 import org.jboss.netty.channel.ChannelFuture;
21 import org.jboss.netty.channel.ChannelFutureListener;
22 import org.jboss.netty.util.ObjectSizeEstimator;
23
24 import java.util.concurrent.Executor;
25 import java.util.concurrent.Executors;
26 import java.util.concurrent.RejectedExecutionException;
27 import java.util.concurrent.ThreadFactory;
28 import java.util.concurrent.TimeUnit;
29
30
31
32
33
34
35
36
37
38
39 public final class OrderedDownstreamThreadPoolExecutor extends OrderedMemoryAwareThreadPoolExecutor {
40
41
42
43
44
45
46 public OrderedDownstreamThreadPoolExecutor(int corePoolSize) {
47 super(corePoolSize, 0L, 0L);
48 }
49
50
51
52
53
54
55
56
57 public OrderedDownstreamThreadPoolExecutor(
58 int corePoolSize, long keepAliveTime, TimeUnit unit) {
59 super(corePoolSize, 0L, 0L, keepAliveTime, unit);
60 }
61
62
63
64
65
66
67
68
69
70 public OrderedDownstreamThreadPoolExecutor(
71 int corePoolSize, long keepAliveTime, TimeUnit unit, ThreadFactory threadFactory) {
72 super(corePoolSize, 0L, 0L,
73 keepAliveTime, unit, threadFactory);
74 }
75
76
77
78
79 @Override
80 public ObjectSizeEstimator getObjectSizeEstimator() {
81 return null;
82 }
83
84
85
86
87
88 @Override
89 public void setObjectSizeEstimator(ObjectSizeEstimator objectSizeEstimator) {
90 throw new UnsupportedOperationException("Not supported by this implementation");
91 }
92
93
94
95
96 @Override
97 public long getMaxChannelMemorySize() {
98 return 0L;
99 }
100
101
102
103
104
105 @Override
106 public void setMaxChannelMemorySize(long maxChannelMemorySize) {
107 throw new UnsupportedOperationException("Not supported by this implementation");
108 }
109
110
111
112
113 @Override
114 public long getMaxTotalMemorySize() {
115 return 0L;
116 }
117
118
119
120
121 @Override
122 protected boolean shouldCount(Runnable task) {
123 return false;
124 }
125
126 @Override
127 public void execute(Runnable command) {
128
129
130 if (command instanceof ChannelUpstreamEventRunnable) {
131 throw new RejectedExecutionException("command must be enclosed with an downstream event.");
132 }
133 doExecute(command);
134 }
135
136 @Override
137 protected Executor getChildExecutor(ChannelEvent e) {
138 final Object key = getChildExecutorKey(e);
139 Executor executor = childExecutors.get(key);
140 if (executor == null) {
141 executor = new ChildExecutor();
142 Executor oldExecutor = childExecutors.putIfAbsent(key, executor);
143 if (oldExecutor != null) {
144 executor = oldExecutor;
145 } else {
146
147 e.getChannel().getCloseFuture().addListener(new ChannelFutureListener() {
148
149 public void operationComplete(ChannelFuture future) throws Exception {
150 removeChildExecutor(key);
151 }
152 });
153 }
154 }
155
156 return executor;
157 }
158 }