Search in sources :

Example 1 with ManagedOperation

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();
}
Also used : ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Example 2 with ManagedOperation

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);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Attributes(org.eclipse.jetty.util.Attributes) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Example 3 with ManagedOperation

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);
}
Also used : OnMessage(javax.websocket.OnMessage) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) Message(org.apache.zeppelin.common.Message) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Example 4 with ManagedOperation

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;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation) MBeanConstructorInfo(javax.management.MBeanConstructorInfo) MBeanNotificationInfo(javax.management.MBeanNotificationInfo) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject)

Example 5 with ManagedOperation

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Handler(org.eclipse.jetty.server.Handler) ArrayTernaryTrie(org.eclipse.jetty.util.ArrayTernaryTrie) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ManagedOperation(org.eclipse.jetty.util.annotation.ManagedOperation)

Aggregations

ManagedOperation (org.eclipse.jetty.util.annotation.ManagedOperation)8 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)3 Attributes (org.eclipse.jetty.util.Attributes)3 ManagedObject (org.eclipse.jetty.util.annotation.ManagedObject)3 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)1 MBeanInfo (javax.management.MBeanInfo)1 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)1 MBeanOperationInfo (javax.management.MBeanOperationInfo)1 OnMessage (javax.websocket.OnMessage)1 ClusterMessage (org.apache.zeppelin.cluster.event.ClusterMessage)1 Message (org.apache.zeppelin.common.Message)1 Handler (org.eclipse.jetty.server.Handler)1 ArrayTernaryTrie (org.eclipse.jetty.util.ArrayTernaryTrie)1