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    /**
022     * Service interface for components to be managed by the {@link Server} class.
023     */
024    public interface Service {
025    
026      /**
027       * Initializes the service. This method is called once, when the
028       * {@link Server} owning the service is being initialized.
029       *
030       * @param server the server initializing the service, give access to the
031       * server context.
032       *
033       * @throws ServiceException thrown if the service could not be initialized.
034       */
035      public void init(Server server) throws ServiceException;
036    
037      /**
038       * Post initializes the service. This method is called by the
039       * {@link Server} after all services of the server have been initialized.
040       *
041       * @throws ServiceException thrown if the service could not be
042       * post-initialized.
043       */
044      public void postInit() throws ServiceException;
045    
046      /**
047       * Destroy the services.  This method is called once, when the
048       * {@link Server} owning the service is being destroyed.
049       */
050      public void destroy();
051    
052      /**
053       * Returns the service dependencies of this service. The service will be
054       * instantiated only if all the service dependencies are already initialized.
055       *
056       * @return the service dependencies.
057       */
058      public Class[] getServiceDependencies();
059    
060      /**
061       * Returns the interface implemented by this service. This interface is used
062       * the {@link Server} when the {@link Server#get(Class)} method is used to
063       * retrieve a service.
064       *
065       * @return the interface that identifies the service.
066       */
067      public Class getInterface();
068    
069      /**
070       * Notification callback when the server changes its status.
071       *
072       * @param oldStatus old server status.
073       * @param newStatus new server status.
074       *
075       * @throws ServiceException thrown if the service could not process the status change.
076       */
077      public void serverStatusChange(Server.Status oldStatus, Server.Status newStatus) throws ServiceException;
078    
079    }