001package org.apache.turbine.services;
002
003
004/*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements.  See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership.  The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License.  You may obtain a copy of the License at
012 *
013 *   http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied.  See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024/**
025 * This is a singleton utility class that acts as a Services broker.
026 *
027 * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
028 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
029 * @author <a href="mailto:burton@apache.org">Kevin Burton</a>
030 * @author <a href="mailto:krzewski@e-point.pl">Rafal Krzewski</a>
031 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
032 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
033 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
034 * @version $Id$
035 */
036public class TurbineServices
037        extends BaseServiceBroker
038        implements ServiceManager
039{
040    /** The single instance of this class. */
041    private static ServiceManager instance = new TurbineServices();
042
043    /**
044     * This constructor is protected to force clients to use
045     * getInstance() to access this class.
046     */
047    protected TurbineServices()
048    {
049        super();
050    }
051
052    /**
053     * The method through which this class is accessed as a broker.
054     *
055     * @return The single instance of this class.
056     */
057    public static ServiceManager getInstance()
058    {
059        return instance;
060    }
061
062    /**
063     * The method through which to change the default manager.
064     * Note that services of the previous manager will be shutdown.
065     * @param manager a new service manager.
066     */
067    public static synchronized void setManager(ServiceManager manager)
068    {
069        ServiceManager previous = instance;
070        instance = manager;
071        if (previous != null)
072        {
073            previous.shutdownServices();
074        }
075    }
076}