PageRenderTime 42ms CodeModel.GetById 36ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/ss7/sgw/boot/src/main/java/org/mobicents/ss7/sgw/boot/MainDeployer.java

http://mobicents.googlecode.com/
Java | 143 lines | 52 code | 15 blank | 76 comment | 0 complexity | 008ed22b6e0a05665a54bf2829b04d8e MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.ss7.sgw.boot;
 24
 25import java.io.File;
 26import java.io.FileFilter;
 27import java.io.IOException;
 28import java.net.URL;
 29
 30import org.apache.log4j.Logger;
 31import org.jboss.kernel.Kernel;
 32import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
 33import org.jboss.kernel.spi.deployment.KernelDeployment;
 34import org.mobicents.ss7.sgw.Version;
 35
 36/**
 37 * Simplified deployement framework designed for hot deployement of endpoints
 38 * and media components.
 39 * 
 40 * Deployement is represented by tree of folders. Each folder may contains one
 41 * or more deployement descriptors. The most top deployment directory is
 42 * referenced as root. Maindeployer creates recursively HDScanner for root and
 43 * each nested directoty. The HDScanner corresponding to the root directory is
 44 * triggered periodicaly by local timer and in it order starts nested scanners
 45 * recursively.
 46 * 
 47 * @author kulikov
 48 * @author amit bhayani
 49 */
 50public class MainDeployer {
 51
 52    /** JBoss microconatiner kernel */
 53    private Kernel kernel;
 54    /** Basic deployer */
 55    private BasicXMLDeployer kernelDeployer;
 56    private KernelDeployment deployment;
 57
 58    /** Filter for selecting descriptors */
 59    private FileFilter fileFilter;
 60    /** Root deployment directory as string */
 61    private String path;
 62    /** Root deployment directory as file object */
 63    private File root;
 64    /** Logger instance */
 65    private Logger logger = Logger.getLogger(MainDeployer.class);
 66
 67    /**
 68     * Creates new instance of deployer.
 69     */
 70    public MainDeployer() {
 71    }
 72
 73    /**
 74     * Gets the path to the to the root deployment directory.
 75     * 
 76     * @return path to deployment directory.
 77     */
 78    public String getPath() {
 79        return path;
 80    }
 81
 82    /**
 83     * Modify the path to the root deployment directory
 84     * 
 85     * @param path
 86     */
 87    public void setPath(String path) {
 88        this.path = path;
 89        root = new File(path);
 90    }
 91
 92    /**
 93     * Gets the filter used by Deployer to select files for deployement.
 94     * 
 95     * @return the file filter object.
 96     */
 97    public FileFilter getFileFilter() {
 98        return fileFilter;
 99    }
100
101    /**
102     * Assigns file filter used for selection files for deploy.
103     * 
104     * @param fileFilter
105     *            the file filter object.
106     */
107    public void setFileFilter(FileFilter fileFilter) {
108        this.fileFilter = fileFilter;
109    }
110
111    /**
112     * Starts main deployer.
113     * 
114     * @param kernel
115     *            the jboss microntainer kernel instance.
116     * @param kernelDeployer
117     *            the jboss basic deployer.
118     */
119    public void start(Kernel kernel, BasicXMLDeployer kernelDeployer) throws Throwable {
120        Version version = Version.instance;
121        this.kernel = kernel;
122        this.kernelDeployer = kernelDeployer;
123
124        try {
125            Configuration d = new Configuration("root", root);
126            URL url = d.getConfig();
127            deployment = kernelDeployer.deploy(url);
128            kernelDeployer.validate();
129        } catch (IOException e) {
130            e.printStackTrace();
131        }
132        logger.info("[[[[[[[[[ " + version.toString() + " Started " + "]]]]]]]]]");
133    }
134
135    /**
136     * Shuts down deployer.
137     */
138    public void stop() {
139        kernelDeployer.undeploy(deployment);
140        logger.info("Stopped");
141    }
142
143}