felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r696809 - in /felix/trunk/dependencymanager.shell: ./ 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/dependencymanager/ src/main/java/org/apache/feli...
Date Thu, 18 Sep 2008 21:18:04 GMT
Author: marrs
Date: Thu Sep 18 14:18:03 2008
New Revision: 696809

URL: http://svn.apache.org/viewvc?rev=696809&view=rev
Log:
Initial version of Felix shell command for querying the status of services managed by the
dependency manager.

Added:
    felix/trunk/dependencymanager.shell/
    felix/trunk/dependencymanager.shell/pom.xml
    felix/trunk/dependencymanager.shell/src/
    felix/trunk/dependencymanager.shell/src/main/
    felix/trunk/dependencymanager.shell/src/main/java/
    felix/trunk/dependencymanager.shell/src/main/java/org/
    felix/trunk/dependencymanager.shell/src/main/java/org/apache/
    felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/
    felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/
    felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/
    felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/Activator.java
    felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/DMCommand.java

Added: felix/trunk/dependencymanager.shell/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager.shell/pom.xml?rev=696809&view=auto
==============================================================================
--- felix/trunk/dependencymanager.shell/pom.xml (added)
+++ felix/trunk/dependencymanager.shell/pom.xml Thu Sep 18 14:18:03 2008
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>1.0.2</version>
+    <relativePath>../pom/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Apache Felix Dependency Manager Shell</name>
+  <version>1.1.0-SNAPSHOT</version>
+  <artifactId>org.apache.felix.dependencymanager.shell</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>1.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>1.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.shell</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>1.4.0</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.felix.dependencymanager.shell</Bundle-SymbolicName>
+            <Bundle-Activator>org.apache.felix.dependencymanager.shell.Activator</Bundle-Activator>
+            <Bundle-Name>Apache Felix Dependency Manager Shell</Bundle-Name>
+            <Bundle-Description>Shell commands for the dependency manager.</Bundle-Description>
+            <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/Activator.java?rev=696809&view=auto
==============================================================================
--- felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/Activator.java
(added)
+++ felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/Activator.java
Thu Sep 18 14:18:03 2008
@@ -0,0 +1,18 @@
+package org.apache.felix.dependencymanager.shell;
+
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator {
+    private ServiceRegistration m_serviceRegistration;
+
+    public void start(BundleContext context) throws Exception {
+        m_serviceRegistration = context.registerService(Command.class.getName(), new DMCommand(context),
null);
+    }
+
+    public void stop(BundleContext context) throws Exception {
+        m_serviceRegistration.unregister();
+    }
+}

Added: felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/DMCommand.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/DMCommand.java?rev=696809&view=auto
==============================================================================
--- felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/DMCommand.java
(added)
+++ felix/trunk/dependencymanager.shell/src/main/java/org/apache/felix/dependencymanager/shell/DMCommand.java
Thu Sep 18 14:18:03 2008
@@ -0,0 +1,74 @@
+package org.apache.felix.dependencymanager.shell;
+
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.apache.felix.dependencymanager.ServiceComponent;
+import org.apache.felix.dependencymanager.ServiceComponentDependency;
+import org.apache.felix.shell.Command;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class DMCommand implements Command {
+    private final BundleContext m_context;
+
+    public DMCommand(BundleContext context) {
+        m_context = context;
+    }
+
+    public void execute(String line, PrintStream out, PrintStream err) {
+        // lookup all dependency manager service components
+        try {
+            ServiceReference[] references = m_context.getServiceReferences(ServiceComponent.class.getName(),
null);
+            // show their state
+            if (references != null) {
+                Arrays.sort(references, new Comparator() {
+                    public int compare(Object o1, Object o2) {
+                        ServiceReference r1 = (ServiceReference) o1;
+                        ServiceReference r2 = (ServiceReference) o2;
+                        return (int) Math.signum(r1.getBundle().getBundleId() - r2.getBundle().getBundleId());
+                    }});
+                for (int i = 0; i < references.length; i++) {
+                    ServiceReference ref = references[i];
+                    ServiceComponent sc = (ServiceComponent) m_context.getService(ref);
+                    if (sc != null) {
+                        String name = sc.getName();
+                        int state = sc.getState();
+                        out.println("[" + ref.getBundle().getBundleId() + "] " + ref.getBundle().getSymbolicName()
+ " " + name + " " + ServiceComponent.STATE_NAMES[state]);
+                        if (line.indexOf("deps") != -1) {
+                            ServiceComponentDependency[] dependencies = sc.getComponentDependencies();
+                            if (dependencies != null) {
+                                for (int j = 0; j < dependencies.length; j++) {
+                                    ServiceComponentDependency dep = dependencies[j];
+                                    String depName = dep.getName();
+                                    String depType = dep.getType();
+                                    int depState = dep.getState();
+                                    out.println(" " + depName + " " + depType + " " + ServiceComponentDependency.STATE_NAMES[depState]);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        catch (InvalidSyntaxException e) {
+            // very weird since I'm not specifying a filter
+            e.printStackTrace(err);
+        }
+    }
+
+    public String getName() {
+        return "dm";
+    }
+
+    public String getShortDescription() {
+        return "list dependency manager component diagnostics.";
+    }
+
+    public String getUsage() {
+        return "dm [deps]";
+    }
+
+}



Mime
View raw message