felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From don...@apache.org
Subject svn commit: r554435 - in /felix/sandbox/donsez/monitor.sample.memorymonitor: ./ 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/ap...
Date Sun, 08 Jul 2007 20:37:22 GMT
Author: donsez
Date: Sun Jul  8 13:37:21 2007
New Revision: 554435

URL: http://svn.apache.org/viewvc?view=rev&rev=554435
Log:
creation of the monitor.sample.memorymonitor bundle, a sample of a Monitorable service

Added:
    felix/sandbox/donsez/monitor.sample.memorymonitor/
    felix/sandbox/donsez/monitor.sample.memorymonitor/doc/
    felix/sandbox/donsez/monitor.sample.memorymonitor/doc/readme.html   (with props)
    felix/sandbox/donsez/monitor.sample.memorymonitor/pom.xml   (with props)
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/
    felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/MemoryMonitor.java
  (with props)

Added: felix/sandbox/donsez/monitor.sample.memorymonitor/doc/readme.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.memorymonitor/doc/readme.html?view=auto&rev=554435
==============================================================================
--- felix/sandbox/donsez/monitor.sample.memorymonitor/doc/readme.html (added)
+++ felix/sandbox/donsez/monitor.sample.memorymonitor/doc/readme.html Sun Jul  8 13:37:21
2007
@@ -0,0 +1,55 @@
+<!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</title>
+</head>
+<body alink="#ff0000" vlink="#551a8b" link="#0000ee" bgcolor="#ffffff"
+ text="#000000">
+<h1><i>Memory Monitor</i></h1>
+
+<p><b>Description</b><br>
+This bundle provides a sample of a Monitorable service (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.monitor.Monitorable</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.memorymonitor/doc/readme.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/monitor.sample.memorymonitor/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.memorymonitor/pom.xml?view=auto&rev=554435
==============================================================================
--- felix/sandbox/donsez/monitor.sample.memorymonitor/pom.xml (added)
+++ felix/sandbox/donsez/monitor.sample.memorymonitor/pom.xml Sun Jul  8 13:37:21 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 sample of Monitorable service.</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</name>
+  <artifactId>org.apache.felix.monitor.sample.memorymonitor</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.monitor.Monitorable
+            </Export-Service>
+
+            <Private-Package>${pom.artifactId}.*</Private-Package>
+            <Import-Package>*</Import-Package>
+            
+            <Bundle-Activator>${pom.artifactId}.MemoryMonitor</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.memorymonitor/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/MemoryMonitor.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/MemoryMonitor.java?view=auto&rev=554435
==============================================================================
--- felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/MemoryMonitor.java
(added)
+++ felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/MemoryMonitor.java
Sun Jul  8 13:37:21 2007
@@ -0,0 +1,126 @@
+/*
+ * 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.memorymonitor;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.monitor.Monitorable;
+import org.osgi.service.monitor.StatusVariable;
+
+/**
+ * This class is inspired for the example of the 119.2.2 Example Monitorable Implementation
+ * The following code shows how a bundle could provide a Status Variable
+ * that contains the current amount of memory.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ *
+ */
+public class MemoryMonitor implements BundleActivator, Monitorable {
+
+	private static final String SERVICE_PID="java.lang.runtime";
+	
+	private static final String MEMORY_FREE_VARIABLE_NAME="memory.free";
+	private static final String MEMORY_MAX_VARIABLE_NAME="memory.max";
+	private static final String MEMORY_TOTAL_VARIABLE_NAME="memory.total";
+
+	private static final Map descriptions=new HashMap();
+
+	public MemoryMonitor(){
+		descriptions.put(MEMORY_FREE_VARIABLE_NAME,
+			"current amount of free memory in the JVM (in bytes)");
+		descriptions.put(MEMORY_TOTAL_VARIABLE_NAME,
+			"current amount of total memory in the JVM (in bytes)");
+		descriptions.put(MEMORY_MAX_VARIABLE_NAME,
+			"current amount of max memory in the JVM (in bytes)");
+	}
+	
+	public void start(BundleContext context) throws Exception {
+		Dictionary properties = new Hashtable();
+		properties.put(Constants.SERVICE_PID, SERVICE_PID);
+		properties.put(Constants.SERVICE_DESCRIPTION, "monitor for free, total and max amounts
of JVM memory");
+		context.registerService(Monitorable.class.getName(), this, properties);
+	}
+
+	public void stop(BundleContext context) throws Exception  {
+		
+	}
+
+	public String[] getStatusVariableNames() {
+		return new String[] { MEMORY_FREE_VARIABLE_NAME };
+	}
+
+	// TODO add maxMemory and totalMemory
+	public StatusVariable getStatusVariable(String name)
+			throws IllegalArgumentException {
+		if (MEMORY_FREE_VARIABLE_NAME.equals(name))
+			return new StatusVariable(
+						name,
+						StatusVariable.CM_GAUGE,
+						(int)Runtime.getRuntime().freeMemory()
+					);
+		else if (MEMORY_TOTAL_VARIABLE_NAME.equals(name))
+			return new StatusVariable(
+						name,
+						StatusVariable.CM_GAUGE,
+						(int)Runtime.getRuntime().totalMemory()
+					);
+		else if (MEMORY_MAX_VARIABLE_NAME.equals(name))
+			return new StatusVariable(
+						name,
+						StatusVariable.CM_GAUGE,
+						(int)Runtime.getRuntime().maxMemory()
+					);
+		else
+			throw new IllegalArgumentException("Invalid Status Variable name "
+					+ name);
+	}
+
+	public boolean notifiesOnChange(String name)
+			throws IllegalArgumentException {
+		if(descriptions.get(name)!=null)
+			return false;
+		else
+			throw new IllegalArgumentException("Invalid Status Variable name "
+					+ name);
+
+	}
+
+	public boolean resetStatusVariable(String name)
+			throws IllegalArgumentException {
+		if(descriptions.get(name)!=null)
+			return false;
+		else
+			throw new IllegalArgumentException("Invalid Status Variable name "
+					+ name);
+	}
+
+	public String getDescription(String name) throws IllegalArgumentException {
+		String description=(String) descriptions.get(name);
+		if(description!=null)
+			return description;
+		else
+			throw new IllegalArgumentException("Invalid Status Variable name "
+					+ name);
+	}
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/monitor.sample.memorymonitor/src/main/java/org/apache/felix/monitor/sample/memorymonitor/MemoryMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message