/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * Initial developer(s): ____________________________________.
 * Contributor(s): ______________________________________.
 * JOnAS 2.4 Murad Meghani (Murad.Meghani@compuware.com) killServer and stopServer
 * JOnAS 2.5 2002.06 Florent Benoit & Ludovic Bert :
 *                   Methods for wars and ear files
 * Dean Jennings = add deployFile
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.adm;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.Vector;
import java.util.List;

import org.objectweb.jonas.ear.EarServiceException;
import org.objectweb.jonas.resource.ResourceServiceException;
import org.objectweb.jonas.web.JWebContainerServiceException;

/*
 * JOnAS Administration Remote Interface.
 * This is used basically by jonas admin.
 * @author Philippe Coq
 * Contributor(s):
 * Murad Meghani (Murad.Meghani@compuware.com) killServer and stopServer
 * Florent Benoit & Ludovic Bert : Methods for wars and ear files
 */
public interface AdmInterface extends Remote {

    public static final int TYPE_EJB = 1;
    public static final int TYPE_WAR = 2;
    public static final int TYPE_EAR = 3;
    public static final int TYPE_RAR = 4;
    public static final int TYPE_CAR = 5;

    public static final int STATUS_RUNNING = 1;
    public static final int STATUS_STOPPED = 2;
    public static final int STATUS_ALL = 0;

    /**
     * Deploy a given ear file with the help of the ear service.
     * @param fileName the name of the ear file.
     * @throws RemoteException if rmi call failed.
     * @throws EarServiceException if the deployment failed.
     */
    public void addEar(String fileName) throws RemoteException, EarServiceException;

    /**
     * Deploy a given rar file with the help of the resource service.
     * @param fileName the name of the rar file.
     * @throws RemoteException if rmi call failed.
     * @throws ResourceServiceException if the deployment failed.
     */
    public void addRar(String fileName) throws RemoteException, ResourceServiceException;

    /**
     * Deploy a given war file with the help of the web container service.
     * @param fileName the name of the war file.
     * @throws RemoteException if rmi call failed.
     * @throws JWebContainerServiceException if the deployment failed.
     */
    public void addWar(String fileName) throws RemoteException, JWebContainerServiceException;

    /**
     * UnDeploy a given ear file with the help of the ear service.
     * @param fileName the name of the ear file.
     * @throws RemoteException if rmi call failed.
     * @throws EarServiceException if the undeployment failed.
     */
    public void removeEar(String fileName) throws RemoteException, EarServiceException;

    /**
     * UnDeploy a given rar file with the help of the resource service.
     * @param fileName the name of the rar file.
     * @throws RemoteException if rmi call failed.
     * @throws ResourceServiceException if the undeployment failed.
     */
    public void removeRar(String fileName) throws RemoteException, ResourceServiceException;

    /**
     * UnDeploy a given war file with the help of the web container service.
     * @param fileName the name of the war file.
     * @throws RemoteException if rmi call failed.
     * @throws JWebContainerServiceException if the undeployment failed.
     */
    public void removeWar(String fileName) throws RemoteException, JWebContainerServiceException;

    /**
     * Test if the specified filename is already deployed or not
     * @param fileName the name of the ear file.
     * @return true if the ear is deployed, else false.
     * @throws RemoteException if rmi call failed.
     */
    boolean isEarLoaded(String fileName) throws RemoteException, EarServiceException;

    /**
     * Test if the specified filename is already deployed or not
     * @param fileName the name of the rar file.
     * @return true if the rar is deployed, else false.
     * @throws RemoteException if rmi call failed.
     */
    boolean isRarLoaded(String fileName) throws RemoteException, ResourceServiceException;


    /**
     * Test if the specified filename is already deployed or not
     * @param fileName the name of the war file.
     * @return true if the war is deployed, else false.
     * @throws RemoteException if rmi call failed.
     */
    boolean isWarLoaded(String fileName) throws RemoteException, JWebContainerServiceException;


    void addBeans(String fileName) throws RemoteException;
    void removeBeans(String fileName) throws RemoteException;
    boolean isLoaded(String fileName) throws RemoteException;
    String [] listBeans() throws RemoteException;
    String dumpCustom() throws RemoteException;
    Vector listContext() throws RemoteException;
    Properties listEnv() throws RemoteException;
    void stopServer() throws RemoteException;
    void killServer() throws RemoteException;
    boolean isEJBContainer() throws RemoteException;
    int getServerState() throws RemoteException;
    void setTransactionTimeout(int timeout) throws RemoteException;
    void runGC() throws RemoteException;
    void syncAllEntities(boolean passivate) throws RemoteException;
    String [] getTopics() throws RemoteException;
    String getTopicLevel(String topic) throws RemoteException;
    void setTopicLevel(String topic, String l) throws RemoteException;
    void deployFileOn(String filename, String [] target) throws RemoteException;
    void stopRemoteServers(String [] target) throws RemoteException;
    void startRemoteServers(String [] target) throws RemoteException;

    /**
     * Deploy file (GenIC), needed for Ishmael to work.
     * @param type type of the file (EJB, WAR, EAR, RAR, CAR)
     * @param file the actual file
     * @param filename basename of the file to be deployed
     * @throws RemoteException
     * @throws EarServiceException
     * @throws ResourceServiceException
     * @throws JWebContainerServiceException
     * @author Dean Jennings. <deanjennings@junta.com.au>
     */
    String deployFile(int type, byte[] file, String filename)
               throws RemoteException , EarServiceException, ResourceServiceException, JWebContainerServiceException;


    /**
     * List modules, needed for Ishmael to work. Currently only lists top
     * level modules. It does need to do sub elements of ears in the future.
     * @param type type of the file (EJB, WAR, EAR, RAR, CAR)
     * @param state status of the modules to be returned
     * (RUNNING, STOPPED, ALL)
     * @throws RemoteException
     * @author Dean Jennings. <deanjennings@junta.com.au>
     */
    List listModules(int type, int state) throws RemoteException;

    /**
     * Physically remove the module from the server
     * @param filename the filename of the module to be removed
     * @throws RemoteException
     * @author Dean Jennings. <deanjennings@junta.com.au>
     *
     */
    public void undeployFile(String filename) throws RemoteException;
}
