KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > work > WorkManagerImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.jbi.serviceengine.work;
25
26 import java.util.logging.Logger JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import com.sun.corba.ee.spi.orbutil.threadpool.ThreadPool;
29 import com.sun.corba.ee.spi.orbutil.threadpool.ThreadPoolManager;
30 import com.sun.corba.ee.spi.orbutil.threadpool.NoSuchThreadPoolException;
31 import com.sun.enterprise.jbi.serviceengine.comm.MessageAcceptor;
32 import com.sun.enterprise.jbi.serviceengine.config.ComponentConfiguration;
33 import com.sun.enterprise.jbi.serviceengine.ServiceEngineException;
34 import com.sun.enterprise.util.S1ASThreadPoolManager;
35 import com.sun.logging.LogDomains;
36
37 /**
38  * Work Manager implementation for JBI Service Engine.
39  *
40  * @author Binod PG
41  */

42 public class WorkManagerImpl implements WorkManager, Runnable JavaDoc {
43
44     
45     private ComponentConfiguration config = null;
46     private String JavaDoc threadPoolName = null;
47     private ThreadPoolManager tpm = null;
48     private ThreadPool tp = null;
49     private MessageAcceptor acceptor= null;
50
51     private static Logger JavaDoc logger =
52         LogDomains.getLogger(LogDomains.SERVER_LOGGER);
53
54     /**
55      * Saves the static service engine instance for use by
56      * work manager. Also obtains configured thread pool name.
57      */

58     public WorkManagerImpl(ComponentConfiguration config) {
59         this.config = config;
60         this.threadPoolName = this.config.getCommonThreadPoolName();
61     }
62
63     /**
64      * Set the name of thread pool.
65      */

66     public void setPoolName(String JavaDoc poolName) {
67         this.threadPoolName = poolName;
68     }
69
70     /**
71      * Retrieves the name of the thread pool used by this
72      * work manager.
73      */

74     public String JavaDoc getPoolName() {
75         return this.threadPoolName;
76     }
77
78     /**
79      * Retrieves the MessageAcceptor of the work manager.
80      */

81     public MessageAcceptor getMessageAcceptor() {
82         return this.acceptor;
83     }
84
85     /**
86      * Submit a work to the queue of the thread pool.
87      * We just submit to a random queue of the thread pool.
88      *
89      * @param work Work object as specified by the Appserver
90      * thread pool interface.
91      */

92     public void submitWork(OneWork work) {
93         tp.getAnyWorkQueue().addWork(work);
94     }
95
96     /**
97      * Start the message acceptor thread.
98      */

99     public void startAcceptor() throws ServiceEngineException {
100         tpm = S1ASThreadPoolManager.getThreadPoolManager();
101
102         if (getPoolName() == null) {
103             // This will be default orb thread pool
104
tp = tpm.getDefaultThreadPool();
105         } else {
106             try {
107                 tp = tpm.getThreadPool(getPoolName());
108                 if (logger.isLoggable(Level.FINE)) {
109                     logger.log(Level.FINE,
110                     "Got the thread pool for :" + getPoolName());
111                 }
112             } catch (NoSuchThreadPoolException e) {
113                 logger.log(Level.SEVERE,
114                 "workmanager.threadpool_not_found", getPoolName());
115                 throw new ServiceEngineException(e.getMessage());
116             }
117         }
118         this.acceptor = new MessageAcceptor();
119         this.acceptor.startAccepting();
120     }
121
122     /**
123      * Convenience method to release acceptor thread.
124      */

125     public void stop() {
126         this.acceptor.release();
127     }
128     
129     public void run() {
130         try {
131             startAcceptor();
132         } catch(ServiceEngineException se) {
133             se.printStackTrace();
134         } finally {
135             stop();
136         }
137     }
138 }
139
Popular Tags