karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ioca...@apache.org
Subject svn commit: r1164994 - in /karaf/cellar/trunk/dosgi: pom.xml src/main/java/org/apache/karaf/cellar/dosgi/shell/ src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml
Date Sun, 04 Sep 2011 11:18:37 GMT
Author: iocanel
Date: Sun Sep  4 11:18:36 2011
New Revision: 1164994

URL: http://svn.apache.org/viewvc?rev=1164994&view=rev
Log:
[KARAF-823] Added a shell command which lists the distributed services and the nodes that
export each service.

Added:
    karaf/cellar/trunk/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/
    karaf/cellar/trunk/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java
    karaf/cellar/trunk/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml
Modified:
    karaf/cellar/trunk/dosgi/pom.xml

Modified: karaf/cellar/trunk/dosgi/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/dosgi/pom.xml?rev=1164994&r1=1164993&r2=1164994&view=diff
==============================================================================
--- karaf/cellar/trunk/dosgi/pom.xml (original)
+++ karaf/cellar/trunk/dosgi/pom.xml Sun Sep  4 11:18:36 2011
@@ -33,6 +33,11 @@
         <osgi.import>
             !org.apache.karaf.cellar.dosgi*,
             org.apache.karaf.cellar.core*;version="${project.version}",
+            org.apache.felix.service.command,
+            org.apache.felix.gogo.commands,
+            org.apache.karaf.shell.console;version="[2.2,4)",
+            org.apache.karaf.shell.console.commands;version="[2.2,4)",
+            org.apache.karaf.shell.console.completer;version="[2.2,4)",
             *
         </osgi.import>
         <osgi.dynamic.import>javax.*,org.w3c.*,org.xml.*</osgi.dynamic.import>

Added: karaf/cellar/trunk/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java?rev=1164994&view=auto
==============================================================================
--- karaf/cellar/trunk/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java
(added)
+++ karaf/cellar/trunk/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/shell/ListDistributedServicesCommand.java
Sun Sep  4 11:18:36 2011
@@ -0,0 +1,42 @@
+package org.apache.karaf.cellar.dosgi.shell;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
+import org.apache.karaf.cellar.dosgi.Constants;
+import org.apache.karaf.cellar.dosgi.EndpointDescription;
+
+import java.util.Map;
+import java.util.Set;
+
+@Command(scope = "cluster", name = "list-distributed-services", description = "List the remote
services")
+public class ListDistributedServicesCommand extends CellarCommandSupport {
+
+    private static final String LIST_FORMAT = "%-80s %-20s";
+
+    @Override
+    protected Object doExecute() throws Exception {
+        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Map<String, EndpointDescription> remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS);
+            if (remoteEndpoints != null && !remoteEndpoints.isEmpty()) {
+                System.out.println(String.format(LIST_FORMAT, "Service Class", "Provider
Node"));
+                for (Map.Entry<String, EndpointDescription> entry : remoteEndpoints.entrySet())
{
+                    EndpointDescription endpointDescription = entry.getValue();
+                    String serviceClass = endpointDescription.getServiceClass();
+                    Set<String> nodes = endpointDescription.getNodes();
+                    for (String nodeId : nodes) {
+                        System.out.println(String.format(LIST_FORMAT, serviceClass, nodeId));
+                        serviceClass = "";
+                    }
+                }
+
+            } else {
+                System.out.println("There are no distributed services.");
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(originalClassLoader);
+        }
+        return null;
+    }
+}

Added: karaf/cellar/trunk/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml?rev=1164994&view=auto
==============================================================================
--- karaf/cellar/trunk/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml (added)
+++ karaf/cellar/trunk/dosgi/src/main/resources/OSGI-INF/blueprint/shell-dosgi.xml Sun Sep
 4 11:18:36 2011
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
+
+    <!-- Command Bundle -->
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+        <command name="cluster/list-distributed-services">
+            <action class="org.apache.karaf.cellar.dosgi.shell.ListDistributedServicesCommand">
+                <property name="clusterManager" ref="clusterManager"/>
+                <property name="eventTransportFactory" ref="eventTransportFactory"/>
+            </action>
+        </command>
+    </command-bundle>
+
+
+</blueprint>



Mime
View raw message