diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java index a2357f14596..6f631f44848 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.stream.Collectors; import org.eclipse.jetty.deploy.bindings.StandardDeployer; import org.eclipse.jetty.deploy.bindings.StandardStarter; @@ -289,13 +288,13 @@ public class DeploymentManager extends ContainerLifeCycle public Collection getAppEntries() { - return _apps; + return Collections.unmodifiableCollection(_apps); } @ManagedAttribute("Deployed Apps") public Collection getApps() { - List ret = new ArrayList(); + List ret = new ArrayList< >(); for (AppEntry entry : _apps) { ret.add(entry.app); @@ -594,38 +593,11 @@ public class DeploymentManager extends ContainerLifeCycle return _lifecycle.getNodes(); } - @SuppressWarnings("unused") - @ManagedOperation(value="list nodes that are tracked by DeploymentManager", impact="INFO") - public Collection getNodeNames() - { - return _lifecycle.getNodes().stream().map(Node::getName).collect(Collectors.toList()); - } - - public Collection getApps(@Name("nodeName") String nodeName) + public Collection getApps(String nodeName) { return getApps(_lifecycle.getNodeByName(nodeName)); } - @SuppressWarnings("unused") - @ManagedOperation(value="list apps that are located at specified App LifeCycle nodes", impact="ACTION") - public Collection getAppNames(@Name("nodeName") String nodeName) - { - Node node = _lifecycle.getNodeByName(nodeName); - if(node == null) - { - throw new IllegalArgumentException("Unable to find node [" + nodeName + "]"); - } - - List ret = new ArrayList<>(); - for (AppEntry entry : _apps) - { - if (entry.lifecyleNode == node) - { - ret.add(String.format("contextPath=%s,originId=%s,appProvider=%s", entry.app.getContextPath(), entry.app.getOriginId(), entry.app.getAppProvider().getClass().getName())); - } - } - return ret; - } public void scope(XmlConfiguration xmlc, Resource webapp) throws IOException diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java index 74753452ce5..6abc620b4f9 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/jmx/DeploymentManagerMBean.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.deploy.jmx; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; @@ -28,54 +29,77 @@ import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.jmx.ObjectMBean; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.annotation.ManagedObject; +import org.eclipse.jetty.util.annotation.ManagedOperation; +import org.eclipse.jetty.util.annotation.Name; +@SuppressWarnings("unused") +@ManagedObject("MBean Wrapper for DeploymentManager") public class DeploymentManagerMBean extends ObjectMBean { private final DeploymentManager _manager; - + public DeploymentManagerMBean(Object managedObject) { super(managedObject); - _manager=(DeploymentManager)managedObject; - } - - public Collection getNodes() - { - List nodes = new ArrayList(); - for (Node node: _manager.getNodes()) - nodes.add(node.getName()); - return nodes; + _manager = (DeploymentManager) managedObject; } + @ManagedOperation(value = "list apps being tracked", impact = "INFO") public Collection getApps() { - List apps=new ArrayList(); - for (App app: _manager.getApps()) - apps.add(app.getOriginId()); - return apps; + List ret = new ArrayList<>(); + for (DeploymentManager.AppEntry entry : _manager.getAppEntries()) + { + ret.add(toRef(entry.getApp())); + } + return ret; } - - public Collection getApps(String nodeName) + + @ManagedOperation(value = "list nodes that are tracked by DeploymentManager", impact = "INFO") + public Collection getNodes() { - List apps=new ArrayList(); - for (App app: _manager.getApps(nodeName)) - apps.add(app.getOriginId()); - return apps; + return _manager.getNodes().stream().map(Node::getName).collect(Collectors.toList()); } - + + @ManagedOperation(value = "list apps that are located at specified App LifeCycle nodes", impact = "ACTION") + public Collection getApps(@Name("nodeName") String nodeName) + { + Node node = _manager.getLifeCycle().getNodeByName(nodeName); + if (node == null) + { + throw new IllegalArgumentException("Unable to find node [" + nodeName + "]"); + } + + List ret = new ArrayList<>(); + for (DeploymentManager.AppEntry entry : _manager.getAppEntries()) + { + if (entry.getLifecyleNode() == node) + { + ret.add(toRef(entry.getApp())); + } + } + return ret; + } + + private String toRef(App app) + { + return String.format("originId=%s,contextPath=%s,appProvider=%s", app.getContextPath(), app.getOriginId(), app.getAppProvider().getClass().getName()); + } + public Collection getContexts() throws Exception { - List apps=new ArrayList(); - for (App app: _manager.getApps()) + List apps = new ArrayList(); + for (App app : _manager.getApps()) apps.add(app.getContextHandler()); return apps; } - + public Collection getAppProviders() { return _manager.getAppProviders(); } - + public void requestAppGoal(String appId, String nodeName) { _manager.requestAppGoal(appId, nodeName);