Search in sources :

Example 6 with HashSet

use of java.util.HashSet in project camel by apache.

the class XPathBuilder method logDiscoveredNamespaces.

private void logDiscoveredNamespaces(NodeList namespaces) {
    Map<String, HashSet<String>> map = new LinkedHashMap<String, HashSet<String>>();
    for (int i = 0; i < namespaces.getLength(); i++) {
        Node n = namespaces.item(i);
        if (n.getNodeName().equals("xmlns:xml")) {
            // skip the implicit XML namespace as it provides no value
            continue;
        }
        String prefix = namespaces.item(i).getNodeName();
        if (prefix.equals("xmlns")) {
            prefix = "DEFAULT";
        }
        // add to map
        if (!map.containsKey(prefix)) {
            map.put(prefix, new HashSet<String>());
        }
        map.get(prefix).add(namespaces.item(i).getNodeValue());
    }
    LOG.info("Namespaces discovered in message: {}.", map);
}
Also used : Node(org.w3c.dom.Node) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 7 with HashSet

use of java.util.HashSet in project camel by apache.

the class BeanInfo method introspect.

/**
     * Introspects the given class
     *
     * @param clazz the class
     */
private void introspect(Class<?> clazz) {
    // get the target clazz as it could potentially have been enhanced by CGLIB etc.
    clazz = getTargetClass(clazz);
    ObjectHelper.notNull(clazz, "clazz", this);
    LOG.trace("Introspecting class: {}", clazz);
    // does the class have any public constructors?
    publicConstructors = clazz.getConstructors().length > 0;
    // favor declared methods, and then filter out duplicate interface methods
    List<Method> methods;
    if (Modifier.isPublic(clazz.getModifiers())) {
        LOG.trace("Preferring class methods as class: {} is public accessible", clazz);
        methods = new ArrayList<Method>(Arrays.asList(clazz.getDeclaredMethods()));
    } else {
        LOG.trace("Preferring interface methods as class: {} is not public accessible", clazz);
        methods = getInterfaceMethods(clazz);
        // and then we must add its declared methods as well
        List<Method> extraMethods = Arrays.asList(clazz.getDeclaredMethods());
        methods.addAll(extraMethods);
    }
    Set<Method> overrides = new HashSet<Method>();
    // do not remove duplicates form class from the Java itself as they have some "duplicates" we need
    boolean javaClass = clazz.getName().startsWith("java.") || clazz.getName().startsWith("javax.");
    if (!javaClass) {
        // it may have duplicate methods already, even from declared or from interfaces + declared
        for (Method source : methods) {
            // skip bridge methods in duplicate checks (as the bridge method is inserted by the compiler due to type erasure)
            if (source.isBridge()) {
                continue;
            }
            for (Method target : methods) {
                // skip ourselves
                if (ObjectHelper.isOverridingMethod(source, target, true)) {
                    continue;
                }
                // skip duplicates which may be assign compatible (favor keep first added method when duplicate)
                if (ObjectHelper.isOverridingMethod(source, target, false)) {
                    overrides.add(target);
                }
            }
        }
        methods.removeAll(overrides);
        overrides.clear();
    }
    // if we are a public class, then add non duplicate interface classes also
    if (Modifier.isPublic(clazz.getModifiers())) {
        // add additional interface methods
        List<Method> extraMethods = getInterfaceMethods(clazz);
        for (Method source : extraMethods) {
            for (Method target : methods) {
                if (ObjectHelper.isOverridingMethod(source, target, false)) {
                    overrides.add(source);
                }
            }
            for (Method target : methodMap.keySet()) {
                if (ObjectHelper.isOverridingMethod(source, target, false)) {
                    overrides.add(source);
                }
            }
        }
        // remove all the overrides methods
        extraMethods.removeAll(overrides);
        methods.addAll(extraMethods);
    }
    // now introspect the methods and filter non valid methods
    for (Method method : methods) {
        boolean valid = isValidMethod(clazz, method);
        LOG.trace("Method: {} is valid: {}", method, valid);
        if (valid) {
            introspect(clazz, method);
        }
    }
    Class<?> superclass = clazz.getSuperclass();
    if (superclass != null && !superclass.equals(Object.class)) {
        introspect(superclass);
    }
}
Also used : Method(java.lang.reflect.Method) HashSet(java.util.HashSet)

Example 8 with HashSet

use of java.util.HashSet in project antlrworks by antlr.

the class XJUndoEngine method unregisterUndo.

public void unregisterUndo(XJUndoDelegate delegate) {
    for (JTextPane tp : new HashSet<JTextPane>(undos.keySet())) {
        XJUndo undo = undos.get(tp);
        if (undo.delegate == delegate) {
            undo.close();
            undos.remove(tp);
            for (FocusListener fl : tp.getFocusListeners()) {
                tp.removeFocusListener(fl);
            }
        }
    }
}
Also used : FocusListener(java.awt.event.FocusListener) HashSet(java.util.HashSet)

Example 9 with HashSet

use of java.util.HashSet in project camel by apache.

the class DefaultRuntimeEndpointRegistry method notify.

@Override
public void notify(EventObject event) throws Exception {
    if (event instanceof RouteAddedEvent) {
        RouteAddedEvent rse = (RouteAddedEvent) event;
        Endpoint endpoint = rse.getRoute().getEndpoint();
        String routeId = rse.getRoute().getId();
        // a HashSet is fine for inputs as we only have a limited number of those
        Set<String> uris = new HashSet<String>();
        uris.add(endpoint.getEndpointUri());
        inputs.put(routeId, uris);
        // use a LRUCache for outputs as we could potential have unlimited uris if dynamic routing is in use
        // and therefore need to have the limit in use
        outputs.put(routeId, new LRUCache<String, String>(limit));
    } else if (event instanceof RouteRemovedEvent) {
        RouteRemovedEvent rse = (RouteRemovedEvent) event;
        String routeId = rse.getRoute().getId();
        inputs.remove(routeId);
        outputs.remove(routeId);
        if (extended) {
            String uri = rse.getRoute().getEndpoint().getEndpointUri();
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                inputUtilization.remove(key);
            }
        }
    } else if (extended && event instanceof ExchangeCreatedEvent) {
        // we only capture details in extended mode
        ExchangeCreatedEvent ece = (ExchangeCreatedEvent) event;
        Endpoint endpoint = ece.getExchange().getFromEndpoint();
        if (endpoint != null) {
            String routeId = ece.getExchange().getFromRouteId();
            String uri = endpoint.getEndpointUri();
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                inputUtilization.onHit(key);
            }
        }
    } else if (event instanceof ExchangeSendingEvent) {
        ExchangeSendingEvent ese = (ExchangeSendingEvent) event;
        Endpoint endpoint = ese.getEndpoint();
        String routeId = getRouteId(ese.getExchange());
        String uri = endpoint.getEndpointUri();
        Map<String, String> uris = outputs.get(routeId);
        if (uris != null && !uris.containsKey(uri)) {
            uris.put(uri, uri);
        }
        if (extended) {
            String key = asUtilizationKey(routeId, uri);
            if (key != null) {
                outputUtilization.onHit(key);
            }
        }
    }
}
Also used : RouteAddedEvent(org.apache.camel.management.event.RouteAddedEvent) ExchangeCreatedEvent(org.apache.camel.management.event.ExchangeCreatedEvent) ExchangeSendingEvent(org.apache.camel.management.event.ExchangeSendingEvent) Endpoint(org.apache.camel.Endpoint) RouteRemovedEvent(org.apache.camel.management.event.RouteRemovedEvent) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 10 with HashSet

use of java.util.HashSet in project camel by apache.

the class DefaultShutdownStrategy method logInflightExchanges.

/**
     * Logs information about the inflight exchanges
     *
     * @param infoLevel <tt>true</tt> to log at INFO level, <tt>false</tt> to log at DEBUG level
     */
protected static void logInflightExchanges(CamelContext camelContext, List<RouteStartupOrder> routes, boolean infoLevel) {
    // check if we need to log
    if (!infoLevel && !LOG.isDebugEnabled()) {
        return;
    }
    Collection<InflightRepository.InflightExchange> inflights = camelContext.getInflightRepository().browse();
    int size = inflights.size();
    if (size == 0) {
        return;
    }
    // filter so inflight must start from any of the routes
    Set<String> routeIds = new HashSet<String>();
    for (RouteStartupOrder route : routes) {
        routeIds.add(route.getRoute().getId());
    }
    Collection<InflightRepository.InflightExchange> filtered = new ArrayList<InflightRepository.InflightExchange>();
    for (InflightRepository.InflightExchange inflight : inflights) {
        String routeId = inflight.getExchange().getFromRouteId();
        if (routeIds.contains(routeId)) {
            filtered.add(inflight);
        }
    }
    size = filtered.size();
    if (size == 0) {
        return;
    }
    StringBuilder sb = new StringBuilder("There are " + size + " inflight exchanges:");
    for (InflightRepository.InflightExchange inflight : filtered) {
        sb.append("\n\tInflightExchange: [exchangeId=").append(inflight.getExchange().getExchangeId()).append(", fromRouteId=").append(inflight.getExchange().getFromRouteId()).append(", routeId=").append(inflight.getRouteId()).append(", nodeId=").append(inflight.getNodeId()).append(", elapsed=").append(inflight.getElapsed()).append(", duration=").append(inflight.getDuration()).append("]");
    }
    if (infoLevel) {
        LOG.info(sb.toString());
    } else {
        LOG.debug(sb.toString());
    }
}
Also used : InflightRepository(org.apache.camel.spi.InflightRepository) ArrayList(java.util.ArrayList) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

HashSet (java.util.HashSet)12137 Set (java.util.Set)2609 ArrayList (java.util.ArrayList)2318 HashMap (java.util.HashMap)2096 Test (org.junit.Test)2060 Map (java.util.Map)1198 Iterator (java.util.Iterator)979 IOException (java.io.IOException)934 List (java.util.List)911 File (java.io.File)607 LinkedHashSet (java.util.LinkedHashSet)460 Test (org.testng.annotations.Test)460 TreeSet (java.util.TreeSet)271 Collection (java.util.Collection)233 LinkedList (java.util.LinkedList)224 Region (org.apache.geode.cache.Region)202 SSOException (com.iplanet.sso.SSOException)188 Date (java.util.Date)180 LinkedHashMap (java.util.LinkedHashMap)169 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166