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 java.util.concurrent.Executor;
19 import java.util.concurrent.Executors;
20 import java.util.concurrent.RejectedExecutionException;
21 import java.util.concurrent.ThreadFactory;
22 import java.util.concurrent.TimeUnit;
23
24 import org.jboss.netty.channel.Channel;
25 import org.jboss.netty.channel.ChannelEvent;
26 import org.jboss.netty.channel.ChannelFuture;
27 import org.jboss.netty.channel.ChannelFutureListener;
28 import org.jboss.netty.util.ObjectSizeEstimator;
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
80 @Override
81 public ObjectSizeEstimator getObjectSizeEstimator() {
82 return null;
83 }
84
85
86
87
88
89 @Override
90 public void setObjectSizeEstimator(ObjectSizeEstimator objectSizeEstimator) {
91 throw new UnsupportedOperationException("Not supported by this implementation");
92 }
93
94
95
96
97 @Override
98 public long getMaxChannelMemorySize() {
99 return 0L;
100 }
101
102
103
104
105
106 @Override
107 public void setMaxChannelMemorySize(long maxChannelMemorySize) {
108 throw new UnsupportedOperationException("Not supported by this implementation");
109 }
110
111
112
113
114 @Override
115 public long getMaxTotalMemorySize() {
116 return 0L;
117 }
118
119
120
121
122
123 @Override
124 public void setMaxTotalMemorySize(long maxTotalMemorySize) {
125 throw new UnsupportedOperationException("Not supported by this implementation");
126 }
127
128
129
130
131 @Override
132 protected boolean shouldCount(Runnable task) {
133 return false;
134 }
135
136 @Override
137 public void execute(Runnable command) {
138
139
140 if (command instanceof ChannelUpstreamEventRunnable) {
141 throw new RejectedExecutionException("command must be enclosed with an downstream event.");
142 }
143 doExecute(command);
144 }
145
146 @Override
147 protected Executor getChildExecutor(ChannelEvent e) {
148 final Object key = getChildExecutorKey(e);
149 Executor executor = childExecutors.get(key);
150 if (executor == null) {
151 executor = new ChildExecutor();
152 Executor oldExecutor = childExecutors.putIfAbsent(key, executor);
153 if (oldExecutor != null) {
154 executor = oldExecutor;
155 } else {
156
157
158 e.getChannel().getCloseFuture().addListener(new ChannelFutureListener() {
159
160 public void operationComplete(ChannelFuture future) throws Exception {
161 removeChildExecutor(key);
162 }
163 });
164 }
165 }
166
167 return executor;
168 }
169
170
171 }