From 07757a8cbb0729dde8e9db0d15dc952e8abbfb11 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Fri, 20 Jul 2012 15:20:05 -0500 Subject: [PATCH] [Bug 385448] @Managed annotation and example usage in the ContextHandler --- .../jetty/server/handler/ContextHandler.java | 32 +++++++++++++++++-- .../jetty/util/annotation/Managed.java | 17 ++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 jetty-util/src/main/java/org/eclipse/jetty/util/annotation/Managed.java diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 3ee08d14d5d..1c1db33cddb 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -73,6 +73,7 @@ import org.eclipse.jetty.util.component.Dumpable; 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.util.annotation.Managed; /* ------------------------------------------------------------ */ /** @@ -89,8 +90,10 @@ import org.eclipse.jetty.util.resource.Resource; * * @org.apache.xbean.XBean description="Creates a basic HTTP context" */ +@Managed("URI Context") public class ContextHandler extends ScopedHandler implements Attributes, Server.Graceful { + private static final Logger LOG = Log.getLogger(ContextHandler.class); private static final ThreadLocal __context = new ThreadLocal(); @@ -117,23 +120,44 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. private final AttributesMap _attributes; private final AttributesMap _contextAttributes; + + @Managed("Initial Parameter map for the context") private final Map _initParams; + private ClassLoader _classLoader; private String _contextPath = "/"; + + @Managed(value="Display name of the Context", readonly=true) private String _displayName; + private Resource _baseResource; private MimeTypes _mimeTypes; private Map _localeEncodingMap; + + @Managed("Partial URIs of directory welcome files") private String[] _welcomeFiles; + + @Managed(value="The error handler to use for the context", managed=true) private ErrorHandler _errorHandler; + + @Managed("Virtual hosts accepted by the context") private String[] _vhosts; + private Set _connectors; private EventListener[] _eventListeners; private Logger _logger; + + @Managed("Checks if the /context is not redirected to /context/") private boolean _allowNullPathInfo; + private int _maxFormKeys = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormKeys",1000).intValue(); + + @Managed("The maximum content size") private int _maxFormContentSize = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormContentSize",200000).intValue(); + + @Managed("True if URLs are compacted to replace the multiple '/'s with a single '/'") private boolean _compactPath = false; + private boolean _aliases = false; private Object _contextListeners; @@ -143,7 +167,9 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. private Map _managedAttributes; private String[] _protectedTargets; + @Managed("False if this context is accepting new requests. True for graceful shutdown, which allows existing requests to complete") private boolean _shutdown = false; + private boolean _available = true; private volatile int _availability; // 0=STOPPED, 1=AVAILABLE, 2=SHUTDOWN, 3=UNAVAILABLE @@ -1177,7 +1203,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. /* * @see javax.servlet.ServletContext#removeAttribute(java.lang.String) */ - public void removeAttribute(String name) + @Managed("Remove context attribute") + public void removeAttribute( @Managed("attribute name") String name) { checkManagedAttribute(name,null); _attributes.removeAttribute(name); @@ -1190,7 +1217,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. * * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object) */ - public void setAttribute(String name, Object value) + @Managed("Set context attribute") + public void setAttribute(@Managed("attribute name") String name, @Managed("attribute value") Object value) { checkManagedAttribute(name,value); _attributes.setAttribute(name,value); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/Managed.java b/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/Managed.java new file mode 100644 index 00000000000..bf9dc1bec6d --- /dev/null +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/annotation/Managed.java @@ -0,0 +1,17 @@ +package org.eclipse.jetty.util.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER } ) +public @interface Managed +{ + String value() default "Not Specified"; + boolean readonly() default false; + boolean managed() default false; +}