1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.services.daemonfactory;
1819import org.apache.jetspeed.daemon.Daemon;
20import org.apache.jetspeed.daemon.DaemonEntry;
21import org.apache.jetspeed.daemon.DaemonContext;
22import org.apache.jetspeed.daemon.DaemonException;
23import org.apache.jetspeed.daemon.DaemonNotFoundException;
24import org.apache.turbine.services.TurbineServices;
2526/***27@author <a href="mailto:burton@apache.org">Kevin A. Burton</a>28@version $Id: DaemonFactory.java,v 1.4 2004/02/23 03:29:24 jford Exp $29*/30publicclassDaemonFactory {
3132protectedstaticfinalDaemonFactoryService getService() {
33return (DaemonFactoryService)TurbineServices
34 .getInstance()
35 .getService(DaemonFactoryService.SERVICE_NAME);
36 }
3738/***39 <p>40 Starts any daemons that need processing.41 </p>4243 <p>44 This should be called right after init() so that any daemons that need to be 45 started will be. If you need to do any per-daemon initialization then do so 46 before calling start()47 </p>48 */49publicstaticvoid start() {
50 getService().start();
51 }
5253/***54 Allows a Daemon to define its Thread priority through a factory. The Thread55 that this object should return should be an implementation of itself.56 */57publicstaticDaemon getDaemon( DaemonEntry entry ) throws DaemonException {
58return getService().getDaemon( entry );
59 }
6061/***62 Get a daemon with the given classname.6364 @see #getDaemon( DaemonEntry entry )65 */66publicstaticDaemon getDaemon( String classname ) throws DaemonException {
67return getService().getDaemon( classname );
68 }
6970/***71 */72publicstaticDaemonContext getDaemonContext() {
73return getService().getDaemonContext();
74 }
7576/***77 Kicks of processing of a Daemon. Does the same thing as getDaemon() but78 also creates a thread and runs the daemon.79 */80publicstaticvoid process( DaemonEntry entry ) throws DaemonException {
81 getService().process( entry );
82 }
8384/***85 */86publicstaticint getStatus(DaemonEntry entry) {
87return getService().getStatus( entry );
88 }
8990/***91 Get the last known result of the given DaemonEntry's processing92 */93publicstaticint getResult(DaemonEntry entry) {
94return getService().getResult( entry );
95 }
9697/***98 Get the last known message of the given DaemonEntry's processing99 */100publicstatic String getMessage( DaemonEntry entry ) {
101return getService().getMessage( entry );
102 }
103104/***105 Get the current known DaemonEntries within the DaemonFactory106 */107publicstaticDaemonEntry[] getDaemonEntries() {
108return getService().getDaemonEntries();
109 }
110111/***112 Given the name of a DaemonEntry... get it from the DaemonFactory 113 */114publicstaticDaemonEntry getDaemonEntry(String name)
115 throws DaemonNotFoundException {
116return getService().getDaemonEntry( name );
117 }
118119 }