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 019package org.apache.hadoop.lib.server; 020 021import org.apache.hadoop.classification.InterfaceAudience; 022import org.apache.hadoop.conf.ConfigRedactor; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.lib.util.Check; 025import org.apache.hadoop.lib.util.ConfigurationUtils; 026import org.apache.hadoop.util.StringUtils; 027import org.apache.log4j.LogManager; 028import org.apache.log4j.PropertyConfigurator; 029import org.slf4j.Logger; 030import org.slf4j.LoggerFactory; 031 032import java.io.File; 033import java.io.FileInputStream; 034import java.io.IOException; 035import java.io.InputStream; 036import java.text.MessageFormat; 037import java.util.ArrayList; 038import java.util.Collections; 039import java.util.LinkedHashMap; 040import java.util.List; 041import java.util.Map; 042import java.util.Properties; 043 044/** 045 * A Server class provides standard configuration, logging and {@link Service} 046 * lifecyle management. 047 * <p> 048 * A Server normally has a home directory, a configuration directory, a temp 049 * directory and logs directory. 050 * <p> 051 * The Server configuration is loaded from 2 overlapped files, 052 * <code>#SERVER#-default.xml</code> and <code>#SERVER#-site.xml</code>. The 053 * default file is loaded from the classpath, the site file is laoded from the 054 * configuration directory. 055 * <p> 056 * The Server collects all configuration properties prefixed with 057 * <code>#SERVER#</code>. The property names are then trimmed from the 058 * <code>#SERVER#</code> prefix. 059 * <p> 060 * The Server log configuration is loaded from the 061 * <code>#SERVICE#-log4j.properties</code> file in the configuration directory. 062 * <p> 063 * The lifecycle of server is defined in by {@link Server.Status} enum. 064 * When a server is create, its status is UNDEF, when being initialized it is 065 * BOOTING, once initialization is complete by default transitions to NORMAL. 066 * The <code>#SERVER#.startup.status</code> configuration property can be used 067 * to specify a different startup status (NORMAL, ADMIN or HALTED). 068 * <p> 069 * Services classes are defined in the <code>#SERVER#.services</code> and 070 * <code>#SERVER#.services.ext</code> properties. They are loaded in order 071 * (services first, then services.ext). 072 * <p> 073 * Before initializing the services, they are traversed and duplicate service 074 * interface are removed from the service list. The last service using a given 075 * interface wins (this enables a simple override mechanism). 076 * <p> 077 * After the services have been resoloved by interface de-duplication they are 078 * initialized in order. Once all services are initialized they are 079 * post-initialized (this enables late/conditional service bindings). 080 */ 081@InterfaceAudience.Private 082public class Server { 083 private Logger log; 084 085 /** 086 * Server property name that defines the service classes. 087 */ 088 public static final String CONF_SERVICES = "services"; 089 090 /** 091 * Server property name that defines the service extension classes. 092 */ 093 public static final String CONF_SERVICES_EXT = "services.ext"; 094 095 /** 096 * Server property name that defines server startup status. 097 */ 098 public static final String CONF_STARTUP_STATUS = "startup.status"; 099 100 /** 101 * Enumeration that defines the server status. 102 */ 103 @InterfaceAudience.Private 104 public static enum Status { 105 UNDEF(false, false), 106 BOOTING(false, true), 107 HALTED(true, true), 108 ADMIN(true, true), 109 NORMAL(true, true), 110 SHUTTING_DOWN(false, true), 111 SHUTDOWN(false, false); 112 113 private boolean settable; 114 private boolean operational; 115 116 /** 117 * Status constructor. 118 * 119 * @param settable indicates if the status is settable. 120 * @param operational indicates if the server is operational 121 * when in this status. 122 */ 123 private Status(boolean settable, boolean operational) { 124 this.settable = settable; 125 this.operational = operational; 126 } 127 128 /** 129 * Returns if this server status is operational. 130 * 131 * @return if this server status is operational. 132 */ 133 public boolean isOperational() { 134 return operational; 135 } 136 } 137 138 /** 139 * Name of the log4j configuration file the Server will load from the 140 * classpath if the <code>#SERVER#-log4j.properties</code> is not defined 141 * in the server configuration directory. 142 */ 143 public static final String DEFAULT_LOG4J_PROPERTIES = "default-log4j.properties"; 144 145 private Status status; 146 private String name; 147 private String homeDir; 148 private String configDir; 149 private String logDir; 150 private String tempDir; 151 private Configuration config; 152 private Map<Class, Service> services = new LinkedHashMap<Class, Service>(); 153 154 /** 155 * Creates a server instance. 156 * <p> 157 * The config, log and temp directories are all under the specified home directory. 158 * 159 * @param name server name. 160 * @param homeDir server home directory. 161 */ 162 public Server(String name, String homeDir) { 163 this(name, homeDir, null); 164 } 165 166 /** 167 * Creates a server instance. 168 * 169 * @param name server name. 170 * @param homeDir server home directory. 171 * @param configDir config directory. 172 * @param logDir log directory. 173 * @param tempDir temp directory. 174 */ 175 public Server(String name, String homeDir, String configDir, String logDir, String tempDir) { 176 this(name, homeDir, configDir, logDir, tempDir, null); 177 } 178 179 /** 180 * Creates a server instance. 181 * <p> 182 * The config, log and temp directories are all under the specified home directory. 183 * <p> 184 * It uses the provided configuration instead loading it from the config dir. 185 * 186 * @param name server name. 187 * @param homeDir server home directory. 188 * @param config server configuration. 189 */ 190 public Server(String name, String homeDir, Configuration config) { 191 this(name, homeDir, homeDir + "/conf", homeDir + "/log", homeDir + "/temp", config); 192 } 193 194 /** 195 * Creates a server instance. 196 * <p> 197 * It uses the provided configuration instead loading it from the config dir. 198 * 199 * @param name server name. 200 * @param homeDir server home directory. 201 * @param configDir config directory. 202 * @param logDir log directory. 203 * @param tempDir temp directory. 204 * @param config server configuration. 205 */ 206 public Server(String name, String homeDir, String configDir, String logDir, String tempDir, Configuration config) { 207 this.name = StringUtils.toLowerCase(Check.notEmpty(name, "name").trim()); 208 this.homeDir = Check.notEmpty(homeDir, "homeDir"); 209 this.configDir = Check.notEmpty(configDir, "configDir"); 210 this.logDir = Check.notEmpty(logDir, "logDir"); 211 this.tempDir = Check.notEmpty(tempDir, "tempDir"); 212 checkAbsolutePath(homeDir, "homeDir"); 213 checkAbsolutePath(configDir, "configDir"); 214 checkAbsolutePath(logDir, "logDir"); 215 checkAbsolutePath(tempDir, "tempDir"); 216 if (config != null) { 217 this.config = new Configuration(false); 218 ConfigurationUtils.copy(config, this.config); 219 } 220 status = Status.UNDEF; 221 } 222 223 /** 224 * Validates that the specified value is an absolute path (starts with '/'). 225 * 226 * @param value value to verify it is an absolute path. 227 * @param name name to use in the exception if the value is not an absolute 228 * path. 229 * 230 * @return the value. 231 * 232 * @throws IllegalArgumentException thrown if the value is not an absolute 233 * path. 234 */ 235 private String checkAbsolutePath(String value, String name) { 236 if (!new File(value).isAbsolute()) { 237 throw new IllegalArgumentException( 238 MessageFormat.format("[{0}] must be an absolute path [{1}]", name, value)); 239 } 240 return value; 241 } 242 243 /** 244 * Returns the current server status. 245 * 246 * @return the current server status. 247 */ 248 public Status getStatus() { 249 return status; 250 } 251 252 /** 253 * Sets a new server status. 254 * <p> 255 * The status must be settable. 256 * <p> 257 * All services will be notified o the status change via the 258 * {@link Service#serverStatusChange(Server.Status, Server.Status)} method. If a service 259 * throws an exception during the notification, the server will be destroyed. 260 * 261 * @param status status to set. 262 * 263 * @throws ServerException thrown if the service has been destroy because of 264 * a failed notification to a service. 265 */ 266 public void setStatus(Status status) throws ServerException { 267 Check.notNull(status, "status"); 268 if (status.settable) { 269 if (status != this.status) { 270 Status oldStatus = this.status; 271 this.status = status; 272 for (Service service : services.values()) { 273 try { 274 service.serverStatusChange(oldStatus, status); 275 } catch (Exception ex) { 276 log.error("Service [{}] exception during status change to [{}] -server shutting down-, {}", 277 new Object[]{service.getInterface().getSimpleName(), status, ex.getMessage(), ex}); 278 destroy(); 279 throw new ServerException(ServerException.ERROR.S11, service.getInterface().getSimpleName(), 280 status, ex.getMessage(), ex); 281 } 282 } 283 } 284 } else { 285 throw new IllegalArgumentException("Status [" + status + " is not settable"); 286 } 287 } 288 289 /** 290 * Verifies the server is operational. 291 * 292 * @throws IllegalStateException thrown if the server is not operational. 293 */ 294 protected void ensureOperational() { 295 if (!getStatus().isOperational()) { 296 throw new IllegalStateException("Server is not running"); 297 } 298 } 299 300 /** 301 * Convenience method that returns a resource as inputstream from the 302 * classpath. 303 * <p> 304 * It first attempts to use the Thread's context classloader and if not 305 * set it uses the <code>ClassUtils</code> classloader. 306 * 307 * @param name resource to retrieve. 308 * 309 * @return inputstream with the resource, NULL if the resource does not 310 * exist. 311 */ 312 static InputStream getResource(String name) { 313 Check.notEmpty(name, "name"); 314 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 315 if (cl == null) { 316 cl = Server.class.getClassLoader(); 317 } 318 return cl.getResourceAsStream(name); 319 } 320 321 /** 322 * Initializes the Server. 323 * <p> 324 * The initialization steps are: 325 * <ul> 326 * <li>It verifies the service home and temp directories exist</li> 327 * <li>Loads the Server <code>#SERVER#-default.xml</code> 328 * configuration file from the classpath</li> 329 * <li>Initializes log4j logging. If the 330 * <code>#SERVER#-log4j.properties</code> file does not exist in the config 331 * directory it load <code>default-log4j.properties</code> from the classpath 332 * </li> 333 * <li>Loads the <code>#SERVER#-site.xml</code> file from the server config 334 * directory and merges it with the default configuration.</li> 335 * <li>Loads the services</li> 336 * <li>Initializes the services</li> 337 * <li>Post-initializes the services</li> 338 * <li>Sets the server startup status</li> 339 * </ul> 340 * 341 * @throws ServerException thrown if the server could not be initialized. 342 */ 343 public void init() throws ServerException { 344 if (status != Status.UNDEF) { 345 throw new IllegalStateException("Server already initialized"); 346 } 347 status = Status.BOOTING; 348 verifyDir(homeDir); 349 verifyDir(tempDir); 350 Properties serverInfo = new Properties(); 351 try { 352 InputStream is = getResource(name + ".properties"); 353 serverInfo.load(is); 354 is.close(); 355 } catch (IOException ex) { 356 throw new RuntimeException("Could not load server information file: " + name + ".properties"); 357 } 358 initLog(); 359 log.info("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); 360 log.info("Server [{}] starting", name); 361 log.info(" Built information:"); 362 log.info(" Version : {}", serverInfo.getProperty(name + ".version", "undef")); 363 log.info(" Source Repository : {}", serverInfo.getProperty(name + ".source.repository", "undef")); 364 log.info(" Source Revision : {}", serverInfo.getProperty(name + ".source.revision", "undef")); 365 log.info(" Built by : {}", serverInfo.getProperty(name + ".build.username", "undef")); 366 log.info(" Built timestamp : {}", serverInfo.getProperty(name + ".build.timestamp", "undef")); 367 log.info(" Runtime information:"); 368 log.info(" Home dir: {}", homeDir); 369 log.info(" Config dir: {}", (config == null) ? configDir : "-"); 370 log.info(" Log dir: {}", logDir); 371 log.info(" Temp dir: {}", tempDir); 372 initConfig(); 373 log.debug("Loading services"); 374 List<Service> list = loadServices(); 375 try { 376 log.debug("Initializing services"); 377 initServices(list); 378 log.info("Services initialized"); 379 } catch (ServerException ex) { 380 log.error("Services initialization failure, destroying initialized services"); 381 destroyServices(); 382 throw ex; 383 } 384 Status status = Status.valueOf(getConfig().get(getPrefixedName(CONF_STARTUP_STATUS), Status.NORMAL.toString())); 385 setStatus(status); 386 log.info("Server [{}] started!, status [{}]", name, status); 387 } 388 389 /** 390 * Verifies the specified directory exists. 391 * 392 * @param dir directory to verify it exists. 393 * 394 * @throws ServerException thrown if the directory does not exist or it the 395 * path it is not a directory. 396 */ 397 private void verifyDir(String dir) throws ServerException { 398 File file = new File(dir); 399 if (!file.exists()) { 400 throw new ServerException(ServerException.ERROR.S01, dir); 401 } 402 if (!file.isDirectory()) { 403 throw new ServerException(ServerException.ERROR.S02, dir); 404 } 405 } 406 407 /** 408 * Initializes Log4j logging. 409 * 410 * @throws ServerException thrown if Log4j could not be initialized. 411 */ 412 protected void initLog() throws ServerException { 413 verifyDir(logDir); 414 LogManager.resetConfiguration(); 415 File log4jFile = new File(configDir, name + "-log4j.properties"); 416 if (log4jFile.exists()) { 417 PropertyConfigurator.configureAndWatch(log4jFile.toString(), 10 * 1000); //every 10 secs 418 log = LoggerFactory.getLogger(Server.class); 419 } else { 420 Properties props = new Properties(); 421 try { 422 InputStream is = getResource(DEFAULT_LOG4J_PROPERTIES); 423 try { 424 props.load(is); 425 } finally { 426 is.close(); 427 } 428 } catch (IOException ex) { 429 throw new ServerException(ServerException.ERROR.S03, DEFAULT_LOG4J_PROPERTIES, ex.getMessage(), ex); 430 } 431 PropertyConfigurator.configure(props); 432 log = LoggerFactory.getLogger(Server.class); 433 log.warn("Log4j [{}] configuration file not found, using default configuration from classpath", log4jFile); 434 } 435 } 436 437 /** 438 * Loads and inializes the server configuration. 439 * 440 * @throws ServerException thrown if the configuration could not be loaded/initialized. 441 */ 442 protected void initConfig() throws ServerException { 443 verifyDir(configDir); 444 File file = new File(configDir); 445 Configuration defaultConf; 446 String defaultConfig = name + "-default.xml"; 447 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 448 InputStream inputStream = classLoader.getResourceAsStream(defaultConfig); 449 if (inputStream == null) { 450 log.warn("Default configuration file not available in classpath [{}]", defaultConfig); 451 defaultConf = new Configuration(false); 452 } else { 453 try { 454 defaultConf = new Configuration(false); 455 ConfigurationUtils.load(defaultConf, inputStream); 456 } catch (Exception ex) { 457 throw new ServerException(ServerException.ERROR.S03, defaultConfig, ex.getMessage(), ex); 458 } 459 } 460 461 if (config == null) { 462 Configuration siteConf; 463 File siteFile = new File(file, name + "-site.xml"); 464 if (!siteFile.exists()) { 465 log.warn("Site configuration file [{}] not found in config directory", siteFile); 466 siteConf = new Configuration(false); 467 } else { 468 if (!siteFile.isFile()) { 469 throw new ServerException(ServerException.ERROR.S05, siteFile.getAbsolutePath()); 470 } 471 try { 472 log.debug("Loading site configuration from [{}]", siteFile); 473 inputStream = new FileInputStream(siteFile); 474 siteConf = new Configuration(false); 475 ConfigurationUtils.load(siteConf, inputStream); 476 } catch (IOException ex) { 477 throw new ServerException(ServerException.ERROR.S06, siteFile, ex.getMessage(), ex); 478 } 479 } 480 481 config = new Configuration(false); 482 ConfigurationUtils.copy(siteConf, config); 483 } 484 485 ConfigurationUtils.injectDefaults(defaultConf, config); 486 ConfigRedactor redactor = new ConfigRedactor(config); 487 for (String name : System.getProperties().stringPropertyNames()) { 488 String value = System.getProperty(name); 489 if (name.startsWith(getPrefix() + ".")) { 490 config.set(name, value); 491 String redacted = redactor.redact(name, value); 492 log.info("System property sets {}: {}", name, redacted); 493 } 494 } 495 496 log.debug("Loaded Configuration:"); 497 log.debug("------------------------------------------------------"); 498 for (Map.Entry<String, String> entry : config) { 499 String name = entry.getKey(); 500 String value = config.get(entry.getKey()); 501 String redacted = redactor.redact(name, value); 502 log.debug(" {}: {}", entry.getKey(), redacted); 503 } 504 log.debug("------------------------------------------------------"); 505 } 506 507 /** 508 * Loads the specified services. 509 * 510 * @param classes services classes to load. 511 * @param list list of loaded service in order of appearance in the 512 * configuration. 513 * 514 * @throws ServerException thrown if a service class could not be loaded. 515 */ 516 private void loadServices(Class[] classes, List<Service> list) throws ServerException { 517 for (Class klass : classes) { 518 try { 519 Service service = (Service) klass.newInstance(); 520 log.debug("Loading service [{}] implementation [{}]", service.getInterface(), 521 service.getClass()); 522 if (!service.getInterface().isInstance(service)) { 523 throw new ServerException(ServerException.ERROR.S04, klass, service.getInterface().getName()); 524 } 525 list.add(service); 526 } catch (ServerException ex) { 527 throw ex; 528 } catch (Exception ex) { 529 throw new ServerException(ServerException.ERROR.S07, klass, ex.getMessage(), ex); 530 } 531 } 532 } 533 534 /** 535 * Loads services defined in <code>services</code> and 536 * <code>services.ext</code> and de-dups them. 537 * 538 * @return List of final services to initialize. 539 * 540 * @throws ServerException throw if the services could not be loaded. 541 */ 542 protected List<Service> loadServices() throws ServerException { 543 try { 544 Map<Class, Service> map = new LinkedHashMap<Class, Service>(); 545 Class[] classes = getConfig().getClasses(getPrefixedName(CONF_SERVICES)); 546 Class[] classesExt = getConfig().getClasses(getPrefixedName(CONF_SERVICES_EXT)); 547 List<Service> list = new ArrayList<Service>(); 548 loadServices(classes, list); 549 loadServices(classesExt, list); 550 551 //removing duplicate services, strategy: last one wins 552 for (Service service : list) { 553 if (map.containsKey(service.getInterface())) { 554 log.debug("Replacing service [{}] implementation [{}]", service.getInterface(), 555 service.getClass()); 556 } 557 map.put(service.getInterface(), service); 558 } 559 list = new ArrayList<Service>(); 560 for (Map.Entry<Class, Service> entry : map.entrySet()) { 561 list.add(entry.getValue()); 562 } 563 return list; 564 } catch (RuntimeException ex) { 565 throw new ServerException(ServerException.ERROR.S08, ex.getMessage(), ex); 566 } 567 } 568 569 /** 570 * Initializes the list of services. 571 * 572 * @param services services to initialized, it must be a de-dupped list of 573 * services. 574 * 575 * @throws ServerException thrown if the services could not be initialized. 576 */ 577 protected void initServices(List<Service> services) throws ServerException { 578 for (Service service : services) { 579 log.debug("Initializing service [{}]", service.getInterface()); 580 checkServiceDependencies(service); 581 service.init(this); 582 this.services.put(service.getInterface(), service); 583 } 584 for (Service service : services) { 585 service.postInit(); 586 } 587 } 588 589 /** 590 * Checks if all service dependencies of a service are available. 591 * 592 * @param service service to check if all its dependencies are available. 593 * 594 * @throws ServerException thrown if a service dependency is missing. 595 */ 596 protected void checkServiceDependencies(Service service) throws ServerException { 597 if (service.getServiceDependencies() != null) { 598 for (Class dependency : service.getServiceDependencies()) { 599 if (services.get(dependency) == null) { 600 throw new ServerException(ServerException.ERROR.S10, service.getClass(), dependency); 601 } 602 } 603 } 604 } 605 606 /** 607 * Destroys the server services. 608 */ 609 protected void destroyServices() { 610 List<Service> list = new ArrayList<Service>(services.values()); 611 Collections.reverse(list); 612 for (Service service : list) { 613 try { 614 log.debug("Destroying service [{}]", service.getInterface()); 615 service.destroy(); 616 } catch (Throwable ex) { 617 log.error("Could not destroy service [{}], {}", 618 new Object[]{service.getInterface(), ex.getMessage(), ex}); 619 } 620 } 621 log.info("Services destroyed"); 622 } 623 624 /** 625 * Destroys the server. 626 * <p> 627 * All services are destroyed in reverse order of initialization, then the 628 * Log4j framework is shutdown. 629 */ 630 public void destroy() { 631 ensureOperational(); 632 destroyServices(); 633 log.info("Server [{}] shutdown!", name); 634 log.info("======================================================"); 635 if (!Boolean.getBoolean("test.circus")) { 636 LogManager.shutdown(); 637 } 638 status = Status.SHUTDOWN; 639 } 640 641 /** 642 * Returns the name of the server. 643 * 644 * @return the server name. 645 */ 646 public String getName() { 647 return name; 648 } 649 650 /** 651 * Returns the server prefix for server configuration properties. 652 * <p> 653 * By default it is the server name. 654 * 655 * @return the prefix for server configuration properties. 656 */ 657 public String getPrefix() { 658 return getName(); 659 } 660 661 /** 662 * Returns the prefixed name of a server property. 663 * 664 * @param name of the property. 665 * 666 * @return prefixed name of the property. 667 */ 668 public String getPrefixedName(String name) { 669 return getPrefix() + "." + Check.notEmpty(name, "name"); 670 } 671 672 /** 673 * Returns the server home dir. 674 * 675 * @return the server home dir. 676 */ 677 public String getHomeDir() { 678 return homeDir; 679 } 680 681 /** 682 * Returns the server config dir. 683 * 684 * @return the server config dir. 685 */ 686 public String getConfigDir() { 687 return configDir; 688 } 689 690 /** 691 * Returns the server log dir. 692 * 693 * @return the server log dir. 694 */ 695 public String getLogDir() { 696 return logDir; 697 } 698 699 /** 700 * Returns the server temp dir. 701 * 702 * @return the server temp dir. 703 */ 704 public String getTempDir() { 705 return tempDir; 706 } 707 708 /** 709 * Returns the server configuration. 710 * 711 * @return the server configuration. 712 */ 713 public Configuration getConfig() { 714 return config; 715 716 } 717 718 /** 719 * Returns the {@link Service} associated to the specified interface. 720 * 721 * @param serviceKlass service interface. 722 * 723 * @return the service implementation. 724 */ 725 @SuppressWarnings("unchecked") 726 public <T> T get(Class<T> serviceKlass) { 727 ensureOperational(); 728 Check.notNull(serviceKlass, "serviceKlass"); 729 return (T) services.get(serviceKlass); 730 } 731 732 /** 733 * Adds a service programmatically. 734 * <p> 735 * If a service with the same interface exists, it will be destroyed and 736 * removed before the given one is initialized and added. 737 * <p> 738 * If an exception is thrown the server is destroyed. 739 * 740 * @param klass service class to add. 741 * 742 * @throws ServerException throw if the service could not initialized/added 743 * to the server. 744 */ 745 public void setService(Class<? extends Service> klass) throws ServerException { 746 ensureOperational(); 747 Check.notNull(klass, "serviceKlass"); 748 if (getStatus() == Status.SHUTTING_DOWN) { 749 throw new IllegalStateException("Server shutting down"); 750 } 751 try { 752 Service newService = klass.newInstance(); 753 Service oldService = services.get(newService.getInterface()); 754 if (oldService != null) { 755 try { 756 oldService.destroy(); 757 } catch (Throwable ex) { 758 log.error("Could not destroy service [{}], {}", 759 new Object[]{oldService.getInterface(), ex.getMessage(), ex}); 760 } 761 } 762 newService.init(this); 763 services.put(newService.getInterface(), newService); 764 } catch (Exception ex) { 765 log.error("Could not set service [{}] programmatically -server shutting down-, {}", klass, ex); 766 destroy(); 767 throw new ServerException(ServerException.ERROR.S09, klass, ex.getMessage(), ex); 768 } 769 } 770 771}