1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.server.handler.jmx;
20
21 import java.util.Enumeration;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.eclipse.jetty.server.handler.ContextHandler;
26 import org.eclipse.jetty.util.Attributes;
27 import org.eclipse.jetty.util.annotation.ManagedAttribute;
28 import org.eclipse.jetty.util.annotation.ManagedObject;
29 import org.eclipse.jetty.util.annotation.ManagedOperation;
30 import org.eclipse.jetty.util.annotation.Name;
31
32 @ManagedObject("ContextHandler mbean wrapper")
33 public class ContextHandlerMBean extends AbstractHandlerMBean
34 {
35 public ContextHandlerMBean(Object managedObject)
36 {
37 super(managedObject);
38 }
39
40 @ManagedAttribute("Map of context attributes")
41 public Map<String,Object> getContextAttributes()
42 {
43 Map<String,Object> map = new HashMap<String,Object>();
44 Attributes attrs = ((ContextHandler)_managed).getAttributes();
45 Enumeration<String> en = attrs.getAttributeNames();
46 while (en.hasMoreElements())
47 {
48 String name = (String)en.nextElement();
49 Object value = attrs.getAttribute(name);
50 map.put(name,value);
51 }
52 return map;
53 }
54
55 @ManagedOperation(value="Set context attribute", impact="ACTION")
56 public void setContextAttribute(@Name(value = "name", description="attribute name") String name, @Name(value = "value", description="attribute value") Object value)
57 {
58 Attributes attrs = ((ContextHandler)_managed).getAttributes();
59 attrs.setAttribute(name,value);
60 }
61
62 @ManagedOperation(value="Set context attribute", impact="ACTION")
63 public void setContextAttribute(@Name(value = "name", description="attribute name") String name, @Name(value = "value", description="attribute value") String value)
64 {
65 Attributes attrs = ((ContextHandler)_managed).getAttributes();
66 attrs.setAttribute(name,value);
67 }
68
69 @ManagedOperation(value="Remove context attribute", impact="ACTION")
70 public void removeContextAttribute(@Name(value = "name", description="attribute name") String name)
71 {
72 Attributes attrs = ((ContextHandler)_managed).getAttributes();
73 attrs.removeAttribute(name);
74 }
75 }