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