package net.lr.demo.chat.command;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.karaf.shell.table.ShellTable;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.EndpointListener;

@Component(//
    property = {
                "osgi.command.scope=rsa", //
                "osgi.command.function=endpoints",
                "endpoint.listener.scope=(endpoint.framework.uuid=*)"
                
    })
public class EndpointsCommand implements EndpointListener {
    Set<EndpointDescription> endpoints = new HashSet<>();

    public void endpoints() {
        ShellTable table = new ShellTable();
        table.column("id");
        table.column("interfaces");
        table.column("framework");
        table.column("comp name");
        System.out.println("Known Endpoints:");
        endpoints.stream().forEach((ep)->print(table, ep));
        table.print(System.out);
    }

    private void print(ShellTable table, EndpointDescription ep) {
        String compName = getProp(ep, "component.name");
        table.addRow().addContent(ep.getId(), ep.getInterfaces(), ep.getFrameworkUUID(), compName);
    }

    private String getProp(EndpointDescription ep, String key) {
        Object value = ep.getProperties().get(key);
        return value == null ? "" : value.toString();
    }

    @Override
    public void endpointAdded(EndpointDescription endpoint, String matchedFilter) {
        endpoints.add(endpoint);
    }

    @Override
    public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) {
        endpoints.remove(endpoint);
    }
    
}

@@ -49,16 +49,14 @@
 til.
-ArrayLis
+HashSe
 t;%0Ai
@@ -75,63 +75,103 @@
 til.
-Hash
 Set;%0A
+%0A
 import 
-java.util.List;%0Aimport java.util.Se
+org.apache.karaf.shell.table.ShellTable;%0Aimport org.osgi.framework.BundleContex
 t;%0A
-%0A
 impo
@@ -181,42 +181,87 @@
 org.
-apache.karaf.shell.table.ShellTabl
+osgi.framework.Constants;%0Aimport org.osgi.service.component.annotations.Activat
 e;%0Ai
@@ -785,38 +785,289 @@
 ();%0A
-%0A    public void endpoints() %7B
+    private String frameworkId;%0A    %0A    @Activate%0A    public void activate(BundleContext context) %7B%0A        this.frameworkId = context.getProperty(Constants.FRAMEWORK_UUID);%0A    %7D%0A%0A    public void endpoints() %7B%0A        System.out.println(%22Endpoints for framework %22 + frameworkId);
 %0A   

Add framework id