01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.util.watchdog;
19:
20: import org.apache.avalon.excalibur.pool.DefaultPool;
21: import org.apache.avalon.excalibur.pool.HardResourceLimitingPool;
22: import org.apache.avalon.excalibur.pool.ObjectFactory;
23: import org.apache.avalon.excalibur.pool.Pool;
24: import org.apache.avalon.excalibur.pool.Poolable;
25: import org.apache.excalibur.thread.ThreadPool;
26: import org.apache.avalon.framework.activity.Disposable;
27: import org.apache.avalon.framework.activity.Initializable;
28: import org.apache.avalon.framework.logger.AbstractLogEnabled;
29: import org.apache.avalon.framework.logger.LogEnabled;
30:
31: /**
32: * This class is a factory to produce Watchdogs, each of which is associated
33: * with a single thread.
34: *
35: */
36: public class ThreadPerWatchdogFactory extends AbstractLogEnabled
37: implements WatchdogFactory {
38:
39: /**
40: * The thread pool used to generate InaccurateTimeoutWatchdogs
41: */
42: private ThreadPool myThreadPool;
43:
44: /**
45: * The watchdog timeout for Watchdogs generated by this factory
46: */
47: private long timeout;
48:
49: /**
50: * Creates the factory and sets the thread pool used to generate
51: * InaccurateTimeoutWatchdogs.
52: */
53: public ThreadPerWatchdogFactory(ThreadPool theThreadPool,
54: long timeout) {
55: if (theThreadPool == null) {
56: throw new IllegalArgumentException(
57: "The thread pool for the ThreadPerWatchdogFactory cannot be null.");
58: }
59: myThreadPool = theThreadPool;
60: this .timeout = timeout;
61: }
62:
63: /**
64: * @see org.apache.james.util.watchdog.WatchdogFactory#getWatchdog(WatchdogTarget)
65: */
66: public Watchdog getWatchdog(WatchdogTarget theTarget)
67: throws Exception {
68: InaccurateTimeoutWatchdog watchdog = new InaccurateTimeoutWatchdog(
69: timeout, theTarget, myThreadPool);
70: watchdog.enableLogging(getLogger());
71: return watchdog;
72: }
73: }
|