View Javadoc

1   package org.apache.turbine.services;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  /***
20   * This is a singleton utility class that acts as a Services broker.
21   *
22   * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
23   * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
24   * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
25   * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
26   * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
27   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
28   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
29   * @version $Id: TurbineServices.java 264148 2005-08-29 14:21:04Z henning $
30   */
31  public class TurbineServices
32          extends BaseServiceBroker
33          implements ServiceManager
34  {
35      /*** The single instance of this class. */
36      private static ServiceManager instance = new TurbineServices();
37  
38      /***
39       * This constructor is protected to force clients to use
40       * getInstance() to access this class.
41       */
42      protected TurbineServices()
43      {
44          super();
45      }
46  
47      /***
48       * The method through which this class is accessed as a broker.
49       *
50       * @return The single instance of this class.
51       */
52      public static ServiceManager getInstance()
53      {
54          return instance;
55      }
56  
57      /***
58       * The method through which to change the default manager.
59       * Note that services of the previous manager will be shutdown.
60       * @param manager a new service manager.
61       */
62      public static synchronized void setManager(ServiceManager manager)
63      {
64          ServiceManager previous = instance;
65          instance = manager;
66          if (previous != null)
67          {
68              previous.shutdownServices();
69          }
70      }
71  }