1. /*
  2. * ====================================================================
  3. *
  4. * The Apache Software License, Version 1.1
  5. *
  6. * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
  7. * reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * 3. The end-user documentation included with the redistribution, if
  22. * any, must include the following acknowlegement:
  23. * "This product includes software developed by the
  24. * Apache Software Foundation (http://www.apache.org/)."
  25. * Alternately, this acknowlegement may appear in the software itself,
  26. * if and wherever such third-party acknowlegements normally appear.
  27. *
  28. * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  29. * Foundation" must not be used to endorse or promote products derived
  30. * from this software without prior written permission. For written
  31. * permission, please contact apache@apache.org.
  32. *
  33. * 5. Products derived from this software may not be called "Apache"
  34. * nor may "Apache" appear in their names without prior written
  35. * permission of the Apache Group.
  36. *
  37. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  38. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  39. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  41. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  45. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48. * SUCH DAMAGE.
  49. * ====================================================================
  50. *
  51. * This software consists of voluntary contributions made by many
  52. * individuals on behalf of the Apache Software Foundation. For more
  53. * information on the Apache Software Foundation, please see
  54. * <http://www.apache.org/>.
  55. *
  56. * [Additional notices, if required by prior licensing conditions]
  57. *
  58. */
  59. package org.apache.commons.modeler;
  60. import java.util.List;
  61. /**
  62. * Interface for modeler MBeans.
  63. *
  64. * This is the main entry point into modeler. It provides methods to create
  65. * and manipulate model mbeans and simplify their use.
  66. *
  67. * Starting with version 1.1, this is no longer a singleton and the static
  68. * methods are strongly deprecated. In a container environment we can expect
  69. * different applications to use different registries.
  70. *
  71. * @author Craig R. McClanahan
  72. * @author Costin Manolache
  73. *
  74. * @since 1.1
  75. */
  76. public interface RegistryMBean {
  77. /**
  78. * Load an extended mlet file. The source can be an URL, File or
  79. * InputStream.
  80. *
  81. * All mbeans will be instantiated, registered and the attributes will be
  82. * set. The result is a list of ObjectNames.
  83. *
  84. * @param source InputStream or URL of the file
  85. * @param cl ClassLoader to be used to load the mbeans, or null to use the
  86. * default JMX mechanism ( i.e. all registered loaders )
  87. * @return List of ObjectName for the loaded mbeans
  88. * @throws Exception
  89. *
  90. * @since 1.1
  91. */
  92. public List loadMBeans( Object source, ClassLoader cl ) throws Exception;
  93. /** Invoke an operation on a set of mbeans.
  94. *
  95. * @param mbeans List of ObjectNames
  96. * @param operation Operation to perform. Typically "init" "start" "stop" or "destroy"
  97. * @param failFirst Behavior in case of exceptions - if false we'll ignore
  98. * errors
  99. * @throws Exception
  100. */
  101. public void invoke( List mbeans, String operation, boolean failFirst )
  102. throws Exception;
  103. /** Register a bean by creating a modeler mbean and adding it to the
  104. * MBeanServer.
  105. *
  106. * If metadata is not loaded, we'll look up and read a file named
  107. * "mbeans-descriptors.ser" or "mbeans-descriptors.xml" in the same package
  108. * or parent.
  109. *
  110. * If the bean is an instance of DynamicMBean. it's metadata will be converted
  111. * to a model mbean and we'll wrap it - so modeler services will be supported
  112. *
  113. * If the metadata is still not found, introspection will be used to extract
  114. * it automatically.
  115. *
  116. * If an mbean is already registered under this name, it'll be first
  117. * unregistered.
  118. *
  119. * If the component implements MBeanRegistration, the methods will be called.
  120. * If the method has a method "setRegistry" that takes a RegistryMBean as
  121. * parameter, it'll be called with the current registry.
  122. *
  123. *
  124. * @param bean Object to be registered
  125. * @param oname Name used for registration
  126. * @param type The type of the mbean, as declared in mbeans-descriptors. If
  127. * null, the name of the class will be used. This can be used as a hint or
  128. * by subclasses.
  129. *
  130. * @since 1.1
  131. */
  132. public void registerComponent(Object bean, String oname, String type)
  133. throws Exception;
  134. /** Unregister a component. We'll first check if it is registered,
  135. * and mask all errors. This is mostly a helper.
  136. *
  137. * @param oname
  138. *
  139. * @since 1.1
  140. */
  141. public void unregisterComponent( String oname );
  142. /** Return an int ID for faster access. Will be used for notifications
  143. * and for other operations we want to optimize.
  144. *
  145. * @param domain Namespace
  146. * @param name Type of the notification
  147. * @return An unique id for the domain:name combination
  148. * @since 1.1
  149. */
  150. public int getId( String domain, String name);
  151. /** Reset all metadata cached by this registry. Should be called
  152. * to support reloading. Existing mbeans will not be affected or modified.
  153. *
  154. * It will be called automatically if the Registry is unregistered.
  155. * @since 1.1
  156. */
  157. public void stop();
  158. /** Load descriptors. The source can be a File, URL pointing to an
  159. * mbeans-descriptors.xml.
  160. *
  161. * Also ( experimental for now ) a ClassLoader - in which case META-INF/ will
  162. * be used.
  163. *
  164. * @param source
  165. */
  166. public void loadMetadata(Object source ) throws Exception;
  167. }