From 5c3a1cfe8ce08f2629243ff07d2779246ccc177e Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 14 Aug 2012 16:52:17 -0500 Subject: [PATCH 1/7] removed the wrapper element from the ManagedObject annotation, rejiggered object mbean to not need wrapper, also smoking the convert concept in objectMbean in favor of dynamically discovering it where needed since its easy with annotations --- .../jetty/embedded/ManyServletContexts.java | 13 + .../eclipse/jetty/deploy/ContextDeployer.java | 468 ------------------ .../jetty/deploy/DeploymentManager.java | 15 +- .../eclipse/jetty/deploy/WebAppDeployer.java | 322 ------------ .../deploy/providers/ContextProvider.java | 2 + .../deploy/providers/ScanningAppProvider.java | 5 + .../deploy/providers/WebAppProvider.java | 9 + .../org/eclipse/jetty/jmx/ObjectMBean.java | 101 ++-- jetty-jmx/src/test/java/com/acme/Derived.java | 2 +- jetty-jmx/src/test/java/com/acme/Managed.java | 2 +- .../java/org/eclipse/jetty/server/Server.java | 2 +- .../jetty/util/annotation/ManagedObject.java | 2 - 12 files changed, 100 insertions(+), 843 deletions(-) delete mode 100644 jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ContextDeployer.java delete mode 100644 jetty-deploy/src/main/java/org/eclipse/jetty/deploy/WebAppDeployer.java diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java index 68874597a9c..c12a58bf4aa 100644 --- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java +++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/ManyServletContexts.java @@ -17,6 +17,9 @@ package org.eclipse.jetty.embedded; import java.lang.management.ManagementFactory; +import org.eclipse.jetty.deploy.DeploymentManager; +import org.eclipse.jetty.deploy.providers.ContextProvider; +import org.eclipse.jetty.deploy.providers.WebAppProvider; import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandlerCollection; @@ -48,6 +51,16 @@ public class ManyServletContexts other.addServlet(DefaultServlet.class.getCanonicalName(),"/"); other.addServlet(new ServletHolder(new HelloServlet("YO!")),"*.yo"); + DeploymentManager dm = new DeploymentManager(); + WebAppProvider wp = new WebAppProvider(); + dm.addAppProvider(wp); + ContextProvider cp = new ContextProvider(); + dm.addAppProvider(cp); + + server.addBean(dm); + server.addBean(wp); + server.addBean(cp); + server.start(); System.err.println(server.dump()); server.join(); diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ContextDeployer.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ContextDeployer.java deleted file mode 100644 index 4e0305142a9..00000000000 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/ContextDeployer.java +++ /dev/null @@ -1,468 +0,0 @@ -// ======================================================================== -// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== - -package org.eclipse.jetty.deploy; - -import java.io.File; -import java.io.FilenameFilter; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jetty.deploy.providers.ContextProvider; -import org.eclipse.jetty.deploy.providers.ScanningAppProvider; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.util.AttributesMap; -import org.eclipse.jetty.util.Scanner; -import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.xml.XmlConfiguration; - -/** - * Legacy Context Deployer. - * - *

- * Note: The WebAppDeployer is being phased out of Jetty in favor of the {@link DeploymentManager} and - * {@link org.eclipse.jetty.deploy.providers.ContextProvider} implementation. - * - *

- * This deployer scans a designated directory by {@link #setConfigurationDir(String)} for the appearance/disappearance - * or changes to xml configuration files. The scan is performed at startup and at an optional hot deployment frequency - * specified by {@link #setScanInterval(int)}. By default, the scanning is NOT recursive, but can be made so by - * {@link #setRecursive(boolean)}. - * - *

- * Each configuration file is in {@link XmlConfiguration} format and represents the configuration of a instance of - * {@link ContextHandler} (or a subclass specified by the XML Configure element). - * - *

- * The xml should configure the context and the instance is deployed to the {@link ContextHandlerCollection} specified - * by {@link Server#setHandler(org.eclipse.jetty.server.Handler)}. - * - *

- * Similarly, when one of these existing files is removed, the corresponding context is undeployed; when one of these - * files is changed, the corresponding context is undeployed, the (changed) xml config file reapplied to it, and then - * (re)deployed. - * - *

- * Note that the context itself is NOT copied into the hot deploy directory. The webapp directory or war file can exist - * anywhere. It is the xml config file that points to it's location and deploys it from there. - * - *

- * It means, for example, that you can keep a "read-only" copy of your webapp somewhere, and apply different - * configurations to it simply by dropping different xml configuration files into the configuration directory. - * - * @see DeploymentManager - * @see ScanningAppProvider - * - * @org.apache.xbean.XBean element="hotDeployer" description="Creates a hot deployer to watch a directory for changes at - * a configurable interval." - * @deprecated replaced with {@link ContextProvider} from the {@link DeploymentManager} - */ -@SuppressWarnings("unchecked") -@Deprecated -public class ContextDeployer extends AbstractLifeCycle -{ - private static final Logger LOG = Log.getLogger(ContextDeployer.class); - - private int _scanInterval=10; - private Scanner _scanner; - private ScannerListener _scannerListener; - private Resource _contextsDir; - private Map _currentDeployments = new HashMap(); - private ContextHandlerCollection _contexts; - private ConfigurationManager _configMgr; - private boolean _recursive = false; - private AttributesMap _contextAttributes = new AttributesMap(); - - - /* ------------------------------------------------------------ */ - protected class ScannerListener implements Scanner.DiscreteListener - { - /** - * Handle a new deployment - * - * @see org.eclipse.jetty.util.Scanner.DiscreteListener#fileAdded(java.lang.String) - */ - public void fileAdded(String filename) throws Exception - { - deploy(filename); - } - - /** - * Handle a change to an existing deployment. Undeploy then redeploy. - * - * @see org.eclipse.jetty.util.Scanner.DiscreteListener#fileChanged(java.lang.String) - */ - public void fileChanged(String filename) throws Exception - { - redeploy(filename); - } - - /** - * Handle an undeploy. - * - * @see org.eclipse.jetty.util.Scanner.DiscreteListener#fileRemoved(java.lang.String) - */ - public void fileRemoved(String filename) throws Exception - { - undeploy(filename); - } - @Override - public String toString() - { - return "ContextDeployer$Scanner"; - } - } - - /** - * Constructor - */ - public ContextDeployer() - { - LOG.warn("ContextDeployer is deprecated. Use ContextProvider"); - _scanner=new Scanner(); - } - - /* ------------------------------------------------------------ */ - /** - * @return the ContextHandlerColletion to which to deploy the contexts - */ - public ContextHandlerCollection getContexts() - { - return _contexts; - } - - /* ------------------------------------------------------------ */ - /** - * Associate with a {@link ContextHandlerCollection}. - * - * @param contexts - * the ContextHandlerColletion to which to deploy the contexts - */ - public void setContexts(ContextHandlerCollection contexts) - { - if (isStarted()||isStarting()) - throw new IllegalStateException("Cannot set Contexts after deployer start"); - _contexts=contexts; - } - - /* ------------------------------------------------------------ */ - /** - * @param seconds - * The period in second between scans for changed configuration - * files. A zero or negative interval disables hot deployment - */ - public void setScanInterval(int seconds) - { - if (isStarted()||isStarting()) - throw new IllegalStateException("Cannot change scan interval after deployer start"); - _scanInterval=seconds; - } - - /* ------------------------------------------------------------ */ - public int getScanInterval() - { - return _scanInterval; - } - - /* ------------------------------------------------------------ */ - /** - * @param dir Directory to scan for context descriptors - */ - public void setContextsDir(String dir) - { - try - { - _contextsDir=Resource.newResource(dir); - } - catch(Exception e) - { - throw new IllegalArgumentException(e); - } - } - - /* ------------------------------------------------------------ */ - public String getContextsDir() - { - return _contextsDir==null?null:_contextsDir.toString(); - } - - /* ------------------------------------------------------------ */ - /** - * @param dir - * @throws Exception - * @deprecated use {@link #setContextsDir(String)} - */ - @Deprecated - public void setConfigurationDir(String dir) throws Exception - { - setConfigurationDir(Resource.newResource(dir)); - } - - /* ------------------------------------------------------------ */ - /** - * @param file - * @throws Exception - * @deprecated use {@link #setContextsDir(String)} - */ - @Deprecated - public void setConfigurationDir(File file) throws Exception - { - setConfigurationDir(Resource.newResource(Resource.toURL(file))); - } - - /* ------------------------------------------------------------ */ - /** - * @param resource - * @deprecated use {@link #setContextsDir(String)} - */ - @Deprecated - public void setConfigurationDir(Resource resource) - { - if (isStarted()||isStarting()) - throw new IllegalStateException("Cannot change hot deploy dir after deployer start"); - _contextsDir=resource; - } - - /* ------------------------------------------------------------ */ - /** - * @param directory - * @deprecated use {@link #setContextsDir(String)} - */ - @Deprecated - public void setDirectory(String directory) throws Exception - { - setConfigurationDir(directory); - } - - /* ------------------------------------------------------------ */ - /** - * @return the directory - * @deprecated use {@link #setContextsDir(String)} - */ - @Deprecated - public String getDirectory() - { - return getConfigurationDir().getName(); - } - - /* ------------------------------------------------------------ */ - /** - * @return the configuration directory - * @deprecated use {@link #setContextsDir(String)} - */ - @Deprecated - public Resource getConfigurationDir() - { - return _contextsDir; - } - - /* ------------------------------------------------------------ */ - /** - * @param configMgr - */ - public void setConfigurationManager(ConfigurationManager configMgr) - { - _configMgr=configMgr; - } - - /* ------------------------------------------------------------ */ - /** - * @return the configuration manager - */ - public ConfigurationManager getConfigurationManager() - { - return _configMgr; - } - - - /* ------------------------------------------------------------ */ - public void setRecursive (boolean recursive) - { - _recursive=recursive; - } - - /* ------------------------------------------------------------ */ - public boolean getRecursive () - { - return _recursive; - } - - /* ------------------------------------------------------------ */ - public boolean isRecursive() - { - return _recursive; - } - - - /* ------------------------------------------------------------ */ - /** - * Set a contextAttribute that will be set for every Context deployed by this deployer. - * @param name - * @param value - */ - public void setAttribute (String name, Object value) - { - _contextAttributes.setAttribute(name,value); - } - - - /* ------------------------------------------------------------ */ - /** - * Get a contextAttribute that will be set for every Context deployed by this deployer. - * @param name - * @return the attribute value - */ - public Object getAttribute (String name) - { - return _contextAttributes.getAttribute(name); - } - - - /* ------------------------------------------------------------ */ - /** - * Remove a contextAttribute that will be set for every Context deployed by this deployer. - * @param name - */ - public void removeAttribute(String name) - { - _contextAttributes.removeAttribute(name); - } - - /* ------------------------------------------------------------ */ - private void deploy(String filename) throws Exception - { - ContextHandler context=createContext(filename); - LOG.info("Deploy "+filename+" -> "+ context); - _contexts.addHandler(context); - _currentDeployments.put(filename,context); - if (_contexts.isStarted()) - context.start(); - } - - /* ------------------------------------------------------------ */ - private void undeploy(String filename) throws Exception - { - ContextHandler context=(ContextHandler)_currentDeployments.get(filename); - LOG.info("Undeploy "+filename+" -> "+context); - if (context==null) - return; - context.stop(); - _contexts.removeHandler(context); - _currentDeployments.remove(filename); - } - - /* ------------------------------------------------------------ */ - private void redeploy(String filename) throws Exception - { - undeploy(filename); - deploy(filename); - } - - /* ------------------------------------------------------------ */ - /** - * Start the hot deployer looking for webapps to deploy/undeploy - * - * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() - */ - @SuppressWarnings("deprecation") - @Override - protected void doStart() throws Exception - { - if (_contextsDir==null) - throw new IllegalStateException("No configuration dir specified"); - - if (_contexts==null) - throw new IllegalStateException("No context handler collection specified for deployer"); - - _scanner.setScanDir(_contextsDir.getFile()); - _scanner.setScanInterval(getScanInterval()); - _scanner.setRecursive(_recursive); //only look in the top level for deployment files? - // Accept changes only in files that could be a deployment descriptor - _scanner.setFilenameFilter(new FilenameFilter() - { - public boolean accept(File dir, String name) - { - try - { - if (name.endsWith(".xml")) - return true; - return false; - } - catch (Exception e) - { - LOG.warn(e); - return false; - } - } - }); - _scannerListener=new ScannerListener(); - _scanner.addListener(_scannerListener); - _scanner.scan(); - _scanner.start(); - _contexts.getServer().getContainer().addBean(_scanner); - } - - /* ------------------------------------------------------------ */ - /** - * Stop the hot deployer. - * - * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop() - */ - @Override - protected void doStop() throws Exception - { - _scanner.removeListener(_scannerListener); - _scanner.stop(); - } - - /* ------------------------------------------------------------ */ - /** - * Create a WebAppContext for the webapp being hot deployed, then apply the - * xml config file to it to configure it. - * - * @param filename - * the config file found in the hot deploy directory - * @return - * @throws Exception - */ - private ContextHandler createContext(String filename) throws Exception - { - // The config file can call any method on WebAppContext to configure - // the webapp being deployed. - Resource resource = Resource.newResource(filename); - if (!resource.exists()) - return null; - - XmlConfiguration xmlConfiguration=new XmlConfiguration(resource.getURL()); - xmlConfiguration.getIdMap().put("Server", _contexts.getServer()); - if (_configMgr!=null) - xmlConfiguration.getProperties().putAll(_configMgr.getProperties()); - - ContextHandler context=(ContextHandler)xmlConfiguration.configure(); - - // merge attributes - if (_contextAttributes!=null && _contextAttributes.size()>0) - { - AttributesMap attributes = new AttributesMap(_contextAttributes); - attributes.addAll(context.getAttributes()); - context.setAttributes(attributes); - } - return context; - } - -} 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 afe06a80e1f..9e5b68f8c04 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 @@ -35,6 +35,10 @@ import org.eclipse.jetty.deploy.graph.Path; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.util.AttributesMap; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; +import org.eclipse.jetty.util.annotation.ManagedOperation; +import org.eclipse.jetty.util.annotation.Name; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -53,6 +57,7 @@ import org.eclipse.jetty.util.log.Logger; *

* */ +@ManagedObject("Deployment Manager") public class DeploymentManager extends AggregateLifeCycle { private static final Logger LOG = Log.getLogger(DeploymentManager.class); @@ -157,6 +162,7 @@ public class DeploymentManager extends AggregateLifeCycle addBean(provider); } + @ManagedAttribute("Application Providers") public Collection getAppProviders() { return Collections.unmodifiableList(_providers); @@ -279,6 +285,7 @@ public class DeploymentManager extends AggregateLifeCycle return _apps; } + @ManagedAttribute("Deployed Apps") public Collection getApps() { List ret = new ArrayList(); @@ -357,6 +364,7 @@ public class DeploymentManager extends AggregateLifeCycle return _contextAttributes; } + @ManagedAttribute("Deployed Contexts") public ContextHandlerCollection getContexts() { return _contexts; @@ -508,7 +516,8 @@ public class DeploymentManager extends AggregateLifeCycle * @param nodeName * the name of the node to attain */ - public void requestAppGoal(String appId, String nodeName) + @ManagedOperation(value="request the app to be moved to the specified lifecycle node", impact="ACTION") + public void requestAppGoal(@Name("appId") String appId, @Name("nodeName") String nodeName) { AppEntry appentry = findAppByOriginId(appId); if (appentry == null) @@ -576,12 +585,14 @@ public class DeploymentManager extends AggregateLifeCycle this._useStandardBindings = useStandardBindings; } + @ManagedAttribute("App LifeCycle Nodes") public Collection getNodes() { return _lifecycle.getNodes(); } - public Collection getApps(String nodeName) + @ManagedOperation(value="list apps that are located at specified App LifeCycle nodes", impact="ACTION") + public Collection getApps(@Name("nodeName") String nodeName) { return getApps(_lifecycle.getNodeByName(nodeName)); } diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/WebAppDeployer.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/WebAppDeployer.java deleted file mode 100644 index 6cbb2d6fc39..00000000000 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/WebAppDeployer.java +++ /dev/null @@ -1,322 +0,0 @@ -// ======================================================================== -// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== - -package org.eclipse.jetty.deploy; - -import java.util.ArrayList; - -import org.eclipse.jetty.deploy.providers.ScanningAppProvider; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.util.AttributesMap; -import org.eclipse.jetty.util.URIUtil; -import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.webapp.WebAppContext; - -/** - * Legacy Web Application Deployer. - * - *

- * Note: The WebAppDeployer is being phased out of Jetty in favor of the {@link DeploymentManager} and - * {@link org.eclipse.jetty.deploy.providers.WebAppProvider} implementation. - * - *

- * The class searches a directory for and deploys standard web application. At startup, the directory specified by - * {@link #setWebAppDir(String)} is searched for subdirectories (excluding hidden and CVS) or files ending with ".zip" - * or "*.war". For each webapp discovered is passed to a new instance of {@link WebAppContext} (or a subclass specified - * by {@link #getContexts()}. {@link ContextHandlerCollection#getContextClass()} - * - *

- * This deployer does not do hot deployment or undeployment. Nor does it support per web application configuration. For - * these features see {@link ContextDeployer}. - * - * @deprecated - * @see DeploymentManager - * @see ScanningAppProvider - * @see ContextDeployer - */ -@SuppressWarnings("unchecked") -public class WebAppDeployer extends AbstractLifeCycle -{ - private static final Logger LOG = Log.getLogger(WebAppDeployer.class); - - private HandlerCollection _contexts; - private String _webAppDir; - private String _defaultsDescriptor; - private String[] _configurationClasses; - private boolean _extract; - private boolean _parentLoaderPriority; - private boolean _allowDuplicates; - private ArrayList _deployed; - private AttributesMap _contextAttributes = new AttributesMap(); - - - public WebAppDeployer() - { - LOG.warn("WebAppDeployer is deprecated. Use WebAppProvider"); - } - - public String[] getConfigurationClasses() - { - return _configurationClasses; - } - - public void setConfigurationClasses(String[] configurationClasses) - { - _configurationClasses=configurationClasses; - } - - public HandlerCollection getContexts() - { - return _contexts; - } - - public void setContexts(HandlerCollection contexts) - { - _contexts=contexts; - } - - public String getDefaultsDescriptor() - { - return _defaultsDescriptor; - } - - public void setDefaultsDescriptor(String defaultsDescriptor) - { - _defaultsDescriptor=defaultsDescriptor; - } - - public boolean isExtract() - { - return _extract; - } - - public void setExtract(boolean extract) - { - _extract=extract; - } - - public boolean isParentLoaderPriority() - { - return _parentLoaderPriority; - } - - public void setParentLoaderPriority(boolean parentPriorityClassLoading) - { - _parentLoaderPriority=parentPriorityClassLoading; - } - - public String getWebAppDir() - { - return _webAppDir; - } - - public void setWebAppDir(String dir) - { - _webAppDir=dir; - } - - public boolean getAllowDuplicates() - { - return _allowDuplicates; - } - - /* ------------------------------------------------------------ */ - /** - * @param allowDuplicates If false, do not deploy webapps that have already been deployed or duplicate context path - */ - public void setAllowDuplicates(boolean allowDuplicates) - { - _allowDuplicates=allowDuplicates; - } - - - /** - * Set a contextAttribute that will be set for every Context deployed by this deployer. - * @param name - * @param value - */ - public void setAttribute (String name, Object value) - { - _contextAttributes.setAttribute(name,value); - } - - - /** - * Get a contextAttribute that will be set for every Context deployed by this deployer. - * @param name - * @return the attribute value - */ - public Object getAttribute (String name) - { - return _contextAttributes.getAttribute(name); - } - - - /** - * Remove a contextAttribute that will be set for every Context deployed by this deployer. - * @param name - */ - public void removeAttribute(String name) - { - _contextAttributes.removeAttribute(name); - } - - /* ------------------------------------------------------------ */ - /** - * @throws Exception - */ - @Override - public void doStart() throws Exception - { - _deployed=new ArrayList(); - - scan(); - - } - - /* ------------------------------------------------------------ */ - /** Scan for webapplications. - * - * @throws Exception - */ - public void scan() throws Exception - { - if (_contexts==null) - throw new IllegalArgumentException("No HandlerContainer"); - - Resource r=Resource.newResource(_webAppDir); - if (!r.exists()) - throw new IllegalArgumentException("No such webapps resource "+r); - - if (!r.isDirectory()) - throw new IllegalArgumentException("Not directory webapps resource "+r); - - String[] files=r.list(); - - files: for (int f=0; files!=null&&f0) - context=context.substring(0,context.length()-1); - - // Check the context path has not already been added or the webapp itself is not already deployed - if (!_allowDuplicates) - { - Handler[] installed=_contexts.getChildHandlersByClass(ContextHandler.class); - for (int i=0; i0;) - { - ContextHandler wac = (ContextHandler)_deployed.get(i); - wac.stop();// TODO Multi exception - } - } -} diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java index 2685b82fdcc..7ae9193ec23 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java @@ -19,6 +19,7 @@ import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.ConfigurationManager; import org.eclipse.jetty.deploy.util.FileID; import org.eclipse.jetty.server.handler.ContextHandler; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.xml.XmlConfiguration; @@ -27,6 +28,7 @@ import org.eclipse.jetty.xml.XmlConfiguration; * replacement for the old (and deprecated) org.eclipse.jetty.deploy.ContextDeployer and it will scan a directory * only for context.xml files. */ +@ManagedObject("Provider for starting webapps originating from context.xml files") public class ContextProvider extends ScanningAppProvider { private ConfigurationManager _configurationManager; diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java index 8bf03f30a12..d59ab145610 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java @@ -25,6 +25,8 @@ import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; import org.eclipse.jetty.deploy.DeploymentManager; import org.eclipse.jetty.util.Scanner; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -32,6 +34,7 @@ import org.eclipse.jetty.util.resource.Resource; /** */ +@ManagedObject("Abstract Provider for loading webapps") public abstract class ScanningAppProvider extends AbstractLifeCycle implements AppProvider { private static final Logger LOG = Log.getLogger(ScanningAppProvider.class); @@ -196,12 +199,14 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A } /* ------------------------------------------------------------ */ + @ManagedAttribute("scanning interval to detect changes which need reloaded") public int getScanInterval() { return _scanInterval; } /* ------------------------------------------------------------ */ + @ManagedAttribute("recursive scanning supported") public boolean isRecursive() { return _recursive; diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java index 557edc0de94..62e7e33be4b 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/WebAppProvider.java @@ -21,6 +21,8 @@ import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.util.FileID; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.URIUtil; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.WebAppContext; @@ -34,6 +36,7 @@ import org.eclipse.jetty.webapp.WebAppContext; * If the name is in the format root-hostname, then the webapp is deployed * at / in the virtual host hostname. */ +@ManagedObject("Provider for start-up deployement of webapps based on presence in directory") public class WebAppProvider extends ScanningAppProvider { private boolean _extractWars = false; @@ -110,6 +113,7 @@ public class WebAppProvider extends ScanningAppProvider /** Get the extractWars. * @return the extractWars */ + @ManagedAttribute("extract war files") public boolean isExtractWars() { return _extractWars; @@ -128,6 +132,7 @@ public class WebAppProvider extends ScanningAppProvider /** Get the parentLoaderPriority. * @return the parentLoaderPriority */ + @ManagedAttribute("parent classloader has priority") public boolean isParentLoaderPriority() { return _parentLoaderPriority; @@ -146,6 +151,7 @@ public class WebAppProvider extends ScanningAppProvider /** Get the defaultsDescriptor. * @return the defaultsDescriptor */ + @ManagedAttribute("default descriptor for webapps") public String getDefaultsDescriptor() { return _defaultsDescriptor; @@ -161,6 +167,7 @@ public class WebAppProvider extends ScanningAppProvider } /* ------------------------------------------------------------ */ + @ManagedAttribute("directory to scan for context.xml files") public String getContextXmlDir() { return _filter._contexts==null?null:_filter._contexts.toString(); @@ -207,6 +214,7 @@ public class WebAppProvider extends ScanningAppProvider /** * */ + @ManagedAttribute("configuration classes for webapps to be processed through") public String[] getConfigurationClasses() { return _configurationClasses; @@ -229,6 +237,7 @@ public class WebAppProvider extends ScanningAppProvider * * @return the user supplied work directory (null if user has not set Temp Directory yet) */ + @ManagedAttribute("temp directory for use, null if no user set temp directory") public File getTempDir() { return _tempDirectory; diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java index b1a1e66e896..75caffc8653 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java @@ -43,7 +43,6 @@ import javax.management.MBeanParameterInfo; import javax.management.ObjectName; import javax.management.ReflectionException; import javax.management.modelmbean.ModelMBean; -import javax.xml.crypto.dsig.keyinfo.RetrievalMethod; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.TypeUtil; @@ -117,15 +116,12 @@ public class ObjectMBean implements DynamicMBean Class oClass = o.getClass(); Object mbean = null; - while (mbean == null && oClass != null) + while ( mbean == null && oClass != null ) { - ManagedObject mo = oClass.getAnnotation(ManagedObject.class); - String mName = ""; - if ( mo != null ) - { - mName = mo.wrapper(); - } - + String pName = oClass.getPackage().getName(); + String cName = oClass.getName().substring(pName.length() + 1); + String mName = pName + ".jmx." + cName + "MBean"; + try { Class mClass = (Object.class.equals(oClass))?oClass=ObjectMBean.class:Loader.loadClass(oClass,mName,true); @@ -180,6 +176,7 @@ public class ObjectMBean implements DynamicMBean { LOG.ignore(e); } + return null; } @@ -258,7 +255,7 @@ public class ObjectMBean implements DynamicMBean { Class oClass = influences.get(i); - ManagedObject typeAnnotation = oClass.getAnnotation( ManagedObject.class); + ManagedObject typeAnnotation = oClass.getAnnotation( ManagedObject.class ); LOG.debug("Influenced by: " + oClass.getCanonicalName() ); if ( typeAnnotation == null ) @@ -335,34 +332,51 @@ public class ObjectMBean implements DynamicMBean // get the attribute Object r=getter.invoke(o, (java.lang.Object[]) null); - // convert to ObjectName if need be. - if (r!=null && _convert.contains(name)) - { + // convert to ObjectName if the type has the @ManagedObject annotation + if (r!=null ) + { if (r.getClass().isArray()) { - ObjectName[] on = new ObjectName[Array.getLength(r)]; - for (int i=0;i) { @SuppressWarnings("unchecked") Collection c = (Collection)r; - ObjectName[] on = new ObjectName[c.size()]; - int i=0; - for (Object obj :c) - on[i++]=_mbeanContainer.findMBean(obj); - r=on; + + if (!c.isEmpty() && c.iterator().next().getClass().isAnnotationPresent(ManagedObject.class)) + { + // check the first thing out + + ObjectName[] on = new ObjectName[c.size()]; + int i = 0; + for (Object obj : c) + { + on[i++] = _mbeanContainer.findMBean(obj); + } + r = on; + } } else { - ObjectName mbean = _mbeanContainer.findMBean(r); - - if (mbean==null) - return null; - r=mbean; + if ( r.getClass().isAnnotationPresent(ManagedObject.class)) + { + ObjectName mbean = _mbeanContainer.findMBean(r); + + if (mbean == null) + return null; + r = mbean; + } } + } return r; @@ -525,24 +539,19 @@ public class ObjectMBean implements DynamicMBean // This class is an influence influences.add(aClass); - // check for mbean influence - ManagedObject mo = aClass.getAnnotation(ManagedObject.class); + String pName = aClass.getPackage().getName(); + String cName = aClass.getName().substring(pName.length() + 1); + String mName = pName + ".jmx." + cName + "MBean"; - if ( mo != null && !"".equals(mo.wrapper())) + try { - String clazz = mo.wrapper(); - - try - { - Class mbean = Class.forName(clazz); - - LOG.debug("MBean Influence found for " + aClass.getSimpleName() ); - influences.add(mbean); - } - catch ( ClassNotFoundException cnfe ) - { - LOG.debug("No MBean Influence for " + aClass.getSimpleName() ); - } + Class mbeanClazz = Class.forName(mName); + LOG.debug("MBean Influence found for " + aClass.getSimpleName()); + influences.add(mbeanClazz); + } + catch (ClassNotFoundException cnfe) + { + LOG.debug("No MBean Influence for " + aClass.getSimpleName()); } // So are the super classes @@ -751,6 +760,7 @@ public class ObjectMBean implements DynamicMBean if ( returnType.isArray() ) { + LOG.debug("returnType is array, get component type"); returnType = returnType.getComponentType(); } @@ -758,7 +768,7 @@ public class ObjectMBean implements DynamicMBean { convert = true; } - + String impactName = methodAnnotation.impact(); @@ -833,8 +843,7 @@ public class ObjectMBean implements DynamicMBean throw new IllegalArgumentException(e.toString()); } - } - + } protected String toVariableName( String methodName ) { diff --git a/jetty-jmx/src/test/java/com/acme/Derived.java b/jetty-jmx/src/test/java/com/acme/Derived.java index 06266370796..e4ccf6a3e1b 100644 --- a/jetty-jmx/src/test/java/com/acme/Derived.java +++ b/jetty-jmx/src/test/java/com/acme/Derived.java @@ -18,7 +18,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.annotation.Name; -@ManagedObject(value="Test the mbean stuff", wrapper="com.acme.jmx.DerivedMBean") +@ManagedObject(value="Test the mbean stuff") public class Derived extends Base implements Signature { String fname="Full Name"; diff --git a/jetty-jmx/src/test/java/com/acme/Managed.java b/jetty-jmx/src/test/java/com/acme/Managed.java index e79ad5a3462..6d01ca9a345 100644 --- a/jetty-jmx/src/test/java/com/acme/Managed.java +++ b/jetty-jmx/src/test/java/com/acme/Managed.java @@ -3,7 +3,7 @@ package com.acme; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; -@ManagedObject(value="Managed Object", wrapper="com.acme.jmx.ManagedMBean") +@ManagedObject(value="Managed Object") public class Managed { String managed = "foo"; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 896ceba4230..f79159c4904 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -52,7 +52,7 @@ import org.eclipse.jetty.util.thread.ThreadPool; * The server is itself a handler and a ThreadPool. Connectors use the ThreadPool methods * to run jobs that will eventually call the handle method. */ -@ManagedObject(value="Jetty HTTP Servlet server", wrapper="org.eclipse.jetty.server.ServerMBean") +@ManagedObject(value="Jetty HTTP Servlet server") public class Server extends HandlerWrapper implements Attributes { private static final Logger LOG = Log.getLogger(Server.class); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedObject.java b/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedObject.java index 56cecadddba..aa654733c55 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedObject.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedObject.java @@ -29,6 +29,4 @@ public @interface ManagedObject * @return */ String value() default "Not Specified"; - - String wrapper() default ""; } From f2a2120ffef815f0fc00d261579c9a476a540b3b Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 14 Aug 2012 17:03:56 -0500 Subject: [PATCH 2/7] add jetty logging to jetty-deploy --- jetty-deploy/src/test/resources/jetty-logging.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 jetty-deploy/src/test/resources/jetty-logging.properties diff --git a/jetty-deploy/src/test/resources/jetty-logging.properties b/jetty-deploy/src/test/resources/jetty-logging.properties new file mode 100644 index 00000000000..9bad879708f --- /dev/null +++ b/jetty-deploy/src/test/resources/jetty-logging.properties @@ -0,0 +1,3 @@ +org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +org.eclipse.jetty.deploy.LEVEL=WARN + From 4de94e00d57edb38594130b2643f4b6d135ddeda Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 14 Aug 2012 17:14:40 -0500 Subject: [PATCH 3/7] the old context and webapp deployer were smoked and removing the node attribute from the deployment manager since the Node's are not jmx objects themselves and are not converted --- .../main/java/org/eclipse/jetty/deploy/DeploymentManager.java | 1 - .../org/eclipse/jetty/util/annotation/ManagedOperation.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 9e5b68f8c04..a968be928cc 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 @@ -585,7 +585,6 @@ public class DeploymentManager extends AggregateLifeCycle this._useStandardBindings = useStandardBindings; } - @ManagedAttribute("App LifeCycle Nodes") public Collection getNodes() { return _lifecycle.getNodes(); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedOperation.java b/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedOperation.java index 0b0543c17f4..0a45a14ecd5 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedOperation.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/ManagedOperation.java @@ -28,7 +28,7 @@ public @interface ManagedOperation * * @return */ - String value() default "Not Specified"; + String value() default "Not Specified"; /** * The impact of an operation. From 80608f386c08b142535b9ee7d4658aec2163d14c Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 14 Aug 2012 17:26:55 -0500 Subject: [PATCH 4/7] remove old mbean files --- .../deploy/jmx/ContextDeployer-mbean.properties | 9 --------- .../deploy/jmx/DeploymentManager-mbean.properties | 10 ---------- .../deploy/jmx/WebAppDeployer-mbean.properties | 14 -------------- .../providers/jmx/ContextProvider-mbean.properties | 1 - .../jmx/ScanningAppProvider-mbean.properties | 4 ---- .../providers/jmx/WebAppProvider-mbean.properties | 7 ------- 6 files changed, 45 deletions(-) delete mode 100644 jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/ContextDeployer-mbean.properties delete mode 100644 jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties delete mode 100644 jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties delete mode 100644 jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ContextProvider-mbean.properties delete mode 100644 jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ScanningAppProvider-mbean.properties delete mode 100644 jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/WebAppProvider-mbean.properties diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/ContextDeployer-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/ContextDeployer-mbean.properties deleted file mode 100644 index 335a5ee661b..00000000000 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/ContextDeployer-mbean.properties +++ /dev/null @@ -1,9 +0,0 @@ -ContextDeployer: Deployer for runtime deploy/undeploy of webapps -contexts: MObject: The ContextHandlerCollection to which the deployer deploys -scanInterval: Object: The interval in seconds between scans of the deploy directory -configurationDir: Object:RO: The deploy directory -setConfigurationDir(java.lang.String):ACTION:Set the deploy directory -setConfigurationDir(java.lang.String)[0]:dir:The directory -setConfigurationDir(java.io.File):ACTION:Set the deploy directory -setConfigurationDir(java.io.File)[0]:file:The directory -configurationManager: MObject:Source of property values for property name resolution in deployed config file diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties deleted file mode 100644 index f640c90a57c..00000000000 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties +++ /dev/null @@ -1,10 +0,0 @@ -DeploymentManager: Deployment Manager -nodes:MBean: App LifeCycle Nodes -apps:MBean: Deployed Apps -contexts:MMBean: Deployed Contexts -appProviders:MMBean: Application Providers -getApps(java.lang.String):MBean:ACTION: List apps that are located at specified App LifeCycle node -getApps(java.lang.String)[0]:nodeName: Name of the App LifeCycle node -requestAppGoal(java.lang.String,java.lang.String):ACTION: Request the app to be moved to the specified App LifeCycle node -requestAppGoal(java.lang.String,java.lang.String)[0]:appId:App identifier -requestAppGoal(java.lang.String,java.lang.String)[1]:nodeName:Name of the App LifeCycle node diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties deleted file mode 100644 index 2815ae6ee40..00000000000 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/WebAppDeployer-mbean.properties +++ /dev/null @@ -1,14 +0,0 @@ -WebAppDeployer: Deployer for startup deployment of webapps -contexts: MObject: The ContextHandlerCollection to which the deployer deploys -allowDuplicates: Object:RO: Whether or not duplicate deployments are allowed -setAllowDuplicates(boolean):ACTION: Whether or not duplicate deployments are allowed -setAllowDuplicates(boolean)[0]:allowDuplicates: True allows duplicate webapps to be deployed while false does not -defaultsDescriptor: Object: The webdefault.xml descriptor to use for all webapps deployed by the deployer -configurationClasses: Object: The set of configuration classes to apply to the deployment of each webapp -webAppDir: Object: The directory where the webapps are to be found to deploy -extract: Object:RO: Whether or not to extract war files on deployment -setExtract(boolean):ACTION:Set whether or not to extract war files -setExtract(boolean)[0]:extract: True will extract war files while false will not -parentLoaderPriority: Object:RO: Whether to use j2se classloading order or servlet spec classloading order -setParentLoaderPriority(boolean):ACTION: Set which classloading paradigm to use -setParentLoaderPriority(boolean)[0]:parentPriorityClassLoading: True uses j2se classloading order while false uses servlet spec order diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ContextProvider-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ContextProvider-mbean.properties deleted file mode 100644 index 3b3cc056fa7..00000000000 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ContextProvider-mbean.properties +++ /dev/null @@ -1 +0,0 @@ -ContextProvider: Context AppProvider for Deployment manager \ No newline at end of file diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ScanningAppProvider-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ScanningAppProvider-mbean.properties deleted file mode 100644 index ecd15b31c85..00000000000 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/ScanningAppProvider-mbean.properties +++ /dev/null @@ -1,4 +0,0 @@ -ScanningAppProvider: Scanning AppProvider for Deployment manager -monitoredDirName: The directory to monitor for new Apps -scanInterval: The scan interval in seconds -recursive: Look in subdirectories diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/WebAppProvider-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/WebAppProvider-mbean.properties deleted file mode 100644 index f47065e7bf9..00000000000 --- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/providers/jmx/WebAppProvider-mbean.properties +++ /dev/null @@ -1,7 +0,0 @@ -WebAppProvider: Web application AppProvider for Deployment manager -extractWars: Extract WAR files to temporary directory -parentLoaderPriority: ClassLoaders give priority to classes from parent loader -defaultsDescriptor: The default descriptor applied before any web.xml -contextXmlDir: The directory of context.xml files -configurationClasses: The configuration classes to apply -tempDir: The temporary directory to use \ No newline at end of file From 1357c342d8ecb540eec50c5a72be0d4c6bfaf714 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 14 Aug 2012 17:29:32 -0500 Subject: [PATCH 5/7] fix logging bits --- .../main/java/org/eclipse/jetty/jmx/ObjectMBean.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java index 75caffc8653..c2e35ee2765 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java @@ -634,7 +634,7 @@ public class ObjectMBean implements DynamicMBean { String declaredSetter = attributeAnnotation.setter(); - LOG.debug("DeclaredSetter:" + declaredSetter); + LOG.debug("DeclaredSetter: {}", declaredSetter); Method[] methods = oClass.getMethods(); for (int m = 0; m < methods.length; m++) { @@ -649,13 +649,13 @@ public class ObjectMBean implements DynamicMBean { if (setter != null) { - LOG.warn("Multiple setters for mbean attr " + name + " in " + oClass); + LOG.warn("Multiple setters for mbean attr {} in {}", name, oClass); continue; } setter = methods[m]; if ( !type.equals(methods[m].getParameterTypes()[0])) { - LOG.warn("Type conflict for mbean attr " + name + " in " + oClass); + LOG.warn("Type conflict for mbean attr {} in {}", name, oClass); continue; } LOG.debug("Declared Setter: " + declaredSetter); @@ -667,13 +667,13 @@ public class ObjectMBean implements DynamicMBean { if (setter != null) { - LOG.warn("Multiple setters for mbean attr " + name + " in " + oClass); + LOG.warn("Multiple setters for mbean attr {} in {}", name, oClass); continue; } setter = methods[m]; if ( !type.equals(methods[m].getParameterTypes()[0])) { - LOG.warn("Type conflict for mbean attr " + name + " in " + oClass); + LOG.warn("Type conflict for mbean attr {} in {}", name, oClass); continue; } } @@ -772,7 +772,7 @@ public class ObjectMBean implements DynamicMBean String impactName = methodAnnotation.impact(); - LOG.debug("defineOperation "+method.getName()+" "+onMBean+":"+impactName+":"+description); + LOG.debug("defineOperation {} {}:{}:{}", method.getName(), onMBean, impactName, description); String signature = method.getName(); From b7407000cb2d399551e96c4c99f36f533fe3e8ff Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 14 Aug 2012 17:30:28 -0500 Subject: [PATCH 6/7] fix logging bits --- .../src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java index c2e35ee2765..dc64958ac8b 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/ObjectMBean.java @@ -235,7 +235,7 @@ public class ObjectMBean implements DynamicMBean Class o_class=_managed.getClass(); List> influences = findInfluences(new ArrayList>(), _managed.getClass()); - LOG.debug("Influence Count: " + influences.size() ); + LOG.debug("Influence Count: {}", influences.size() ); // Process Type Annotations ManagedObject primary = o_class.getAnnotation( ManagedObject.class); @@ -260,7 +260,7 @@ public class ObjectMBean implements DynamicMBean LOG.debug("Influenced by: " + oClass.getCanonicalName() ); if ( typeAnnotation == null ) { - LOG.debug("Annotations not found for: " + oClass.getCanonicalName() ); + LOG.debug("Annotations not found for: {}", oClass.getCanonicalName() ); continue; } @@ -273,7 +273,7 @@ public class ObjectMBean implements DynamicMBean if (methodAttributeAnnotation != null) { // TODO sort out how a proper name could get here, its a method name as an attribute at this point. - LOG.debug("Attribute Annotation found for: " + method.getName()); + LOG.debug("Attribute Annotation found for: {}", method.getName()); MBeanAttributeInfo mai = defineAttribute(method,methodAttributeAnnotation); if ( mai != null ) { @@ -285,7 +285,7 @@ public class ObjectMBean implements DynamicMBean if (methodOperationAnnotation != null) { - LOG.debug("Method Annotation found for: " + method.getName()); + LOG.debug("Method Annotation found for: {}", method.getName()); MBeanOperationInfo oi = defineOperation(method,methodOperationAnnotation); if (oi != null) From a06d5e96b6ee039b54c52294023e6f8793859c7e Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Wed, 15 Aug 2012 08:41:16 -0500 Subject: [PATCH 7/7] convert jetty-servlet to annotated jmx --- .../main/java/org/eclipse/jetty/servlet/FilterMapping.java | 7 ++++++- .../src/main/java/org/eclipse/jetty/servlet/Holder.java | 7 +++++++ .../org/eclipse/jetty/servlet/ServletContextHandler.java | 6 ++++++ .../java/org/eclipse/jetty/servlet/ServletHandler.java | 7 +++++++ .../main/java/org/eclipse/jetty/servlet/ServletHolder.java | 6 ++++++ .../java/org/eclipse/jetty/servlet/ServletMapping.java | 6 ++++++ .../jetty/servlet/jmx/FilterMapping-mbean.properties | 4 ---- .../org/eclipse/jetty/servlet/jmx/Holder-mbean.properties | 5 ----- .../servlet/jmx/ServletContextHandler-mbean.properties | 4 ---- .../jetty/servlet/jmx/ServletHandler-mbean.properties | 5 ----- .../jetty/servlet/jmx/ServletHolder-mbean.properties | 4 ---- .../jetty/servlet/jmx/ServletMapping-mbean.properties | 3 --- 12 files changed, 38 insertions(+), 26 deletions(-) delete mode 100644 jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/FilterMapping-mbean.properties delete mode 100644 jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties delete mode 100644 jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletContextHandler-mbean.properties delete mode 100644 jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHandler-mbean.properties delete mode 100644 jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHolder-mbean.properties delete mode 100644 jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletMapping-mbean.properties diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java index 25955bdd769..3601211cc9b 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java @@ -21,10 +21,12 @@ import javax.servlet.DispatcherType; import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.util.TypeUtil; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.component.Dumpable; - +@ManagedObject("Filter Mappings") public class FilterMapping implements Dumpable { /** Dispatch types */ @@ -126,6 +128,7 @@ public class FilterMapping implements Dumpable /** * @return Returns the filterName. */ + @ManagedAttribute(value="filter name", readonly=true) public String getFilterName() { return _filterName; @@ -144,6 +147,7 @@ public class FilterMapping implements Dumpable /** * @return Returns the pathSpec. */ + @ManagedAttribute(value="url patterns", readonly=true) public String[] getPathSpecs() { return _pathSpecs; @@ -223,6 +227,7 @@ public class FilterMapping implements Dumpable /** * @return Returns the servletName. */ + @ManagedAttribute(value="servlet names", readonly=true) public String[] getServletNames() { return _servletNames; diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java index eea5ac42feb..877b9bb387f 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java @@ -27,6 +27,8 @@ import javax.servlet.UnavailableException; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.Loader; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.component.Dumpable; @@ -38,6 +40,7 @@ import org.eclipse.jetty.util.log.Logger; /** * */ +@ManagedObject("Holder - a container for servlets and the like") public class Holder extends AbstractLifeCycle implements Dumpable { public enum Source { EMBEDDED, JAVAX_API, DESCRIPTOR, ANNOTATION }; @@ -111,6 +114,7 @@ public class Holder extends AbstractLifeCycle implements Dumpable } /* ------------------------------------------------------------ */ + @ManagedAttribute(value="Class Name", readonly=true) public String getClassName() { return _className; @@ -123,6 +127,7 @@ public class Holder extends AbstractLifeCycle implements Dumpable } /* ------------------------------------------------------------ */ + @ManagedAttribute(value="Display Name", readonly=true) public String getDisplayName() { return _displayName; @@ -145,12 +150,14 @@ public class Holder extends AbstractLifeCycle implements Dumpable } /* ---------------------------------------------------------------- */ + @ManagedAttribute(value="Initial Parameters", readonly=true) public Map getInitParameters() { return _initParams; } /* ------------------------------------------------------------ */ + @ManagedAttribute(value="Name", readonly=true) public String getName() { return _name; diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index aeebdf433c2..c05d7def6e2 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -53,6 +53,8 @@ import org.eclipse.jetty.server.handler.ErrorHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.session.SessionHandler; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; /* ------------------------------------------------------------ */ @@ -66,6 +68,7 @@ import org.eclipse.jetty.server.session.SessionHandler; * This class should have been called ServletContext, but this would have * cause confusion with {@link ServletContext}. */ +@ManagedObject("Servlet Context Handler") public class ServletContextHandler extends ContextHandler { public final static int SESSIONS=1; @@ -262,6 +265,7 @@ public class ServletContextHandler extends ContextHandler /** * @return Returns the securityHandler. */ + @ManagedAttribute(value="context security handler", readonly=true) public SecurityHandler getSecurityHandler() { if (_securityHandler==null && (_options&SECURITY)!=0 && !isStarted()) @@ -274,6 +278,7 @@ public class ServletContextHandler extends ContextHandler /** * @return Returns the servletHandler. */ + @ManagedAttribute(value="context servlet handler", readonly=true) public ServletHandler getServletHandler() { if (_servletHandler==null && !isStarted()) @@ -285,6 +290,7 @@ public class ServletContextHandler extends ContextHandler /** * @return Returns the sessionHandler. */ + @ManagedAttribute(value="context session handler", readonly=true) public SessionHandler getSessionHandler() { if (_sessionHandler==null && (_options&SESSIONS)!=0 && !isStarted()) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 6fd5ab614a4..9e054966778 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -62,6 +62,8 @@ import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.URIUtil; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -77,6 +79,7 @@ import org.eclipse.jetty.util.log.Logger; * Unless run as part of a {@link ServletContextHandler} or derivative, the {@link #initialize()} * method must be called manually after start(). */ +@ManagedObject("Servlet Handler") public class ServletHandler extends ScopedHandler { private static final Logger LOG = Log.getLogger(ServletHandler.class); @@ -230,6 +233,7 @@ public class ServletHandler extends ScopedHandler /** * @return Returns the filterMappings. */ + @ManagedAttribute(value="filters", readonly=true) public FilterMapping[] getFilterMappings() { return _filterMappings; @@ -239,6 +243,7 @@ public class ServletHandler extends ScopedHandler /** Get Filters. * @return Array of defined servlets */ + @ManagedAttribute(value="filters", readonly=true) public FilterHolder[] getFilters() { return _filters; @@ -266,6 +271,7 @@ public class ServletHandler extends ScopedHandler /** * @return Returns the servletMappings. */ + @ManagedAttribute(value="mappings of servlets", readonly=true) public ServletMapping[] getServletMappings() { return _servletMappings; @@ -300,6 +306,7 @@ public class ServletHandler extends ScopedHandler /** Get Servlets. * @return Array of defined servlets */ + @ManagedAttribute(value="servlets", readonly=true) public ServletHolder[] getServlets() { return _servlets; diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java index 360e00cad08..48def56b2f1 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java @@ -43,6 +43,8 @@ import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.Loader; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -58,6 +60,7 @@ import org.eclipse.jetty.util.log.Logger; * * */ +@ManagedObject("Servlet Holder") public class ServletHolder extends Holder implements UserIdentity.Scope, Comparable { private static final Logger LOG = Log.getLogger(ServletHolder.class); @@ -157,6 +160,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } /* ------------------------------------------------------------ */ + @ManagedAttribute(value="initialization order", readonly=true) public int getInitOrder() { return _initOrder; @@ -254,6 +258,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope /** * @return Returns the forcedPath. */ + @ManagedAttribute(value="forced servlet path", readonly=true) public String getForcedPath() { return _forcedPath; @@ -585,6 +590,7 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } /* ------------------------------------------------------------ */ + @ManagedAttribute(value="role to run servlet as", readonly=true) public String getRunAsRole() { return _runAsRole; diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletMapping.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletMapping.java index 27af5fa4001..456a2e2cb0f 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletMapping.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletMapping.java @@ -16,7 +16,10 @@ package org.eclipse.jetty.servlet; import java.io.IOException; import java.util.Arrays; +import org.eclipse.jetty.util.annotation.ManagedAttribute; +import org.eclipse.jetty.util.annotation.ManagedObject; +@ManagedObject("Servlet Mapping") public class ServletMapping { private String[] _pathSpecs; @@ -33,6 +36,7 @@ public class ServletMapping /** * @return Returns the pathSpecs. */ + @ManagedAttribute(value="url patterns", readonly=true) public String[] getPathSpecs() { return _pathSpecs; @@ -42,6 +46,7 @@ public class ServletMapping /** * @return Returns the servletName. */ + @ManagedAttribute(value="servlet name", readonly=true) public String getServletName() { return _servletName; @@ -79,6 +84,7 @@ public class ServletMapping /** * @return */ + @ManagedAttribute(value="default", readonly=true) public boolean isDefault() { return _default; diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/FilterMapping-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/FilterMapping-mbean.properties deleted file mode 100644 index afcbe2f032c..00000000000 --- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/FilterMapping-mbean.properties +++ /dev/null @@ -1,4 +0,0 @@ -FilterMapping: Filter Mapping -filterName: RO:Filter Name -pathSpecs: RO:URL patterns -servletNames: RO:Servlet Names diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties deleted file mode 100644 index 7730ff40733..00000000000 --- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties +++ /dev/null @@ -1,5 +0,0 @@ -Holder: Holder -name: RO:Name -displayName: RO:Display Name -className: RO:Class Name -initParameters: RO:Initial parameters diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletContextHandler-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletContextHandler-mbean.properties deleted file mode 100644 index 2c1a05adb4b..00000000000 --- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletContextHandler-mbean.properties +++ /dev/null @@ -1,4 +0,0 @@ -ServletContextHandler: Servlet Context Handler -securityHandler: MObject: The context's security handler -servletHandler: MObject: The context's servlet handler -sessionHandler: MObject: The context's session handler diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHandler-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHandler-mbean.properties deleted file mode 100644 index 9326c1906d6..00000000000 --- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHandler-mbean.properties +++ /dev/null @@ -1,5 +0,0 @@ -ServletHandler: Servlet Handler -servlets: MObject:RO:Servlets -servletMappings: MObject:RO:Mappings of servlets -filters: MObject:RO:Filters -filterMappings: MObject:RO:Mappings of filters diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHolder-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHolder-mbean.properties deleted file mode 100644 index 38445467d3c..00000000000 --- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletHolder-mbean.properties +++ /dev/null @@ -1,4 +0,0 @@ -ServletHolder: Servlet Holder -initOrder: Initialization order -runAsRole: Role to run servlet as -forcedPath: Forced servlet path diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletMapping-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletMapping-mbean.properties deleted file mode 100644 index efe07ff433c..00000000000 --- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/ServletMapping-mbean.properties +++ /dev/null @@ -1,3 +0,0 @@ -ServletMapping: Servlet Mapping -servletName: RO:Servlet Name -pathSpecs: RO:URL patterns