KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > quartz > inflow > JBossQuartzThreadPool


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.adapter.quartz.inflow;
23
24 import org.quartz.SchedulerConfigException;
25
26 import javax.resource.spi.work.Work JavaDoc;
27 import javax.resource.spi.work.WorkException JavaDoc;
28 import javax.resource.spi.work.WorkManager JavaDoc;
29
30 /**
31  * Thread pool used to fire Quartz Jobs.
32  * <p/>
33  * Using BootstrapContext's workManager thread pool.
34  * No dependency outside this rar or JCA.
35  *
36  * @see http://jira.jboss.com/jira/browse/JBAS-1792
37  * @see quartz.properties
38  *
39  * @author <a HREF="mailto:ales.justin@gmail.com">Ales Justin</a>
40  */

41 public class JBossQuartzThreadPool implements org.quartz.spi.ThreadPool
42 {
43    private int poolSize = Integer.MAX_VALUE;
44
45    private WorkManager JavaDoc workManager;
46
47    public void initialize() throws SchedulerConfigException
48    {
49       workManager = QuartzResourceAdapter.getConfigTimeWorkManager();
50    }
51
52    /**
53     * Currently this method is only used in metadata lookup.
54     * Which is has no further use.
55     * How to provide better estimate?
56     */

57    public int getPoolSize()
58    {
59       return poolSize;
60    }
61
62    public boolean runInThread(Runnable JavaDoc runnable)
63    {
64       try
65       {
66          WorkWrapper workWrapper = new WorkWrapper(runnable);
67          workManager.doWork(workWrapper);
68          return true;
69       }
70       catch (WorkException JavaDoc e)
71       {
72          return false;
73       }
74    }
75
76    /**
77     * No shutdown impl - workManager is shutdown by itself.
78     */

79    public void shutdown(boolean waitForJobsToComplete)
80    {
81    }
82
83    /**
84     * Just in case we want to set pool size.
85     */

86    public void setPoolSize(int poolSize)
87    {
88       this.poolSize = poolSize;
89    }
90
91    private class WorkWrapper implements Work JavaDoc
92    {
93
94       private Runnable JavaDoc delegate;
95
96       public WorkWrapper(Runnable JavaDoc delegate)
97       {
98          this.delegate = delegate;
99       }
100
101       public void run()
102       {
103          delegate.run();
104       }
105
106       public void release()
107       {
108       }
109
110    }
111
112 }
113
Popular Tags