001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.xbean.kernel;
018
019 import java.util.Set;
020
021 /**
022 * The StartStrategy interface is used to assist the kernel in determining how to handle problems that occur while
023 * starting a service.
024 *
025 * @author Dain Sundstrom
026 * @version $Id$
027 * @since 2.0
028 */
029 public interface StartStrategy {
030 /**
031 * Determines if the kernel should wait for the unsatified conditions to be satisfied.
032 *
033 * @param serviceName the name of the service that has the unsatisfied condtions
034 * @param conditions the unsatisfied condtions
035 * @return true if the kernel should wait for the conditions to be satisfied; false if the strategy would like
036 * silently leave the service in the starting state
037 * @throws UnsatisfiedConditionsException the the strategy would like to leave the service in the starting state
038 * and throw an exception the caller
039 * @throws UnregisterServiceException if the strategy would like to ignore the unsatisfied conditions and continue to
040 * destry the service
041 */
042 boolean waitForUnsatisfiedConditions(ServiceName serviceName, Set conditions) throws UnsatisfiedConditionsException, UnregisterServiceException;
043
044 /**
045 * Handle the start error. The strategy can rethrow the exception, throw an {@link UnregisterServiceException}, or
046 * return. If this method rethrows the exception, the service will be destroyed and the exception will be thrown to
047 * the caller. If an UnregisterServiceException is thrown, the kernel will unregister the service and rethrow
048 * {@link UnregisterServiceException#getCause()}. If this method returns without throwing an exception, the kernel
049 * will pass the exception to the service monitor for processing and leave the service in the starting state.
050 *
051 * @param serviceName the name of the service that has the error
052 * @param startError the Exception or Error
053 * @throws UnregisterServiceException if the strategy would like the service to be destroyed and unregistered
054 * @throws Exception if the strategy would like to destroy the service and throw the exception to the caller
055 */
056 void startError(ServiceName serviceName, Throwable startError) throws UnregisterServiceException, Exception;
057 }