You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2007/07/08 22:44:08 UTC
svn commit: r554436 - in
/felix/sandbox/donsez/monitor.sample.memorymonitorjob: ./ doc/ 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/monitor/
src/main/java/org...
Author: donsez
Date: Sun Jul 8 13:44:07 2007
New Revision: 554436
URL: http://svn.apache.org/viewvc?view=rev&rev=554436
Log:
creation of the monitor.sample.memorymonitorjob bundle, a sample of a Monitor Job
Added:
felix/sandbox/donsez/monitor.sample.memorymonitorjob/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/readme.html (with props)
felix/sandbox/donsez/monitor.sample.memorymonitorjob/pom.xml (with props)
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/
felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/MemoryMonitorJob.java (with props)
Added: felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/readme.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/readme.html?view=auto&rev=554436
==============================================================================
--- felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/readme.html (added)
+++ felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/readme.html Sun Jul 8 13:44:07 2007
@@ -0,0 +1,56 @@
+<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type"
+ content="text/html; charset=iso-8859-1">
+ <title>Memory Monitor Job</title>
+</head>
+<body alink="#ff0000" vlink="#551a8b" link="#0000ee" bgcolor="#ffffff"
+ text="#000000">
+<h1><i>Memory Monitor Job</i></h1>
+
+<p><b>Description</b><br>
+This bundle provides a sample of a monitoring job (Chapter 119 Monitor Admin Service Specification Version 1.0)
+</p>
+</font>
+
+
+<p><b>Contributor(s)</b><br>
+Apache Felix Project Team
+</p>
+
+<p><b>License</b><br>
+ASL2
+</p>
+
+<p><b>Services</b><br>
+<ul>
+<li>org.osgi.service.event.EventHandler</li>
+</ul>
+</p>
+
+
+<p><b>Provisions</b><br>
+None
+</p>
+
+<p id="doc"><b>Documentation</b><br>
+<ul>
+<li><a href=".">general</a></li>
+<li><a href="api">JavaDoc</a></li>
+</ul>
+</p>
+
+
+<p id="todolist"><b>TODOLIST</b><br>
+TODO
+</p>
+
+<p id="link"><b>Links</b><br>
+<ul>
+</ul>
+</p>
+
+
+</body>
+</html>
Propchange: felix/sandbox/donsez/monitor.sample.memorymonitorjob/doc/readme.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/monitor.sample.memorymonitorjob/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.memorymonitorjob/pom.xml?view=auto&rev=554436
==============================================================================
--- felix/sandbox/donsez/monitor.sample.memorymonitorjob/pom.xml (added)
+++ felix/sandbox/donsez/monitor.sample.memorymonitorjob/pom.xml Sun Jul 8 13:44:07 2007
@@ -0,0 +1,108 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project>
+
+ <properties>
+ <repositoryLocation>http://www.apache.org/~donsez/dev/osgi/</repositoryLocation>
+ <description>provides a simple monitoring job.</description>
+ </properties>
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.9.0-incubator-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>Apache Felix Monitor Admin Sample : Memory Monitor Job</name>
+ <artifactId>org.apache.felix.monitor.sample.memorymonitorjob</artifactId>
+ <description>${description}</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.monitor</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
+ <!-- docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+
+ <Export-Service>
+ org.osgi.service.event.EventHandler
+ </Export-Service>
+
+ <Private-Package>${pom.artifactId}.*</Private-Package>
+ <Import-Package>*</Import-Package>
+
+ <Bundle-Activator>${pom.artifactId}.MemoryMonitorJob</Bundle-Activator>
+
+ <!--
+ <Bundle-DocURL>${repositoryLocation}${pom.artifactId}/index.html</Bundle-DocURL>
+ <Bundle-Url>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</Bundle-Url>
+ <Bundle-Source>${repositoryLocation}${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</Bundle-Source>
+ -->
+
+ <!--
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Description>${description}</Bundle-Description>
+ <Bundle-Vendor>Apache Software Foundation</Bundle-Vendor>
+ -->
+
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <!--
+ <repositories>
+ <repository>
+ <id>apache.m2.incubator</id>
+ <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>apache.m2.incubator</id>
+ <name>Apache M2 Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ </pluginRepository>
+ </pluginRepositories>
+ -->
+</project>
Propchange: felix/sandbox/donsez/monitor.sample.memorymonitorjob/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/MemoryMonitorJob.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/MemoryMonitorJob.java?view=auto&rev=554436
==============================================================================
--- felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/MemoryMonitorJob.java (added)
+++ felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/MemoryMonitorJob.java Sun Jul 8 13:44:07 2007
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.monitor.sample.memorymonitorjob;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+import org.osgi.service.monitor.MonitorAdmin;
+import org.osgi.service.monitor.MonitoringJob;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This example is inspired from the 119.4.4.1 Example Monitoring Job.
+ * For example, a bundle is interested in working with periodic samples of the
+ * com.acme.foo/memory.free Status Variable. It should therefore register an
+ * Event Handler with the correct topic and a filter on its Event Handler service.
+ * It then starts a monitoring job that is stopped in the BundleActivator
+ * stop method.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ *
+ */
+public class MemoryMonitorJob implements BundleActivator, EventHandler {
+
+ private static final String SERVICE_PID = "java.lang.runtime";
+
+ private static final String MEMORY_FREE_VARIABLE_NAME = "memory.free";
+ private static final String MEMORY_TOTAL_VARIABLE_NAME = "memory.total";
+
+ private MonitoringJob job;
+ private ServiceTracker serviceTracker;
+
+ /**
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+
+ String monListenerId="org.apache.felix.monitor.sample.memorymonitorjob#"+context.getBundle().getBundleId();
+
+ serviceTracker=new ServiceTracker(context,MonitorAdmin.class.getName(),null);
+ serviceTracker.open();
+
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.EVENT_TOPIC, new String[]{"org/osgi/service/monitor"});
+ properties.put(EventConstants.EVENT_FILTER,
+ "(mon.listener.id="+monListenerId+")");
+ context.registerService(EventHandler.class.getName(), this, properties);
+ MonitorAdmin monitorAdmin=(MonitorAdmin) serviceTracker.getService();
+ if(monitorAdmin==null)
+ throw new IllegalStateException("could not start if no MonitorAdmin service is available");
+
+ job = monitorAdmin.startScheduledJob(
+ monListenerId, // listener.id
+ new String[] {
+ SERVICE_PID + "/" + MEMORY_FREE_VARIABLE_NAME,
+ SERVICE_PID + "/" + MEMORY_TOTAL_VARIABLE_NAME
+ },
+ 20, // seconds
+ 0 // Forever
+ );
+ }
+
+ /**
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ job.stop();
+ serviceTracker.close();
+ }
+
+ /**
+ * @see org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)
+ */
+ public void handleEvent(Event event) {
+ String pid = (String) event.getProperty("mon.monitorable.pid");
+ String name = (String) event.getProperty("mon.statusvariable.name");
+ Object value = event.getProperty("mon.statusvariable.value");
+ System.out.println("StatusVariable "+pid+"/" + name + "=" + value);
+ }
+}
Propchange: felix/sandbox/donsez/monitor.sample.memorymonitorjob/src/main/java/org/apache/felix/monitor/sample/memorymonitorjob/MemoryMonitorJob.java
------------------------------------------------------------------------------
svn:eol-style = native