001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.hadoop.lib.server; 020 021 import org.apache.hadoop.classification.InterfaceAudience; 022 import org.apache.hadoop.lib.lang.XException; 023 024 /** 025 * Exception thrown by the {@link Server} class. 026 */ 027 @InterfaceAudience.Private 028 public class ServerException extends XException { 029 030 /** 031 * Error codes use by the {@link Server} class. 032 */ 033 @InterfaceAudience.Private 034 public static enum ERROR implements XException.ERROR { 035 S01("Dir [{0}] does not exist"), 036 S02("[{0}] is not a directory"), 037 S03("Could not load file from classpath [{0}], {1}"), 038 S04("Service [{0}] does not implement declared interface [{1}]"), 039 S05("[{0}] is not a file"), 040 S06("Could not load file [{0}], {1}"), 041 S07("Could not instanciate service class [{0}], {1}"), 042 S08("Could not load service classes, {0}"), 043 S09("Could not set service [{0}] programmatically -server shutting down-, {1}"), 044 S10("Service [{0}] requires service [{1}]"), 045 S11("Service [{0}] exception during status change to [{1}] -server shutting down-, {2}"), 046 S12("Could not start service [{0}], {1}"), 047 S13("Missing system property [{0}]"), 048 S14("Could not initialize server, {0}") 049 ; 050 051 private String msg; 052 053 /** 054 * Constructor for the error code enum. 055 * 056 * @param msg message template. 057 */ 058 private ERROR(String msg) { 059 this.msg = msg; 060 } 061 062 /** 063 * Returns the message template for the error code. 064 * 065 * @return the message template for the error code. 066 */ 067 @Override 068 public String getTemplate() { 069 return msg; 070 } 071 } 072 073 /** 074 * Constructor for sub-classes. 075 * 076 * @param error error code for the XException. 077 * @param params parameters to use when creating the error message 078 * with the error code template. 079 */ 080 protected ServerException(XException.ERROR error, Object... params) { 081 super(error, params); 082 } 083 084 /** 085 * Creates an server exception using the specified error code. 086 * The exception message is resolved using the error code template 087 * and the passed parameters. 088 * 089 * @param error error code for the XException. 090 * @param params parameters to use when creating the error message 091 * with the error code template. 092 */ 093 public ServerException(ERROR error, Object... params) { 094 super(error, params); 095 } 096 097 }