/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. package org.mobicents.ss7.sgw.boot;
  23. import java.io.File;
  24. import java.io.FileFilter;
  25. import java.io.IOException;
  26. import java.net.URL;
  27. import org.apache.log4j.Logger;
  28. import org.jboss.kernel.Kernel;
  29. import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
  30. import org.jboss.kernel.spi.deployment.KernelDeployment;
  31. import org.mobicents.ss7.sgw.Version;
  32. /**
  33. * Simplified deployement framework designed for hot deployement of endpoints
  34. * and media components.
  35. *
  36. * Deployement is represented by tree of folders. Each folder may contains one
  37. * or more deployement descriptors. The most top deployment directory is
  38. * referenced as root. Maindeployer creates recursively HDScanner for root and
  39. * each nested directoty. The HDScanner corresponding to the root directory is
  40. * triggered periodicaly by local timer and in it order starts nested scanners
  41. * recursively.
  42. *
  43. * @author kulikov
  44. * @author amit bhayani
  45. */
  46. public class MainDeployer {
  47. /** JBoss microconatiner kernel */
  48. private Kernel kernel;
  49. /** Basic deployer */
  50. private BasicXMLDeployer kernelDeployer;
  51. private KernelDeployment deployment;
  52. /** Filter for selecting descriptors */
  53. private FileFilter fileFilter;
  54. /** Root deployment directory as string */
  55. private String path;
  56. /** Root deployment directory as file object */
  57. private File root;
  58. /** Logger instance */
  59. private Logger logger = Logger.getLogger(MainDeployer.class);
  60. /**
  61. * Creates new instance of deployer.
  62. */
  63. public MainDeployer() {
  64. }
  65. /**
  66. * Gets the path to the to the root deployment directory.
  67. *
  68. * @return path to deployment directory.
  69. */
  70. public String getPath() {
  71. return path;
  72. }
  73. /**
  74. * Modify the path to the root deployment directory
  75. *
  76. * @param path
  77. */
  78. public void setPath(String path) {
  79. this.path = path;
  80. root = new File(path);
  81. }
  82. /**
  83. * Gets the filter used by Deployer to select files for deployement.
  84. *
  85. * @return the file filter object.
  86. */
  87. public FileFilter getFileFilter() {
  88. return fileFilter;
  89. }
  90. /**
  91. * Assigns file filter used for selection files for deploy.
  92. *
  93. * @param fileFilter
  94. * the file filter object.
  95. */
  96. public void setFileFilter(FileFilter fileFilter) {
  97. this.fileFilter = fileFilter;
  98. }
  99. /**
  100. * Starts main deployer.
  101. *
  102. * @param kernel
  103. * the jboss microntainer kernel instance.
  104. * @param kernelDeployer
  105. * the jboss basic deployer.
  106. */
  107. public void start(Kernel kernel, BasicXMLDeployer kernelDeployer) throws Throwable {
  108. Version version = Version.instance;
  109. this.kernel = kernel;
  110. this.kernelDeployer = kernelDeployer;
  111. try {
  112. Configuration d = new Configuration("root", root);
  113. URL url = d.getConfig();
  114. deployment = kernelDeployer.deploy(url);
  115. kernelDeployer.validate();
  116. } catch (IOException e) {
  117. e.printStackTrace();
  118. }
  119. logger.info("[[[[[[[[[ " + version.toString() + " Started " + "]]]]]]]]]");
  120. }
  121. /**
  122. * Shuts down deployer.
  123. */
  124. public void stop() {
  125. kernelDeployer.undeploy(deployment);
  126. logger.info("Stopped");
  127. }
  128. }