KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > TransportServerThreadSupport


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport;
19
20
21 import org.apache.activemq.ThreadPriorities;
22 import org.apache.activemq.util.ServiceStopper;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 import java.net.URI JavaDoc;
27
28 /**
29  * A useful base class for implementations of {@link TransportServer} which uses
30  * a background thread to accept new connections.
31  *
32  * @version $Revision: 1.1 $
33  */

34 public abstract class TransportServerThreadSupport extends TransportServerSupport implements Runnable JavaDoc {
35     private static final Log log = LogFactory.getLog(TransportServerThreadSupport.class);
36
37     private boolean daemon = true;
38     private boolean joinOnStop = true;
39     private Thread JavaDoc runner;
40     private long stackSize=0;//should be a multiple of 128k
41

42     public TransportServerThreadSupport() {
43     }
44
45     public TransportServerThreadSupport(URI JavaDoc location) {
46         super(location);
47     }
48
49     public boolean isDaemon() {
50         return daemon;
51     }
52
53     /**
54      * Sets whether the background read thread is a daemon thread or not
55      */

56     public void setDaemon(boolean daemon) {
57         this.daemon = daemon;
58     }
59
60     
61     public boolean isJoinOnStop() {
62         return joinOnStop;
63     }
64
65     /**
66      * Sets whether the background read thread is joined with (waited for) on a stop
67      */

68     public void setJoinOnStop(boolean joinOnStop) {
69         this.joinOnStop = joinOnStop;
70     }
71
72     protected void doStart() throws Exception JavaDoc {
73         log.info("Listening for connections at: " + getConnectURI());
74         runner = new Thread JavaDoc(null,this, "ActiveMQ Transport Server: "+toString(),stackSize);
75         runner.setDaemon(daemon);
76         runner.setPriority(ThreadPriorities.BROKER_MANAGEMENT);
77         runner.start();
78     }
79
80     protected void doStop(ServiceStopper stopper) throws Exception JavaDoc {
81         if (runner != null && joinOnStop) {
82             runner.join();
83             runner = null;
84         }
85     }
86
87     
88     /**
89      * @return the stackSize
90      */

91     public long getStackSize(){
92         return this.stackSize;
93     }
94
95     
96     /**
97      * @param stackSize the stackSize to set
98      */

99     public void setStackSize(long stackSize){
100         this.stackSize=stackSize;
101     }
102 }
103
Popular Tags