You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/01/12 03:10:23 UTC
cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel DefaultApplicationContext.java
donaldp 02/01/11 18:10:23
Modified: src/java/org/apache/avalon/phoenix/interfaces
ApplicationContext.java
src/java/org/apache/avalon/phoenix/components/kernel
DefaultApplicationContext.java
Log:
Add in mechanisms for the Application to expose sub-elements via the management interface. The sub-elements must be represented by an interface and have a name of the form.
application=Foo,name=MrBlock,role=org.apache.MyManagementInterface
Revision Changes Path
1.5 +21 -0 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java
Index: ApplicationContext.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ApplicationContext.java 11 Dec 2001 10:13:34 -0000 1.4
+++ ApplicationContext.java 12 Jan 2002 02:10:22 -0000 1.5
@@ -30,6 +30,27 @@
ThreadContext getThreadContext();
/**
+ * Export specified object into management system.
+ * The object is exported using specifed interface
+ * and using the specified name.
+ *
+ * @param name the name of object to export
+ * @param interfaceClass the interface of object with which to export
+ * @param object the actual object to export
+ */
+ void exportObject( String name, Class interfaceClass, Object object )
+ throws Exception;
+
+ /**
+ * Unexport specified object from management system.
+ *
+ * @param name the name of object to unexport
+ * @param interfaceClass the interface of object with which to unexport
+ */
+ void unexportObject( String name, Class interfaceClass )
+ throws Exception;
+
+ /**
* Get ClassLoader for the current application.
*
* @return the ClassLoader
1.9 +51 -6 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java
Index: DefaultApplicationContext.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultApplicationContext.java 11 Dec 2001 10:13:34 -0000 1.8
+++ DefaultApplicationContext.java 12 Jan 2002 02:10:23 -0000 1.9
@@ -24,6 +24,7 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.phoenix.interfaces.ApplicationContext;
import org.apache.avalon.phoenix.interfaces.ConfigurationRepository;
+import org.apache.avalon.phoenix.interfaces.SystemManager;
import org.apache.avalon.phoenix.metadata.SarMetaData;
import org.apache.log.Hierarchy;
import org.apache.log.Logger;
@@ -41,21 +42,24 @@
ResourceManager.getPackageResources( DefaultApplicationContext.class );
///Map of thread pools for application
- private HashMap m_threadPools = new HashMap();
+ private final HashMap m_threadPools = new HashMap();
- //LogKitManager for application
- private Hierarchy m_hierarchy;
+ //Log HIerarchy for application
+ private final Hierarchy m_hierarchy;
///ClassLoader for application
- private ClassLoader m_classLoader;
+ private final ClassLoader m_classLoader;
///ThreadContext for application
- private ThreadContext m_threadContext;
+ private final ThreadContext m_threadContext;
//Repository of configuration data to access
private ConfigurationRepository m_repository;
- private SarMetaData m_metaData;
+ ///Place to expose Management beans
+ private SystemManager m_systemManager;
+
+ private final SarMetaData m_metaData;
protected DefaultApplicationContext( final SarMetaData metaData,
final ClassLoader classLoader,
@@ -75,6 +79,7 @@
throws ComponentException
{
m_repository = (ConfigurationRepository)componentManager.lookup( ConfigurationRepository.ROLE );
+ m_systemManager = (SystemManager)componentManager.lookup( SystemManager.ROLE );
}
/**
@@ -133,6 +138,46 @@
public Logger getLogger( final String category )
{
return m_hierarchy.getLoggerFor( category );
+ }
+
+ /**
+ * Export specified object into management system.
+ * The object is exported using specifed interface
+ * and using the specified name.
+ *
+ * @param name the name of object to export
+ * @param interfaceClass the interface of object with which to export
+ * @param object the actual object to export
+ */
+ public void exportObject( final String name,
+ final Class service,
+ final Object object )
+ throws Exception
+ {
+ final String longName = getServiceName( name, service );
+ m_systemManager.register( longName, object, new Class[] { service } );
+ }
+
+ /**
+ * Unexport specified object from management system.
+ *
+ * @param name the name of object to unexport
+ * @param interfaceClass the interface of object with which to unexport
+ */
+ public void unexportObject( final String name, final Class service )
+ throws Exception
+ {
+ final String longName = getServiceName( name, service );
+ m_systemManager.unregister( longName );
+ }
+
+ /**
+ * Utility method to get the JMX-ized name of service to export
+ */
+ private String getServiceName( final String name, final Class service )
+ {
+ return name + ",application=" + getMetaData().getName() +
+ ",role=" + service.getName();
}
/**
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>