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    /**
020     * Signifies that a thread carrying out a kernel operation was interrupted.  The kernel will always leave the
021     * system in a stable state before returning to the caller.
022     *
023     * @author Dain Sundstrom
024     * @version $Id$
025     * @since 2.0
026     */
027    public class KernelOperationInterruptedException extends RuntimeException {
028        private final ServiceName serviceName;
029        private final String operationName;
030    
031        /**
032         * Created a KernelOperationInterruptedException for the specified operation on the specified service.
033         *
034         * @param cause the {@link InterruptedException} that casused the kernel operation to be interrupted
035         * @param serviceName the name of the service for which the operation was interrupted
036         * @param operationName the name of the operation that was interrupted
037         */
038        public KernelOperationInterruptedException(InterruptedException cause, ServiceName serviceName, String operationName) {
039            super(cause);
040            if (serviceName == null) throw new NullPointerException("serviceName is null");
041            if (operationName == null) throw new NullPointerException("operationName is null");
042            this.serviceName = serviceName;
043            this.operationName = operationName;
044        }
045    
046        /**
047         * Created a KernelOperationInterruptedException with a custom message.
048         *
049         * @param message a custom message for this exception
050         * @param cause the {@link InterruptedException} that casused the kernel operation to be interrupted
051         * @param serviceName the name of the service for which the operation was interrupted
052         * @param operationName the name of the operation that was interrupted
053         */
054        public KernelOperationInterruptedException(String message, InterruptedException cause, ServiceName serviceName, String operationName) {
055            super(message, cause);
056            if (serviceName == null) throw new NullPointerException("serviceName is null");
057            if (operationName == null) throw new NullPointerException("operationName is null");
058            this.serviceName = serviceName;
059            this.operationName = operationName;
060        }
061    
062        /**
063         * Gets the name of the service for which the operation was interrupted.
064         *
065         * @return the name of the service for which the operation was interrupted
066         */
067        public ServiceName getServiceName() {
068            return serviceName;
069        }
070    
071        /**
072         * Gets the name of the operation that was interrupted.
073         *
074         * @return the name of the operation that was interrupted
075         */
076        public String getOperationName() {
077            return operationName;
078        }
079    }