Author: donsez
Date: Wed Jul 11 14:26:24 2007
New Revision: 555402

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

Added:
    felix/sandbox/donsez/monitor.sample.usagemonitor/
    felix/sandbox/donsez/monitor.sample.usagemonitor/doc/
    felix/sandbox/donsez/monitor.sample.usagemonitor/doc/readme.html   (with 
props)
    felix/sandbox/donsez/monitor.sample.usagemonitor/pom.xml   (with props)
    felix/sandbox/donsez/monitor.sample.usagemonitor/src/
    felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/
    felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/
    felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/
    felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/Activator.java
   (with props)
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/cpumonitor/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/cpumonitor/CPUUsageMonitor.java
   (with props)
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/osmemmonitor/
    
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/osmemmonitor/OSMemoryUsageMonitor.java
   (with props)

Added: felix/sandbox/donsez/monitor.sample.usagemonitor/doc/readme.html
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.usagemonitor/doc/readme.html?view=auto&rev=555402
==============================================================================
--- felix/sandbox/donsez/monitor.sample.usagemonitor/doc/readme.html (added)
+++ felix/sandbox/donsez/monitor.sample.usagemonitor/doc/readme.html Wed Jul 11 
14:26:24 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</title>
+</head>
+<body alink="#ff0000" vlink="#551a8b" link="#0000ee" bgcolor="#ffffff"
+ text="#000000">
+<h1><i>Usage 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).<br>
+It monitors memory and cpu of the underluying OS for Linux. 
+</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.usagemonitor/doc/readme.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/monitor.sample.usagemonitor/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.usagemonitor/pom.xml?view=auto&rev=555402
==============================================================================
--- felix/sandbox/donsez/monitor.sample.usagemonitor/pom.xml (added)
+++ felix/sandbox/donsez/monitor.sample.usagemonitor/pom.xml Wed Jul 11 
14:26:24 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 : OS Memory and CPU Monitors</name>
+  <artifactId>org.apache.felix.sandbox.monitor.sample.usagemonitor</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.sandbox.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>org.apache.felix.sandbox.monitor.sample.usagemonitor,org.apache.felix.sandbox.monitor.sample</Private-Package>
+            <Import-Package>*</Import-Package>
+            
+            
<Bundle-Activator>org.apache.felix.sandbox.monitor.sample.Activator</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.usagemonitor/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/Activator.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/Activator.java?view=auto&rev=555402
==============================================================================
--- 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/Activator.java
 (added)
+++ 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/Activator.java
 Wed Jul 11 14:26:24 2007
@@ -0,0 +1,63 @@
+/*
+ * 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.sandbox.monitor.sample;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.felix.sandbox.monitor.sample.cpumonitor.CPUUsageMonitor;
+import 
org.apache.felix.sandbox.monitor.sample.osmemmonitor.OSMemoryUsageMonitor;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * This class activates several monitorable
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class Activator implements BundleActivator {
+
+       
+       private List bundleActivators=new ArrayList();
+
+       public void start(BundleContext bundleContext) throws Exception {
+               
+               // TODO test if the operating system is Unix-based
+               
+               
+               BundleActivator bundleActivator;
+               
+               bundleActivator=new OSMemoryUsageMonitor();
+               bundleActivator.start(bundleContext);
+               bundleActivators.add(bundleActivator);
+
+               bundleActivator=new CPUUsageMonitor();
+               bundleActivator.start(bundleContext);
+               bundleActivators.add(bundleActivator);
+       }
+
+       public void stop(BundleContext bundleContext) throws Exception {
+               ListIterator listIterator=bundleActivators.listIterator();
+               while (listIterator.hasNext()) {
+                       BundleActivator bundleActivator=(BundleActivator) 
listIterator.next();
+                       listIterator.remove();
+                       bundleActivator.stop(bundleContext);                    
+               }
+       }
+}
\ No newline at end of file

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

Added: 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/cpumonitor/CPUUsageMonitor.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/cpumonitor/CPUUsageMonitor.java?view=auto&rev=555402
==============================================================================
--- 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/cpumonitor/CPUUsageMonitor.java
 (added)
+++ 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/cpumonitor/CPUUsageMonitor.java
 Wed Jul 11 14:26:24 2007
@@ -0,0 +1,152 @@
+/*
+ * 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.sandbox.monitor.sample.cpumonitor;
+
+import java.io.FileInputStream;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.monitor.Monitorable;
+import org.osgi.service.monitor.StatusVariable;
+
+/**
+ * This class provides a Monitorable (see chapter 119 MEG spec.) to monitor 
cpu of the underluying OS (only fot Linux).
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class CPUUsageMonitor implements BundleActivator, Monitorable {
+
+       private static final String SERVICE_PID = "os.linux.proc";
+
+       private static final String CPU_USED_VARIABLE_NAME = "cpu.used";
+
+       private static final String CPU_FREQUENCY_VARIABLE_NAME = 
"cpu.frequency";
+
+       private static final Map descriptions = new HashMap();
+
+       private ServiceRegistration serviceRegistration;
+       
+       public CPUUsageMonitor() {
+               descriptions.put(CPU_USED_VARIABLE_NAME,
+                               "current percentage of CPU used");
+               descriptions.put(CPU_FREQUENCY_VARIABLE_NAME,
+                               "processor frequency");
+
+       }
+
+       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 processor frequency and of it is 
used");
+               
serviceRegistration=context.registerService(Monitorable.class.getName(), this, 
properties);
+       }
+
+       public void stop(BundleContext context) throws Exception {
+               serviceRegistration.unregister();
+
+       }
+
+       public String[] getStatusVariableNames() {
+               return new String[] { CPU_USED_VARIABLE_NAME };
+       }
+
+       public StatusVariable getStatusVariable(String name)
+                       throws IllegalArgumentException {
+               if (CPU_USED_VARIABLE_NAME.equals(name)) {
+                       return new StatusVariable(name, 
StatusVariable.CM_GAUGE,0);
+                       //TODO
+                       
+               }
+               else if (CPU_FREQUENCY_VARIABLE_NAME.equals(name)) {
+               
+                       try {
+                               
+                               Pattern pat;
+                               Matcher mat;
+                               
+                               FileInputStream fis=new 
FileInputStream("/proc/cpuinfo");
+                                                                       
+                               byte[] buff=new byte[512];
+                               fis.read(buff);
+                               fis.close();
+                               
+                               String s=new String(buff);
+
+                               pat=Pattern.compile("cpu 
MHz\\s*:\\s*\\d+.\\d+");
+                               mat=pat.matcher(s);
+                               String res="";
+                               while(mat.find()) {
+                                       res=mat.group();                        
                        
+                               }
+                               
+                               double frequency=0;
+                               
+                               pat=Pattern.compile("\\d+");
+                               mat=pat.matcher(res);
+                               while(mat.find()) {
+                                       if(frequency==0)
+                                               
frequency+=(Double.valueOf(mat.group())).doubleValue();
+                                       else
+                                               
frequency+=(Double.valueOf(mat.group())).doubleValue()/1000;
+                               }
+                       
+                               return new StatusVariable(name, 
StatusVariable.CM_GAUGE,(int) frequency);
+                               
+                       } catch(Exception ex) {
+                               return new StatusVariable(name, 
StatusVariable.CM_GAUGE,0);
+                       }
+               }
+               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);
+       }
+}

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

Added: 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/osmemmonitor/OSMemoryUsageMonitor.java
URL: 
http://svn.apache.org/viewvc/felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/osmemmonitor/OSMemoryUsageMonitor.java?view=auto&rev=555402
==============================================================================
--- 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/osmemmonitor/OSMemoryUsageMonitor.java
 (added)
+++ 
felix/sandbox/donsez/monitor.sample.usagemonitor/src/main/java/org/apache/felix/sandbox/monitor/sample/osmemmonitor/OSMemoryUsageMonitor.java
 Wed Jul 11 14:26:24 2007
@@ -0,0 +1,158 @@
+/*
+ * 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.sandbox.monitor.sample.osmemmonitor;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.monitor.Monitorable;
+import org.osgi.service.monitor.StatusVariable;
+
+/**
+ * This class provides a Monitorable (see chapter 119 MEG spec.) to monitor 
memory of the underluying OS (only fot Linux).
+ * @author <a href="mailto:[EMAIL PROTECTED]">Felix Project Team</a>
+ */
+public class OSMemoryUsageMonitor implements BundleActivator, Monitorable {
+
+       private static final String SERVICE_PID="monitoradmin.os.linux";
+       
+       private static final String MEMORY_FREE_VARIABLE_NAME="memory.free";
+       private static final String MEMORY_TOTAL_VARIABLE_NAME="memory.total";
+
+       
+       private long memoryFree=-1;
+       private long memoryTotal=-1;
+       
+       private static final Map descriptions=new HashMap();
+       
+       private ServiceRegistration serviceRegistration;
+
+       public OSMemoryUsageMonitor(){
+               descriptions.put(MEMORY_FREE_VARIABLE_NAME,
+                       "current amount of free memory in the OS (in bytes)");
+               descriptions.put(MEMORY_TOTAL_VARIABLE_NAME,
+                       "current amount of total memory in the OS (in bytes)");
+       }
+       
+       private static final String badOSErrorMessage="This bundle could only 
run under Linux";
+       public void start(BundleContext context) throws Exception {
+               
if(!context.getProperty(Constants.FRAMEWORK_OS_NAME).equals("Linux")) {
+                       System.out.println(badOSErrorMessage);
+                       throw new Exception(badOSErrorMessage);
+               }
+               Dictionary properties = new Hashtable();
+               properties.put(Constants.SERVICE_PID, SERVICE_PID);
+               properties.put(Constants.SERVICE_DESCRIPTION, "monitor for free 
and total amounts of OS memory");
+               
serviceRegistration=context.registerService(Monitorable.class.getName(), this, 
properties);
+       }
+
+       public void stop(BundleContext context) throws Exception  {
+               serviceRegistration.unregister();
+       }
+
+       public String[] getStatusVariableNames() {
+               return new String[] { MEMORY_FREE_VARIABLE_NAME };
+       }
+
+
+       public StatusVariable getStatusVariable(String name)
+                       throws IllegalArgumentException {
+               refreshMemory();
+               if (MEMORY_FREE_VARIABLE_NAME.equals(name))
+                       return new StatusVariable(
+                                               name,
+                                               StatusVariable.CM_GAUGE,
+                                               memoryFree
+                                       );
+               else if (MEMORY_TOTAL_VARIABLE_NAME.equals(name))
+                       return new StatusVariable(
+                                               name,
+                                               StatusVariable.CM_GAUGE,
+                                               memoryTotal
+                                       );
+               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);
+       }
+
+
+       /**
+        * Refresh memory amounts
+        */
+       private void refreshMemory(){
+               StringTokenizer st;
+               long l=0;
+               try{
+                       FileReader meminfo=new FileReader("/proc/meminfo");
+                       BufferedReader buffer=new BufferedReader(meminfo);
+                       
+                       st=new StringTokenizer(buffer.readLine());
+                       st.nextToken();
+                       memoryTotal=Long.valueOf(st.nextToken()).longValue();
+
+                       st=new StringTokenizer(buffer.readLine());
+                       st.nextToken();
+                       memoryFree=Long.valueOf(st.nextToken()).longValue();
+
+                       buffer.close();
+                       meminfo.close();
+               }
+               catch(IOException e){
+                       System.out.println(e);
+               }
+       }
+}

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


Reply via email to