View Javadoc

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 at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * 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 and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.services.daemonfactory;
18  
19  import org.apache.jetspeed.daemon.Daemon;
20  import org.apache.jetspeed.daemon.DaemonEntry;
21  import org.apache.jetspeed.daemon.DaemonContext;
22  import org.apache.jetspeed.daemon.DaemonException;
23  import org.apache.jetspeed.daemon.DaemonNotFoundException;
24  import org.apache.turbine.services.TurbineServices;
25  
26  /***
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  */
30  public class DaemonFactory {
31      
32      protected static final DaemonFactoryService getService() {
33          return (DaemonFactoryService)TurbineServices
34              .getInstance()
35              .getService(DaemonFactoryService.SERVICE_NAME);
36      }
37      
38      /***
39      <p>
40      Starts any daemons that need processing.
41      </p>
42      
43      <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      */
49      public static void start() {
50          getService().start();
51      }
52      
53      /***
54      Allows a Daemon to define its Thread priority through a factory.  The Thread
55      that this object should return should be an implementation of itself.
56      */
57      public static Daemon getDaemon( DaemonEntry entry ) throws DaemonException {
58          return getService().getDaemon( entry );
59      }
60  
61      /***
62      Get a daemon with the given classname.
63      
64      @see    #getDaemon( DaemonEntry entry )
65      */
66      public static Daemon getDaemon( String classname ) throws DaemonException {
67          return getService().getDaemon( classname );
68      }
69  
70      /***
71      */
72      public static DaemonContext getDaemonContext() {
73          return getService().getDaemonContext();
74      }
75  
76      /***
77      Kicks of processing of a Daemon.  Does the same thing as getDaemon() but
78      also creates a thread and runs the daemon.
79      */
80      public static void process( DaemonEntry entry ) throws DaemonException {
81          getService().process( entry );
82      }
83  
84      /***
85      */
86      public static int getStatus(DaemonEntry entry) {
87          return getService().getStatus( entry );
88      }
89  
90      /***
91      Get the last known result of the given DaemonEntry's processing
92      */
93      public static int getResult(DaemonEntry entry) {
94          return getService().getResult( entry );
95      }
96  
97      /***
98      Get the last known message of the given DaemonEntry's processing
99      */
100     public static String getMessage( DaemonEntry entry ) {
101         return getService().getMessage( entry );
102     }
103     
104     /***
105     Get the current known DaemonEntries within the DaemonFactory
106     */
107     public static DaemonEntry[] getDaemonEntries() {
108         return getService().getDaemonEntries();
109     }
110 
111     /***
112     Given the name of a DaemonEntry... get it from the DaemonFactory 
113     */
114     public static DaemonEntry getDaemonEntry(String name) 
115         throws DaemonNotFoundException {
116         return getService().getDaemonEntry( name );
117     }
118     
119 }