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 * This class contains the built-in common stop startegies. 023 * 024 * @author Dain Sundstrom 025 * @version $Id$ 026 * @since 2.0 027 */ 028 public final class StopStrategies { 029 private StopStrategies() { 030 } 031 032 /** 033 * This strategy attempts to immedately stop the service. When there are unsatisfied conditions, this strategy 034 * will leave the service in the STOPPING state, and throw an UnsatisfiedConditionsException 035 * to the caller. 036 */ 037 public static final StopStrategy SYNCHRONOUS = new Synchronous(); 038 039 private static class Synchronous implements StopStrategy { 040 public boolean waitForUnsatisfiedConditions(ServiceName serviceName, Set conditions) throws UnsatisfiedConditionsException { 041 throw new UnsatisfiedConditionsException("Unsatisfied stop conditions", serviceName, conditions); 042 } 043 044 } 045 046 /** 047 * This strategy attempts to stop the service asynchronously. When there are unsatisfied conditions, this strategy 048 * will leave the service in the STOPPING state, and caller will not recieve any exceptions. 049 */ 050 public static final StopStrategy ASYNCHRONOUS = new Asynchronous(); 051 052 private static class Asynchronous implements StopStrategy { 053 public boolean waitForUnsatisfiedConditions(ServiceName serviceName, Set conditions) { 054 return false; 055 } 056 057 } 058 059 /** 060 * This strategy wait until the service stops. This strategy blocks until all unsatisfied conditons 061 * are satisfied. 062 */ 063 public static final StopStrategy BLOCK = new Block(); 064 065 private static class Block implements StopStrategy { 066 public boolean waitForUnsatisfiedConditions(ServiceName serviceName, Set conditions) { 067 return true; 068 } 069 070 } 071 072 /** 073 * This strategy forceable stops the service. This strategy ignores all unsatisfied conditons. 074 */ 075 public static final StopStrategy FORCE = new Force(); 076 077 private static class Force implements StopStrategy { 078 public boolean waitForUnsatisfiedConditions(ServiceName serviceName, Set conditions) throws ForcedStopException { 079 throw new ForcedStopException(serviceName, conditions); 080 } 081 082 } 083 }