1 /*
2 * Copyright 2012 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package org.jboss.netty.channel.socket.nio;
17
18 import org.jboss.netty.util.HashedWheelTimer;
19 import org.jboss.netty.util.ThreadNameDeterminer;
20 import org.jboss.netty.util.Timer;
21
22 import java.util.concurrent.Executor;
23
24 /**
25 * Holds {@link NioClientBoss} instances to use
26 */
27 public class NioClientBossPool extends AbstractNioBossPool<NioClientBoss> {
28 private final ThreadNameDeterminer determiner;
29 private final Timer timer;
30 private boolean stopTimer;
31
32 /**
33 * Create a new instance
34 *
35 * @param bossExecutor the Executor to use for server the {@link NioClientBoss}
36 * @param bossCount the number of {@link NioClientBoss} instances this {@link NioClientBossPool} will hold
37 * @param timer the Timer to use for handle connect timeouts
38 * @param determiner the {@link ThreadNameDeterminer} to use for name the threads. Use {@code null}
39 * if you not want to set one explicit.
40 */
41 public NioClientBossPool(Executor bossExecutor, int bossCount, Timer timer, ThreadNameDeterminer determiner) {
42 super(bossExecutor, bossCount, false);
43 this.determiner = determiner;
44 this.timer = timer;
45 init();
46 }
47
48 /**
49 * Create a new instance using a new {@link HashedWheelTimer} and no {@link ThreadNameDeterminer}
50 *
51 * @param bossExecutor the Executor to use for server the {@link NioClientBoss}
52 * @param bossCount the number of {@link NioClientBoss} instances this {@link NioClientBoss} will hold
53 */
54 public NioClientBossPool(Executor bossExecutor, int bossCount) {
55 this(bossExecutor, bossCount, new HashedWheelTimer(), null);
56 stopTimer = true;
57 }
58
59 @Override
60 protected NioClientBoss newBoss(Executor executor) {
61 return new NioClientBoss(executor, timer, determiner);
62 }
63
64 @Override
65 public void shutdown() {
66 super.shutdown();
67 if (stopTimer) {
68 timer.stop();
69 }
70 }
71
72 @Override
73 public void releaseExternalResources() {
74 super.releaseExternalResources();
75 timer.stop();
76 }
77 }
78