You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by sa...@apache.org on 2006/08/11 00:16:02 UTC
svn commit: r430562 [1/6] - in
/incubator/felix/sandbox/santillan/org.apache.felix.jmood: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/jmood/
src/main/java/...
Author: santillan
Date: Thu Aug 10 15:15:58 2006
New Revision: 430562
URL: http://svn.apache.org/viewvc?rev=430562&view=rev
Log:
Initial version of JMood for the sandbox
Added:
incubator/felix/sandbox/santillan/org.apache.felix.jmood/pom.xml
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/ (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/ (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/ (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/Activator.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentConstants.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentContext.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/CompendiumController.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManager.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManagerMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegate.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegateMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManager.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManagerMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/UserManager.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/UserManagerMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/BundleNotAvailableException.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/CoreController.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/CoreControllerMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/Framework.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/FrameworkMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ManagedBundle.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ManagedBundleMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ManagedPackage.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ManagedPackageMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ManagedService.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ManagedServiceMBean.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/NotImplementedException.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/ServiceNotAvailableException.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/BundleInfo.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/FrameworkSnapshot.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/PackageInfo.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/core/instrumentation/ServiceInfo.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/utils/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/utils/CompositeDataItemNames.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/utils/InstrumentationSupport.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/utils/OSGi2JMXCodec.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/utils/OSGiTypes.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/utils/ObjectNames.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/agent.properties
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/config.properties
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/descriptor.xml
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/jmood.xml
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/manifest.r4
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/resources/simple.policy
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/models/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/models/mom.uod
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/models/org.apache.felix.jmood.core.classdiagram.ucd
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/models/org.apache.felix.jmood.core.classdiagram.wmf (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/models/org.apache.felix.jmood.core.ucd
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/images/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/images/fondo-azul-blanco.jpg (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/images/smile_yellow.jpg (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/images/valid-html401 (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/images/valid-html401.png (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/images/vcss.png (with props)
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/index.html
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/js/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/js/fecha.js
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/js/menu.js
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/js/overlib.js
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/js/overlib_mini.js
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/styles/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/resources/styles/resolvit.css
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/site/site.xml
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/MyMain.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/BundleMBeanTestCase.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/CoreTestCase.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/java/org/apache/felix/jmood/core/TestHarness.java
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/resources/
incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/test/resources/config.properties
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/pom.xml?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/pom.xml (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/pom.xml Thu Aug 10 15:15:58 2006
@@ -0,0 +1,85 @@
+<project>
+ <groupId>org.apache.felix</groupId>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>osgi-bundle</packaging>
+ <name>JMood JMX Management Agent</name>
+ <artifactId>${groupId}.jmood</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.main</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>mx4j</groupId>
+ <artifactId>mx4j-tools</artifactId>
+ <version>1.1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix.plugins</groupId>
+ <artifactId>maven-osgi-plugin</artifactId>
+ <version>${pom.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest >
+ <bundleName>${name}</bundleName>
+ <bundleActivator>${artifactId}.Activator</bundleActivator>
+ <bundleDescription>JMood management agent</bundleDescription>
+ <bundleSymbolicName>${artifactId}</bundleSymbolicName>
+ <exportPackage>
+ <!-- TODO -->
+ </exportPackage>
+ <!--Automatic resolution includes not available, unused, mx4j stuff-->
+ <importPackage>
+ org.osgi.framework, org.osgi.util.tracker, org.osgi.service.log, org.osgi.service.packageadmin, org.osgi.service.startlevel, org.osgi.service.permissionadmin, org.osgi.service.useradmin, org.osgi.service.cm, javax.management, javax.management.remote
+ </importPackage>
+
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
Propchange: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 10 15:15:58 2006
@@ -0,0 +1,2 @@
+
+*CVS
Propchange: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 10 15:15:58 2006
@@ -0,0 +1,2 @@
+
+CVS
Propchange: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 10 15:15:58 2006
@@ -0,0 +1,2 @@
+
+*CVS*
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/Activator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/Activator.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/Activator.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/Activator.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,231 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.felix.jmood;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.URL;
+import java.rmi.server.ExportException;
+import java.util.Properties;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+
+import mx4j.tools.naming.NamingService;
+
+import org.apache.felix.jmood.core.CoreController;
+import org.apache.felix.jmood.core.Framework;
+import org.apache.felix.jmood.utils.ObjectNames;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+public class Activator implements BundleActivator{
+ private Properties props;
+ private String agentPropsPath="/agent.properties";
+ private static final String IS_POLICY_EMBEDDED="policy.embedded";
+ private static final String JAVA_SECURITY_POLICY="java.security.policy";
+ private MBeanServer server;
+ private JMXConnectorServer connectorServer;
+ private int rmiRegistryPort = 1199;
+ private AgentContext ac;
+ private static final String rmiregOname="RemotingService:type=NamingService,subtype=RMIRegistry, provider=MX4J";
+ private static final String connectoServerOname="RemotingService:type=ConnectorServer, subtype=RMIConnectorServer, provider=JRE";
+ private CompendiumController compendium;
+ private NamingService rmiRegistry;
+
+
+ public void start(BundleContext context) throws Exception {
+ this.ac=new AgentContext(context);
+ this.ac.debug("starting");
+ try{
+ this.server=this.getMBeanServer();
+ }
+ catch (Exception e){
+ this.ac.error("unexpected error", e);
+ throw e;
+ }
+ this.ac.debug("got platform mbeanserver");
+ this.compendium = new CompendiumController(this.server,this.ac);
+ this.props = this.loadProperties();
+ this.ac.debug("props loaded");
+ //TODO Enable this when Felix has security support.RMI Serialization doesn't work well without it. In Equinox, it works fine
+ //this.setSecurityManager();
+ //ac.debug("security manager set");
+ this.ac.debug("registering mbeans");
+ this.registerMBeans();
+ this.initRMIConn();
+ this.ac.debug("rmi connection initialised and mbeans registered");
+ this.ac.debug("agent started");
+ }
+ public void stop(BundleContext context) throws Exception {
+ this.ac.debug("stopping");
+ this.stopRMIConn();
+ this.ac.closeTrackers();
+ this.unregisterMBeans();
+ this.ac.debug("done");
+ }
+ private void setSecurityManager() throws Exception{
+ //TODO check this when we add permission admin support to the bundle
+ //It caused StackOverFlow the second time the framework was run(?)
+
+ if (System.getSecurityManager() != null) {
+ return;
+ }
+ try {
+ this.ac.debug("Security manager does not exist");
+ if (this.props.getProperty(IS_POLICY_EMBEDDED).equalsIgnoreCase("true")){
+ this.ac.debug("Policy is embedded, copying it to filesystem...");
+ String policyName=this.props.getProperty(JAVA_SECURITY_POLICY);
+ //The policy is in the file system and should be copied...
+ File file=this.ac.getBundleContext().getDataFile(policyName);
+ if (file.exists()) {
+ this.ac.debug("trying to delete file...");
+ boolean deleted=file.delete();
+ if(!deleted) {
+ this.ac.error("Could not delete existing policy file");
+ } else {
+ this.ac.debug("successfully deleted");
+ }
+ file=this.ac.getBundleContext().getDataFile(policyName);
+ file.createNewFile();
+ this.ac.debug("new file created");
+ }
+
+ FileOutputStream o=new FileOutputStream (file);
+ InputStream i=this.ac.getBundleContext().getBundle().getResource("/"+policyName).openStream();
+ byte [] buffer=new byte [1024];
+ while (i.read(buffer)!=-1){
+ o.write(buffer);
+ }
+ i.close();
+ o.flush();
+ o.close();
+
+ System.setProperty(JAVA_SECURITY_POLICY, file.getAbsolutePath());
+ }
+ else{
+ System.setProperty(JAVA_SECURITY_POLICY, this.props.getProperty(JAVA_SECURITY_POLICY));
+ }
+ System.setSecurityManager(new SecurityManager());
+
+ }catch(Exception e){
+ this.ac.error("Unexpected exception", e);
+ }
+ this.ac.debug("Security policy: "+System.getProperty(JAVA_SECURITY_POLICY));
+ this.ac.debug("Security manager toString(): "+System.getSecurityManager().toString());
+
+ }
+
+ private Properties loadProperties() throws Exception{
+ Properties props = new Properties();
+ URL u=this.ac.getBundleContext().getBundle().getResource(this.agentPropsPath);
+ props.load(u.openStream());
+ return props;
+ }
+
+ /**
+ * A getter method for retrieving the context of this bundle
+ * @return BundleContext the bundle context for this bundle
+ * @throws InstanceNotFoundException
+ */
+
+ private void initRMIConn() throws IOException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, NullPointerException, InstanceNotFoundException {
+ rmiRegistry=new NamingService(rmiRegistryPort);
+ ObjectName rmiRegName = new ObjectName(rmiregOname);
+ server.registerMBean(rmiRegistry, rmiRegName);
+ try {
+ rmiRegistry.start();
+ } catch (ExportException e) {
+ ac.warning(e.getMessage()+"\n"+"Possibly some other framework already running, skipping RMI setup");
+ server.unregisterMBean(rmiRegName);
+ return;
+ }
+ InetAddress[] addresses=InetAddress.getAllByName(InetAddress.getLocalHost().getCanonicalHostName());
+ //Do not attach the agent to the loopback address
+ InetAddress address=null;
+ for (int i = 0; i < addresses.length; i++) {
+ if (!addresses[i].isLoopbackAddress()) {
+ address=addresses[i];
+ break;
+ }
+ }
+ if (address==null){
+ StringBuffer msg=new StringBuffer("java.net.InetAddress could not find non-localhost IP. \n");
+ msg.append(" Is there any network interface available? Are you using Linux?. \n")
+ .append("If you are using debian-based distros, try editing the /etc/hosts file so that it does not contain")
+ .append(" something like '127.0.0.1 ${hostname}'");
+ this.ac.warning(msg.toString());
+ address=InetAddress.getLocalHost();
+ }
+ JMXServiceURL url = new JMXServiceURL(
+ "service:jmx:rmi:///jndi/rmi://"+address.getHostName()+":"
+ + this.rmiRegistryPort + "/server");
+ this.ac.debug(url.toString());
+ this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(
+ url, null,this.server);
+
+ this.server.registerMBean(this.connectorServer, new ObjectName(connectoServerOname));
+ this.connectorServer.start();
+ }
+ private void stopRMIConn() throws Exception {
+ this.connectorServer.stop();
+ this.rmiRegistry.stop();
+ this.server.unregisterMBean(new ObjectName(rmiregOname));
+ this.server.unregisterMBean(new ObjectName(connectoServerOname));
+ }
+
+ private void registerMBeans() throws Exception{
+ this.server.registerMBean(new CoreController(this.ac), new ObjectName(ObjectNames.CORE_CONTROLLER));
+ this.server.registerMBean(new Framework(this.ac), new ObjectName(ObjectNames.FRAMEWORK));
+ this.compendium.initController();
+ this.ac.debug("mbeans registered");
+
+
+ }
+ private void unregisterMBeans() throws Exception{
+ this.server.unregisterMBean(new ObjectName(ObjectNames.CORE_CONTROLLER));
+ this.server.unregisterMBean(new ObjectName(ObjectNames.FRAMEWORK));
+ this.compendium.dispose();
+ }
+ private MBeanServer getMBeanServer() throws Exception{
+ String jvm=System.getProperty("java.version"); //1.5.0 or higher
+ this.ac.debug("java version is: "+jvm);
+ String[] s=jvm.split("\\.");
+ if(Integer.parseInt(s[1])<5){//In this way it should also work with Mustang
+ return MBeanServerFactory.createMBeanServer();
+ } else {
+ Class clazz =
+ Class.forName("java.lang.management.ManagementFactory");
+ Method m=clazz.getDeclaredMethod("getPlatformMBeanServer", new Class[0]);
+ return (MBeanServer) m.invoke(null,(Object[]) null);
+ }
+ }
+
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentConstants.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentConstants.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentConstants.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentConstants.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood;
+
+/**
+ * org.apache.felix.jmood
+ * ManagementAgent
+ *
+ *
+ */
+public interface AgentConstants {
+ public static final String FRAMEWORK_NOTIFICATION_TYPE =
+ "osgi.framework.framework";
+ public static final String USER_ADMIN_NOTIFICATION_TYPE = "osgi.useradmin";
+ public static final String SERVICE_NOTIFICATION_TYPE =
+ "osgi.framework.service";
+ public static final String LOG_NOTIFICATION_TYPE = "osgi.log";
+ public static final String USER = "User";
+ public static final String GROUP = "Group";
+ public static final String ROLE = "Role";
+
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentContext.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentContext.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentContext.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/AgentContext.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.felix.jmood;
+
+
+import org.apache.felix.jmood.core.ServiceNotAvailableException;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.permissionadmin.PermissionAdmin;
+import org.osgi.service.startlevel.StartLevel;
+import org.osgi.service.useradmin.UserAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+
+/**
+ *
+ *
+ */public class AgentContext {
+ private BundleContext context;
+ private ServiceTracker logTracker;
+ private ServiceTracker logReaderTracker;
+ private ServiceTracker startLevelTracker;
+ private ServiceTracker packageAdminTracker;
+ private ServiceTracker permissionAdminTracker;
+ private ServiceTracker userAdminTracker;
+ private ServiceTracker configAdminTracker;
+
+ private int loglevel;
+ public static final int DEBUG=0;
+ public static final int INFO=1;
+ public static final int WARNING=2;
+ public static final int ERROR=3;
+ public AgentContext(BundleContext context) throws Exception{
+ super();
+ this.context=context;
+ this.setTrackers();
+ }
+
+ ///////////////////////////////////////////////////////////////
+ //////////////////LOGGING/////////////////////////////////////
+ ///////////////////////////////////////////////////////////////
+ public void debug(String s){
+ if(this.loglevel==DEBUG) System.out.println("DEBUG: JMOOD. "+s);
+ }
+ public void info(String s){
+ if(this.loglevel<=INFO) System.out.println("INFO: JMOOD. "+s);
+ }
+ public void warning (String s){
+ if(this.loglevel<=WARNING) System.out.println("WARNING: JMOOD. "+s);
+ }
+ public void error(String s){
+ if(this.loglevel<=ERROR) System.out.println("ERROR: JMOOD. "+s);
+ }
+ public void error(String s, Exception e){
+ if(this.loglevel<=ERROR) {
+ System.out.println("ERROR: JMOOD. "+s);
+ e.printStackTrace();
+ }
+ }
+ public int getLoglevel() {
+ return loglevel;
+ }
+ public void setLoglevel(int level) {
+ this.loglevel=level;
+ }
+ //////////////////////////////////////////////////////////////
+ ///////////////////CONTEXT AND SERVICES//////////////////////
+ public BundleContext getBundleContext() {
+ return context;
+ }
+ public LogService getLogservice() {
+ int count = logTracker.getTrackingCount();
+ switch (count) {
+ case 0 :
+ return null;
+ //FUTURE WORK when there is more than one log service available, select "the best"
+ case 1 :
+ default :
+ return (LogService) logTracker.getService();
+ }
+ }
+ public StartLevel getStartLevel() throws ServiceNotAvailableException {
+ int count = startLevelTracker.getTrackingCount();
+ switch (count) {
+ case 0 :
+ throw new ServiceNotAvailableException("No start level service available");
+ case 1 :
+ default :
+ return (StartLevel) startLevelTracker.getService();
+ }
+ }
+ public PackageAdmin getPackageadmin() throws ServiceNotAvailableException{
+ int count = packageAdminTracker.getTrackingCount();
+ switch (count) {
+ case 0 :
+ throw new ServiceNotAvailableException("No package admin available");
+ case 1 :
+ default :
+ return (PackageAdmin) packageAdminTracker.getService();
+ }
+
+ }
+ public PermissionAdmin getPermissionadmin() {
+ int count = permissionAdminTracker.getTrackingCount();
+ switch (count) {
+ case 0 :
+ return null;
+ case 1 :
+ default :
+ return (PermissionAdmin) permissionAdminTracker.getService();
+ }
+ }
+ public UserAdmin getUserAdmin() {
+ int count = userAdminTracker.getTrackingCount();
+ switch (count) {
+ case 0 :
+ return null;
+ case 1 :
+ default :
+ return (UserAdmin) userAdminTracker.getService();
+ }
+ }
+ public ConfigurationAdmin getConfigurationAdmin() {
+ int count = configAdminTracker.getTrackingCount();
+ switch (count) {
+ case 0 :
+ return null;
+ case 1 :
+ default :
+ return (ConfigurationAdmin) configAdminTracker.getService();
+ }
+ }
+ //////////////////////////////////////////////////////////////////////
+ //////////////////PRIVATE////////////////////////////////////////////
+ private void setTrackers() {
+ try {
+ logTracker =
+ new ServiceTracker(
+ context,
+ context.createFilter(
+ "(objectClass=" + LogService.class.getName() + ")"),
+ null);
+ logReaderTracker =
+ new ServiceTracker(
+ context,
+ context.createFilter(
+ "(objectClass=" + LogReaderService.class.getName() + ")"),
+ null);
+ startLevelTracker =
+ new ServiceTracker(
+ context,
+ context.createFilter(
+ "(objectClass=" + StartLevel.class.getName() + ")"),
+ null);
+ packageAdminTracker =
+ new ServiceTracker(
+ context,
+ context.createFilter(
+ "(objectClass=" + PackageAdmin.class.getName() + ")"),
+ null);
+ permissionAdminTracker =
+ new ServiceTracker(
+ context,
+ context.createFilter(
+ "(objectClass=" + PermissionAdmin.class.getName() + ")"),
+ null);
+ userAdminTracker=new ServiceTracker(context, context.createFilter("(objectClass=" + UserAdmin.class.getName() + ")"), null);
+ configAdminTracker=new ServiceTracker(context, context.createFilter("(objectClass=" + ConfigurationAdmin.class.getName() + ")"), null);
+
+ } catch (InvalidSyntaxException e) {
+ warning("INVALID FILTER ");
+ }
+
+
+
+ logTracker.open();
+ logReaderTracker.open();
+ startLevelTracker.open();
+ packageAdminTracker.open();
+ permissionAdminTracker.open();
+ userAdminTracker.open();
+ configAdminTracker.open();
+ }
+ void closeTrackers() {
+ logTracker.close();
+ logReaderTracker.close();
+ startLevelTracker.close();
+ packageAdminTracker.close();
+ permissionAdminTracker.close();
+ userAdminTracker.close();
+ configAdminTracker.close();
+
+
+ }
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/CompendiumController.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/CompendiumController.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/CompendiumController.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/CompendiumController.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.felix.jmood;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+
+import org.apache.felix.jmood.compendium.ConfigAdminManager;
+import org.apache.felix.jmood.compendium.ConfigAdminManagerMBean;
+import org.apache.felix.jmood.compendium.LogManager;
+import org.apache.felix.jmood.compendium.LogManagerMBean;
+import org.apache.felix.jmood.compendium.UserManager;
+import org.apache.felix.jmood.compendium.UserManagerMBean;
+import org.apache.felix.jmood.utils.ObjectNames;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogService;
+import org.osgi.service.useradmin.UserAdmin;
+
+
+/**
+ * This class will control the life-cycle of MBeans related to OSGi Compendium
+ * Services
+ *
+ *
+ */
+public class CompendiumController {
+
+ private AgentContext ac;
+
+ private ServiceListener sl;
+
+ private Vector svcs;
+
+ private MBeanServer server;
+
+ public CompendiumController(MBeanServer server, AgentContext ac) {
+ super();
+ this.ac = ac;
+ this.server = server;
+ svcs = new Vector();
+ svcs.add(ConfigurationAdmin.class.getName());
+ svcs.add(UserAdmin.class.getName());
+ svcs.add(LogService.class.getName());
+ sl = new ServiceListener() {
+ public void serviceChanged(ServiceEvent event) {
+ processServiceEvent(event);
+ }
+ };
+ }
+
+ public void initController() {
+ try {
+ if (ac.getConfigurationAdmin() != null) {
+ ConfigAdminManagerMBean ca = new ConfigAdminManager(ac);
+ server
+ .registerMBean(ca, new ObjectName(
+ ObjectNames.CM_SERVICE));
+ }
+ if (ac.getLogservice() != null) {
+ LogManagerMBean lm = new LogManager(ac);
+ server.registerMBean(lm,
+ new ObjectName(ObjectNames.LOG_SERVICE));
+ }
+ if (ac.getUserAdmin() != null) {
+ UserManagerMBean um = new UserManager(ac);
+ server
+ .registerMBean(um, new ObjectName(
+ ObjectNames.UA_SERVICE));
+ }
+ } catch (InstanceAlreadyExistsException e) {
+ ac.error("Unexpected error", e);
+ } catch (MBeanRegistrationException e) {
+ ac.error("Unexpected error", e);
+ } catch (NotCompliantMBeanException e) {
+ ac.error("Unexpected error", e);
+ } catch (MalformedObjectNameException e) {
+ ac.error("Unexpected error", e);
+ } catch (NullPointerException e) {
+ ac.error("Unexpected error", e);
+ }
+ ac.getBundleContext().addServiceListener(sl);
+
+ }
+
+ public void dispose() {
+ ac.getBundleContext().removeServiceListener(sl);
+ try {
+ Iterator it = server.queryNames(
+ new ObjectName(ObjectNames.COMPENDIUM + ":*"), null)
+ .iterator();
+ while (it.hasNext())
+ server.unregisterMBean((ObjectName) it.next());
+
+ } catch (MalformedObjectNameException e) {
+ ac.error("Unexpected error", e);
+ } catch (NullPointerException e) {
+ ac.error("Unexpected error", e);
+ } catch (InstanceNotFoundException e) {
+ ac.error("Unexpected error", e);
+ } catch (MBeanRegistrationException e) {
+ ac.error("Unexpected error", e);
+ }
+ }
+
+ private void processServiceEvent(ServiceEvent event) {
+ String[] svs = (String[]) event.getServiceReference().getProperty(
+ Constants.OBJECTCLASS);
+ // Check if this event comes from an OSGi compendium service
+ for (int i = 0; i < svs.length; i++) {
+ if (svcs.contains(svs[i])) {
+ if (event.getType() == ServiceEvent.REGISTERED
+ || event.getType() == ServiceEvent.UNREGISTERING)
+ handleEvent(event.getServiceReference(), svs[i], event
+ .getType());
+ }
+ }
+
+ }
+
+ private void handleEvent(ServiceReference serviceReference,
+ String iService, int eType) {
+ try {
+
+ if (iService.equals(ConfigurationAdmin.class.getName())) {
+ switch (eType) {
+ case ServiceEvent.REGISTERED:
+ ConfigAdminManagerMBean ca = new ConfigAdminManager(ac);
+ server.registerMBean(ca, new ObjectName(
+ ObjectNames.CM_SERVICE));
+ break;
+ case ServiceEvent.UNREGISTERING:
+ server.unregisterMBean(new ObjectName(
+ ObjectNames.CM_SERVICE));
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (iService.equals(LogService.class.getName())) {
+ switch (eType) {
+ case ServiceEvent.REGISTERED:
+ LogManagerMBean lm = new LogManager(ac);
+ server.registerMBean(lm, new ObjectName(
+ ObjectNames.LOG_SERVICE));
+ break;
+ case ServiceEvent.UNREGISTERING:
+ server.unregisterMBean(new ObjectName(
+ ObjectNames.LOG_SERVICE));
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (iService.equals(UserAdmin.class.getName())) {
+ switch (eType) {
+ case ServiceEvent.REGISTERED:
+ UserManagerMBean um = new UserManager(ac);
+ server.registerMBean(um, new ObjectName(
+ ObjectNames.UA_SERVICE));
+ break;
+ case ServiceEvent.UNREGISTERING:
+ server.unregisterMBean(new ObjectName(
+ ObjectNames.UA_SERVICE));
+ break;
+ default:
+ break;
+ }
+ }
+ } catch (InstanceAlreadyExistsException e) {
+ ac.error("Unexpected error", e);
+ } catch (MBeanRegistrationException e) {
+ ac.error("Unexpected error", e);
+ } catch (NotCompliantMBeanException e) {
+ ac.error("Unexpected error", e);
+ } catch (MalformedObjectNameException e) {
+ ac.error("Unexpected error", e);
+ } catch (NullPointerException e) {
+ ac.error("Unexpected error", e);
+ } catch (InstanceNotFoundException e) {
+ ac.error("Unexpected error", e);
+ }
+ }
+
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManager.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManager.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManager.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,357 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood.compendium;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.ObjectName;
+
+import org.apache.felix.jmood.AgentContext;
+import org.apache.felix.jmood.utils.ObjectNames;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+//import es.upm.dit.osgi.management.agent.AgentConstants;
+/**
+ * This is the main class of the config admin module. As such, it is responsible for controlling all the issues related to it. This class implements
+ * the ConfigAdminManagerMXBean which defines its management interface. It creates a ConfigurationDelegate object for each available
+ * Configuration object.
+ *
+ */
+public class ConfigAdminManager extends NotificationBroadcasterSupport
+ implements MBeanRegistration, ConfigAdminManagerMBean{
+ /*NOTE: The spec says that ConfigurationException's should be used by management systems
+ * in order to inform a human manager in a suitable way. However, this is not possible unless we implement the service
+ * because nowhere in the spec is there a way of accesing those exceptions (unless the implementation of the cm chooses to log the exception, which is not even suggested in the spec)
+ */
+ private MBeanServer server;
+ private AgentContext ac;
+ private ConfigurationAdmin cadmin;
+ public ConfigAdminManager(AgentContext ac) {
+ this.ac=ac;
+
+ }
+ /**
+ * This is called before the module is loaded. It initializes the module.
+ * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer, javax.management.ObjectName)
+ */
+ public ObjectName preRegister(MBeanServer server, ObjectName name)
+ throws Exception {
+ this.server = server;
+ return name;
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
+ */
+ public void postRegister(Boolean registrationDone) {}
+ /**
+ * @see javax.management.MBeanRegistration#preDeregister()
+ */
+ public void preDeregister() throws Exception {
+ //Remove the service
+ //and remove all mbeans from this module...
+ unregisterMBeans();
+ }
+ /**
+ * @see javax.management.MBeanRegistration#postDeregister()
+ */
+ public void postDeregister() {}
+
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#listConfigurations(java.lang.String)
+ */
+
+ public String[] listConfigurations(String filter) throws Exception {
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ Configuration[] confs = null;
+ if (cad!= null) {
+ confs = cad.listConfigurations(filter);
+ refresh();
+ if (confs == null)
+ return null;
+ }
+ String[] result = new String[confs.length];
+ for (int i = 0; i < confs.length; i++)
+ result[i] = this.getObjectName(confs[i]);
+ return result;
+ }
+
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#getConfiguration(java.lang.String)
+ */
+ public String getConfiguration(String pid) throws Exception {
+ //FIXME this should not be invoked
+ //if created, the configuration is attached to the management agent's location
+ ac.debug("ConfigAdmin, getting config for pid: "+pid);
+ if (pid.contains(":")) throw new IllegalArgumentException("pid not compliant with jmx. Please remove ':' from the pid");
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ if (cad != null) {
+ Configuration config = cad.getConfiguration(pid);
+ refresh();
+ return this.getObjectName(config);
+
+ } else
+ return null;
+ }
+
+ /**
+ * This method gets a configuration object related to a pid and a bundle location
+ * @param pid Persistent ID
+ * @param location Bundle location of the service
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#getConfiguration(java.lang.String, java.lang.String)
+ */
+ public String getConfiguration(String pid, String location)
+ throws Exception {
+ //":" is reserved in objectnames, as a work around we do not permit pids containing it
+ if (pid.contains(":")) throw new IllegalArgumentException("pid not compliant with jmx. Please remove ':' from the pid");
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ if (cad != null) {
+ Configuration config = cad.getConfiguration(pid, location);
+ refresh();
+ return this.getObjectName(config);
+ } else
+ return null;
+ }
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#createFactoryConfiguration(java.lang.String)
+ */
+ public String createFactoryConfiguration(String pid) throws Exception {
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ if (cad != null) {
+ Configuration conf = cad.createFactoryConfiguration(pid);
+ refresh();
+ return this.getObjectName(conf);
+ } else
+ return null;
+ }
+
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#createFactoryConfiguration(java.lang.String, java.lang.String)
+ */
+ public String createFactoryConfiguration(String pid, String location)
+ throws Exception {
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ if (cad != null) {
+ Configuration conf = cad.createFactoryConfiguration(pid, location);
+ refresh();
+ return this.getObjectName(conf);
+ } else
+ return null;
+ }
+ /**
+ * Delete the configurations identified by the LDAP filter
+ * @param filter LDAP String representing the configurations that want to be deleted
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#deleteConfigurations(java.lang.String)
+ */
+ public void deleteConfigurations(String filter) throws Exception {
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ Configuration[] confs = null;
+ if (cad!= null) {
+ confs = cad.listConfigurations(filter);
+ }
+ if (confs != null)
+ for (int i = 0; i < confs.length; i++) {
+ confs[i].delete();
+ }
+ refresh();
+ }
+
+ /**
+ * Removes a property from all the configurations selected by an LDAP expression
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#removePropertyFromConfigurations(java.lang.String, java.lang.String)
+ */
+ public void removePropertyFromConfigurations(String filter, String name)
+ throws Exception {
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ Configuration[] confs = null;
+ if (cad != null) {
+ confs = cad.listConfigurations(filter);
+ }
+ if (confs != null)
+ for (int i = 0; i < confs.length; i++) {
+ Dictionary dic = confs[i].getProperties();
+ Enumeration keys = dic.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ if (key.equals(name)) {
+ dic.remove(key);
+ try {
+ confs[i].update(dic);
+ } catch (IOException e) {
+ ac.error("Unexpected exception", (Exception)e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Updates or adds a property to configurations selected by an LDAP expression
+ * Arrays and vectors not supported
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#addPropertyToConfigurations(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void addPropertyToConfigurations(
+ String filter,
+ String name,
+ String value,
+ String type)
+ throws Exception {
+ if (isValidType(type)) {
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ Configuration[] confs = null;
+ if (cad != null) {
+ confs = cad.listConfigurations(filter);
+ }
+ if (confs != null)
+ for (int i = 0; i < confs.length; i++) {
+ Dictionary dic = confs[i].getProperties();
+ dic.put(name, castValueToType(type, value));
+ try {
+ confs[i].update(dic);
+ } catch (IOException e) {
+ ac.error("Unexpected exception", (Exception)e);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * Validate that the value type is supported
+ * @param type
+ */
+ protected static boolean isValidType(String type) {
+ String[] validTypes =
+ {
+ "String",
+ "Integer",
+ "Long",
+ "Float",
+ "Double",
+ "Byte",
+ "Short",
+ "Character",
+ "Boolean",
+ "BigInteger",
+ "BigDecimal" };
+ for (int i = 0; i < validTypes.length; i++) {
+ if (validTypes[i].equalsIgnoreCase(type))
+ return true;
+ }
+ return false;
+ }
+ protected static Object castValueToType(String type, String value) {
+ value = value.equals("") ? null : value;
+ if (type.equals("String")) {
+ return value == null ? new String() : new String(value);
+ } else if (type.equals("Integer")) {
+ return value == null ? new Integer(0) : new Integer(value);
+ } else if (type.equals("Long")) {
+ return value == null ? new Long(0) : new Long(value);
+ } else if (type.equals("Float")) {
+ return value == null ? new Float(0) : new Float(value);
+ } else if (type.equals("Double")) {
+ return value == null ? new Double(0) : new Double(value);
+ } else if (type.equals("Byte")) {
+ return value == null ? new Byte("0") : new Byte(value);
+ } else if (type.equals("Short")) {
+ return value == null ? new Short("0") : new Short(value);
+ } else if (type.equals("BigInteger")) {
+ return value == null ? new BigInteger("0") : new BigInteger(value);
+ } else if (type.equals("BigDecimal")) {
+ return value == null ? new BigDecimal(0) : new BigDecimal(value);
+ } else if (type.equals("Character")) {
+ return value == null
+ ? new Character('a')
+ : new Character(value.charAt(0));
+ } else if (type.equals("Boolean")) {
+ return value == null ? new Boolean(false) : new Boolean(value);
+ } else {
+ // Unsupported type
+ return null;
+ }
+ }
+ private void registerMBeans() throws Exception{
+ ConfigurationAdmin cad=ac.getConfigurationAdmin();
+ if (cad==null) {
+ ac.debug("could not add any conf mbean, conf admin not available");
+ return;
+ }
+ ac.debug("creating mbeans for existing config objects");
+ Configuration[] confs = null;
+ //confs contains the new config objects
+ //The old ones are in configObjects, whose key is the object name.
+ confs = cad.listConfigurations(null);
+ if (confs!=null) {
+ ac.debug("Existing conf objects: ");
+ for(int i=0;i<confs.length;i++) {
+ ac.debug("\t"+confs[i].getPid());
+ //now we add the new ones
+ String oname = this.getObjectName(confs[i]);
+ server.registerMBean(
+ new ConfigurationDelegate(confs[i], ac),
+ new ObjectName(oname));
+ ac.debug("Succesfully registered? "+!server.queryMBeans(new ObjectName(oname), null).isEmpty());
+ }
+ }
+
+ }
+ public synchronized void refresh() throws Exception {
+ //Extremely innefficient but KISS
+ unregisterMBeans();
+ registerMBeans();
+ }
+ public boolean isAvailable() {
+ return ac.getConfigurationAdmin()==null?false:true;
+ }
+ private void unregisterMBeans() throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException, MBeanRegistrationException{
+ Set set =
+ server.queryNames(
+ new ObjectName(ObjectNames.ALL_CM_OBJECT),
+ null);
+ Iterator it = set.iterator();
+ while (it.hasNext()) {
+ ObjectName oname=(ObjectName) it.next();
+ ac.debug("Unregistering config mbean: "+oname);
+ server.unregisterMBean(oname);
+ }
+ }
+
+ private String getObjectName(Configuration configuration) {
+ StringBuffer posfix = new StringBuffer();
+ posfix.append("pid=" + configuration.getPid());
+ if (configuration.getFactoryPid() != null)
+ posfix.append(
+ ",isFactory=true,FactoryPid=" + configuration.getFactoryPid());
+ else
+ posfix.append(",isFactory=false");
+ String oname = ObjectNames.CM_OBJECT + posfix.toString();
+ return oname;
+ }
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManagerMBean.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManagerMBean.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManagerMBean.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigAdminManagerMBean.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood.compendium;
+
+
+/**
+ * org.apache.felix.jmood.modules.configadmin
+ * ManagementAgent
+ *
+ *
+ */
+public interface ConfigAdminManagerMBean {
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#listConfigurations(java.lang.String)
+ */
+ public abstract String[] listConfigurations(String filter)
+ throws Exception;
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#getConfiguration(java.lang.String)
+ */
+ public abstract String getConfiguration(String pid) throws Exception;
+ /**
+ * This method gets a configuration object related to a pid and a bundle location
+ * @param pid Persistent ID
+ * @param location Bundle location of the service
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#getConfiguration(java.lang.String, java.lang.String)
+ */
+ public abstract String getConfiguration(String pid, String location)
+ throws Exception;
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#createFactoryConfiguration(java.lang.String)
+ */
+ public abstract String createFactoryConfiguration(String pid)
+ throws Exception;
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#createFactoryConfiguration(java.lang.String, java.lang.String)
+ */
+ public abstract String createFactoryConfiguration(
+ String pid,
+ String location)
+ throws Exception;
+ /**
+ * Delete the configurations identified by the LDAP filter
+ * @param filter LDAP String representing the configurations that want to be deleted
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#deleteConfigurations(java.lang.String)
+ */
+ public abstract void deleteConfigurations(String filter) throws Exception;
+ /**
+ * Removes a property from all the configurations selected by an LDAP expression
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#removePropertyFromConfigurations(java.lang.String, java.lang.String)
+ */
+ public abstract void removePropertyFromConfigurations(
+ String filter,
+ String name)
+ throws Exception;
+ /**
+ * Updates or adds a property to configurations selected by an LDAP expression
+ * Arrays and vectors not supported
+ * @see org.apache.felix.jmood.compendium.ConfigAdminManagerMBean#addPropertyToConfigurations(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ public abstract void addPropertyToConfigurations(
+ String filter,
+ String name,
+ String value,
+ String type)
+ throws Exception;
+ public abstract void refresh() throws Exception;
+ public abstract boolean isAvailable() throws Exception;
+}
\ No newline at end of file
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegate.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegate.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegate.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegate.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood.compendium;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.felix.jmood.AgentContext;
+import org.osgi.service.cm.Configuration;
+
+
+/**
+ * org.apache.felix.jmood.modules.configadmin
+ * ManagementAgent
+ *
+ *
+ */
+public class ConfigurationDelegate implements MBeanRegistration, ConfigurationDelegateMBean {
+ private Configuration configuration;
+ private MBeanServer server;
+ private ObjectName oname;
+ private AgentContext ac;
+ public ConfigurationDelegate(Configuration configuration, AgentContext ac){
+ this.configuration=configuration;
+ this.ac=ac;
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#getPid()
+ */
+ public String getPid() {
+
+ return configuration.getPid();
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#getProperties()
+ */
+ public Hashtable getProperties() {
+ Dictionary dic=configuration.getProperties();
+ Enumeration keys=dic.keys();
+ Hashtable properties=new Hashtable();
+ while(keys.hasMoreElements()) {
+ Object key=keys.nextElement();
+ properties.put(key, dic.get(key));
+ }
+ return properties;
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#update(java.util.Dictionary)
+ *hashtable is a dictionary!
+ */
+ public void update(Hashtable properties) throws IOException {
+ configuration.update(properties);
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#delete()
+ */
+ public void delete() throws Exception {
+ server.unregisterMBean(oname);
+ configuration.delete();
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#getFactoryPid()
+ */
+ public String getFactoryPid() {
+ return configuration.getFactoryPid();
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#update()
+ */
+ public void update() throws IOException {
+ configuration.update();
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#setBundleLocation(java.lang.String)
+ */
+ public void setBundleLocation(String bundleLocation) {
+ configuration.setBundleLocation(bundleLocation);
+ }
+
+ /**
+ * @see org.osgi.service.cm.Configuration#getBundleLocation()
+ */
+ public String getBundleLocation() {
+ return configuration.getBundleLocation();
+ }
+ /**
+ * @see javax.management.MBeanRegistration#postDeregister()
+ */
+ public void postDeregister() {
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
+ */
+ public void postRegister(Boolean registrationDone) {
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#preDeregister()
+ */
+ public void preDeregister() throws Exception {
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer, javax.management.ObjectName)
+ */
+ public ObjectName preRegister(MBeanServer server, ObjectName name)
+ throws Exception {
+ this.oname=name;
+ this.server=server;
+ return name;
+ }
+
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigurationDelegateMBean#getProperty(java.lang.String)
+ */
+ public String getProperty(String key) throws Exception {
+ Object result= configuration.getProperties().get(key);
+ if (result==null) return null;
+ if (result instanceof String) return (String) result;
+ else return result.toString();
+ }
+
+ /**
+ * @see org.apache.felix.jmood.compendium.ConfigurationDelegateMBean#setProperty(java.lang.String, java.lang.String)
+ */
+ public void setProperty(String key, String value, String type) throws Exception {
+ if (ConfigAdminManager.isValidType(type)) {
+ Dictionary dic = configuration.getProperties();
+ dic.put(key, ConfigAdminManager.castValueToType(type, value));
+ try {
+ configuration.update(dic);
+ } catch (IOException e) {
+ ac.error("Unexpected exception", (Exception)e);
+ }
+ }
+ }
+ public void deleteProperty(String key) throws Exception{
+ Dictionary dic = configuration.getProperties();
+ Enumeration keys = dic.keys();
+ while (keys.hasMoreElements()) {
+ String k = (String) keys.nextElement();
+ if (k.equals(key)) {
+ dic.remove(k);
+ configuration.update(dic);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegateMBean.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegateMBean.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegateMBean.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/ConfigurationDelegateMBean.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood.compendium;
+import java.util.Hashtable;
+
+/**
+ * org.apache.felix.jmood.modules.configadmin
+ * ManagementAgent
+ *
+ *
+ */
+public interface ConfigurationDelegateMBean {
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#getPid()
+ */
+ public abstract String getPid() throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#getProperties()
+ */
+ public abstract Hashtable getProperties() throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#update(java.util.Dictionary)
+ *hashtable is a dictionary!
+ */
+ public abstract void update(Hashtable properties) throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#delete()
+ */
+ public abstract void delete() throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#getFactoryPid()
+ */
+ public abstract String getFactoryPid() throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#update()
+ */
+ public abstract void update() throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#setBundleLocation(java.lang.String)
+ */
+ public abstract void setBundleLocation(String bundleLocation) throws Exception;
+ /* (no Javadoc)
+ * @see org.osgi.service.cm.Configuration#getBundleLocation()
+ */
+ public abstract String getBundleLocation() throws Exception;
+ /* (no Javadoc)
+ * @see org.apache.felix.jmood.modules.configadmin.ConfigurationDelegateMXBean#getProperty(java.lang.String)
+ */
+ public abstract String getProperty(String key) throws Exception;
+ /* (no Javadoc)
+ * @see org.apache.felix.jmood.modules.configadmin.ConfigurationDelegateMXBean#setProperty(java.lang.String, java.lang.String)
+ */
+ public abstract void setProperty(String key, String value, String type)
+ throws Exception;
+ public abstract void deleteProperty(String key) throws Exception;
+}
\ No newline at end of file
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManager.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManager.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManager.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManager.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,227 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood.compendium;
+
+import java.util.*;
+import javax.management.*;
+import javax.management.openmbean.*;
+
+import org.apache.felix.jmood.AgentConstants;
+import org.apache.felix.jmood.AgentContext;
+import org.apache.felix.jmood.utils.*;
+import org.osgi.framework.*;
+import org.osgi.service.log.*;
+
+
+/**
+ *
+ * This class enables remote management of
+ * org.osgi.service.log.LogReaderService It enables the operator to read
+ * the system log.
+ */
+// FUTURE WORK: limitations of Log manager: if the service appears or
+// disappears, and/or there ismore than one service available, correct
+// functioning is not guaranteed. A New manager should be branched for each
+// available log service, and info should be merged to expose it afterwards.
+// FUTURE WORK: Log Listener should be an anonymous class
+// FUTURE WORK: Add persistence to the log manager
+public class LogManager extends NotificationBroadcasterSupport implements
+ LogListener, MBeanRegistration, LogManagerMBean {
+ private LogReaderService logReader = null;
+
+ private ServiceReference[] refs;
+
+ private LogService log = null;
+
+ private String[][] Log;
+
+ private static final int DefaultLogLevel = 0;
+
+ private int LogLevel;
+
+ private Vector entryVector;
+
+ private static int sequenceNumber = 0;
+
+ private AgentContext ac;
+
+ private ServiceRegistration registration;
+
+ // FUTURE WORK: add persistence to sequence numbers
+ public LogManager(AgentContext ac) {
+ this.ac = ac;
+ }
+
+ public void setLogLevel(int level) {
+ // FUTURE WORK This setting only affects to the agent. Extend it to the
+ // service. This is implementation dependent.
+ this.LogLevel = level;
+ }
+
+ public int getLogLevel() {
+ return LogLevel;
+ }
+
+ public CompositeData[] getLog() {
+ if (entryVector == null) {
+ return null;
+ } else {
+ try {
+
+ CompositeData[] value = new CompositeData[entryVector.size()];
+ for (int i = 0; i < entryVector.size(); i++) {
+ value[i] = OSGi2JMXCodec
+ .encodeLogEntry((LogEntry) entryVector.elementAt(i));
+ }
+ return value;
+ } catch (Exception e) {
+ ac.error("Unexpected exception", e);
+ return null;
+ }
+ }
+
+ }
+
+ /**
+ * This method exposes the attribute LogFromReader for remote management.
+ * The main difference with the log attribute is that the later uses the
+ * level configuration specified by the log level attribute and as a
+ * drawback does not include log entries registered before the log manager
+ * was started.
+ *
+ * @return
+ */
+ public String[] getLogMessages() {
+ if (entryVector == null)
+ return null;
+ String[] msgs = new String[entryVector.size()];
+ for (int i = 0; i < msgs.length; i++) {
+ LogEntry entry = (LogEntry) entryVector.elementAt(i);
+ msgs[i] = "BUNDLE " + entry.getBundle().getBundleId() + " ("
+ + entry.getBundle().getLocation() + "): LEVEL="
+ + this.getLevelAsString(entry.getLevel()) + "; MESSAGE="
+ + entry.getMessage();
+ }
+ return msgs;
+
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#postDeregister()
+ *
+ */
+ public void postDeregister() {
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
+ * @param registrationDone
+ */
+ public void postRegister(Boolean registrationDone) {
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#preDeregister()
+ * @throws java.lang.Exception
+ */
+ public void preDeregister() throws Exception {
+ registration.unregister();
+ }
+
+ /**
+ * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
+ * javax.management.ObjectName)
+ * @param server
+ * @param name
+ * @return
+ * @throws java.lang.Exception
+ */
+ public ObjectName preRegister(MBeanServer server, ObjectName name) {
+ this.entryVector = new Vector();
+ this.LogLevel = DefaultLogLevel;
+ registration=ac.getBundleContext().registerService(LogListener.class.getName(), this, null);
+ return name;
+ }
+
+ /**
+ * @see org.osgi.service.log.LogListener#logged(org.osgi.service.log.LogEntry)
+ * @param arg0
+ */
+ public void logged(LogEntry entry) {
+ if (entry.getLevel() >= this.LogLevel) {
+ this.notifyLogEntry(entry);
+ entryVector.add(entry);
+ }
+
+ }
+
+ private void notifyLogEntry(LogEntry entry) {
+ // TEST: See if user data are correctly received. This we cannot do with
+ // MC4J
+ String Level = this.getLevelAsString(entry.getLevel());
+ try {
+ ObjectName source = new ObjectName(ObjectNames.LOG_SERVICE);
+ String message = "Log entry added: Bundle "
+ + entry.getBundle().getLocation() + " with id "
+ + entry.getBundle().getBundleId()
+ + " has added a new log entry of level " + Level
+ + ". The message is: " + entry.getMessage();
+ Notification notification = new Notification(
+ AgentConstants.LOG_NOTIFICATION_TYPE, source,
+ sequenceNumber++, message);
+ // User data is CompositeData with the info of the log entry
+
+ CompositeData userData = OSGi2JMXCodec.encodeLogEntry(entry);
+
+ // Before using composite data, we used a simple string array:
+ /*
+ * String[] userData = new String[4]; userData[0] =
+ * entry.getBundle().getLocation(); userData[1] = new
+ * Long(entry.getBundle().getBundleId()).toString(); userData[2] =
+ * Level; userData[3] = entry.getMessage();
+ */
+
+ notification.setUserData(userData);
+ sendNotification(notification);
+ } catch (Exception e) {
+ ac.error("Unexpected exception", e);
+ }
+ }
+
+ private String getLevelAsString(int level) {
+ String Level;
+ switch (level) {
+ case LogService.LOG_DEBUG:
+ Level = "DEBUG";
+ break;
+ case LogService.LOG_WARNING:
+ Level = "WARNING";
+ break;
+ case LogService.LOG_INFO:
+ Level = "INFO";
+ break;
+ case LogService.LOG_ERROR:
+ Level = "ERROR";
+ break;
+ default:
+ Level = "UserDefined: " + level;
+ break;
+ }
+ return Level;
+
+ }
+}
Added: incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManagerMBean.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManagerMBean.java?rev=430562&view=auto
==============================================================================
--- incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManagerMBean.java (added)
+++ incubator/felix/sandbox/santillan/org.apache.felix.jmood/src/main/java/org/apache/felix/jmood/compendium/LogManagerMBean.java Thu Aug 10 15:15:58 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.jmood.compendium;
+
+import javax.management.openmbean.CompositeData;
+
+public interface LogManagerMBean {
+ //FUTURE WORK: add persistence to sequence numbers
+ public abstract void setLogLevel(int level) throws Exception;
+ public abstract int getLogLevel() throws Exception;
+ public abstract CompositeData[] getLog() throws Exception;
+ /**
+ * This method exposes the attribute LogFromReader for remote management. The main difference with the log attribute is that the later
+ * uses the level configuration specified by the log level attribute and as a drawback does not include log entries registered before the log manager was started.
+ * @return
+ */
+ public abstract String[] getLogMessages() throws Exception;
+}
\ No newline at end of file