use of org.eclipse.jetty.util.annotation.ManagedOperation in project jetty.project by eclipse.
the class JavaMonitorTools method getCacheNegativeSeconds.
@ManagedOperation(value = "Amount of time failed DNS queries are cached for")
public int getCacheNegativeSeconds() throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
final Class policy = Class.forName(POLICY);
final Object returnValue = policy.getMethod("getNegative", (Class[]) null).invoke(null, (Object[]) null);
Integer seconds = (Integer) returnValue;
return seconds.intValue();
}
use of org.eclipse.jetty.util.annotation.ManagedOperation in project jetty.project by eclipse.
the class ContextHandlerMBean method setContextAttribute.
@ManagedOperation(value = "Set context attribute", impact = "ACTION")
public void setContextAttribute(@Name(value = "name", description = "attribute name") String name, @Name(value = "value", description = "attribute value") Object value) {
Attributes attrs = ((ContextHandler) _managed).getAttributes();
attrs.setAttribute(name, value);
}
use of org.eclipse.jetty.util.annotation.ManagedOperation in project zeppelin by apache.
the class NotebookServer method sendMessage.
@ManagedOperation
public void sendMessage(String message) {
Message m = new Message(OP.NOTICE);
m.data.put("notice", message);
connectionManager.broadcast(m);
}
use of org.eclipse.jetty.util.annotation.ManagedOperation in project jetty.project by eclipse.
the class ObjectMBean method getMBeanInfo.
public MBeanInfo getMBeanInfo() {
try {
if (_info == null) {
// Start with blank lazy lists attributes etc.
String desc = null;
List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
List<MBeanConstructorInfo> constructors = new ArrayList<MBeanConstructorInfo>();
List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
List<MBeanNotificationInfo> notifications = new ArrayList<MBeanNotificationInfo>();
// Find list of classes that can influence the mbean
Class<?> o_class = _managed.getClass();
List<Class<?>> influences = new ArrayList<Class<?>>();
// always add MBean itself
influences.add(this.getClass());
influences = findInfluences(influences, _managed.getClass());
if (LOG.isDebugEnabled())
LOG.debug("Influence Count: {}", influences.size());
// Process Type Annotations
ManagedObject primary = o_class.getAnnotation(ManagedObject.class);
if (primary != null) {
desc = primary.value();
} else {
if (LOG.isDebugEnabled())
LOG.debug("No @ManagedObject declared on {}", _managed.getClass());
}
// For each influence
for (int i = 0; i < influences.size(); i++) {
Class<?> oClass = influences.get(i);
ManagedObject typeAnnotation = oClass.getAnnotation(ManagedObject.class);
if (LOG.isDebugEnabled())
LOG.debug("Influenced by: " + oClass.getCanonicalName());
if (typeAnnotation == null) {
if (LOG.isDebugEnabled())
LOG.debug("Annotations not found for: {}", oClass.getCanonicalName());
continue;
}
for (Method method : oClass.getDeclaredMethods()) {
ManagedAttribute methodAttributeAnnotation = method.getAnnotation(ManagedAttribute.class);
if (methodAttributeAnnotation != null) {
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
if (LOG.isDebugEnabled())
LOG.debug("Attribute Annotation found for: {}", method.getName());
MBeanAttributeInfo mai = defineAttribute(method, methodAttributeAnnotation);
if (mai != null) {
attributes.add(mai);
}
}
ManagedOperation methodOperationAnnotation = method.getAnnotation(ManagedOperation.class);
if (methodOperationAnnotation != null) {
if (LOG.isDebugEnabled())
LOG.debug("Method Annotation found for: {}", method.getName());
MBeanOperationInfo oi = defineOperation(method, methodOperationAnnotation);
if (oi != null) {
operations.add(oi);
}
}
}
}
_info = new MBeanInfo(o_class.getName(), desc, (MBeanAttributeInfo[]) attributes.toArray(new MBeanAttributeInfo[attributes.size()]), (MBeanConstructorInfo[]) constructors.toArray(new MBeanConstructorInfo[constructors.size()]), (MBeanOperationInfo[]) operations.toArray(new MBeanOperationInfo[operations.size()]), (MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
}
} catch (RuntimeException e) {
LOG.warn(e);
throw e;
}
return _info;
}
use of org.eclipse.jetty.util.annotation.ManagedOperation in project jetty.project by eclipse.
the class ContextHandlerCollection method mapContexts.
/* ------------------------------------------------------------ */
/**
* Remap the context paths.
*/
@ManagedOperation("update the mapping of context path to context")
public void mapContexts() {
_contextBranches.clear();
if (getHandlers() == null) {
_pathBranches = new ArrayTernaryTrie<>(false, 16);
return;
}
// Create map of contextPath to handler Branch
Map<String, Branch[]> map = new HashMap<>();
for (Handler handler : getHandlers()) {
Branch branch = new Branch(handler);
for (String contextPath : branch.getContextPaths()) {
Branch[] branches = map.get(contextPath);
map.put(contextPath, ArrayUtil.addToArray(branches, branch, Branch.class));
}
for (ContextHandler context : branch.getContextHandlers()) _contextBranches.putIfAbsent(context, branch.getHandler());
}
// Sort the branches so those with virtual hosts are considered before those without
for (Map.Entry<String, Branch[]> entry : map.entrySet()) {
Branch[] branches = entry.getValue();
Branch[] sorted = new Branch[branches.length];
int i = 0;
for (Branch branch : branches) if (branch.hasVirtualHost())
sorted[i++] = branch;
for (Branch branch : branches) if (!branch.hasVirtualHost())
sorted[i++] = branch;
entry.setValue(sorted);
}
// Loop until we have a big enough trie to hold all the context paths
int capacity = 512;
Trie<Map.Entry<String, Branch[]>> trie;
loop: while (true) {
trie = new ArrayTernaryTrie<>(false, capacity);
for (Map.Entry<String, Branch[]> entry : map.entrySet()) {
if (!trie.put(entry.getKey().substring(1), entry)) {
capacity += 512;
continue loop;
}
}
break loop;
}
if (LOG.isDebugEnabled()) {
for (String ctx : trie.keySet()) LOG.debug("{}->{}", ctx, Arrays.asList(trie.get(ctx).getValue()));
}
_pathBranches = trie;
}
Aggregations