Search in sources :

Example 6 with LinkedHashSet

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

the class MBeanInfoAssembler method getMBeanInfo.

/**
     * Gets the {@link ModelMBeanInfo} for the given managed bean
     *
     * @param defaultManagedBean  the default managed bean
     * @param customManagedBean   an optional custom managed bean
     * @param objectName   the object name
     * @return the model info, or <tt>null</tt> if not possible to create, for example due the managed bean is a proxy class
     * @throws JMException is thrown if error creating the model info
     */
public ModelMBeanInfo getMBeanInfo(Object defaultManagedBean, Object customManagedBean, String objectName) throws JMException {
    // skip proxy classes
    if (defaultManagedBean != null && Proxy.isProxyClass(defaultManagedBean.getClass())) {
        LOG.trace("Skip creating ModelMBeanInfo due proxy class {}", defaultManagedBean.getClass());
        return null;
    }
    // maps and lists to contain information about attributes and operations
    Map<String, ManagedAttributeInfo> attributes = new LinkedHashMap<String, ManagedAttributeInfo>();
    Set<ManagedOperationInfo> operations = new LinkedHashSet<ManagedOperationInfo>();
    Set<ModelMBeanAttributeInfo> mBeanAttributes = new LinkedHashSet<ModelMBeanAttributeInfo>();
    Set<ModelMBeanOperationInfo> mBeanOperations = new LinkedHashSet<ModelMBeanOperationInfo>();
    Set<ModelMBeanNotificationInfo> mBeanNotifications = new LinkedHashSet<ModelMBeanNotificationInfo>();
    // extract details from default managed bean
    if (defaultManagedBean != null) {
        extractAttributesAndOperations(defaultManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(defaultManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(defaultManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(defaultManagedBean, mBeanNotifications);
    }
    // extract details from custom managed bean
    if (customManagedBean != null) {
        extractAttributesAndOperations(customManagedBean.getClass(), attributes, operations);
        extractMbeanAttributes(customManagedBean, attributes, mBeanAttributes, mBeanOperations);
        extractMbeanOperations(customManagedBean, operations, mBeanOperations);
        extractMbeanNotifications(customManagedBean, mBeanNotifications);
    }
    // create the ModelMBeanInfo
    String name = getName(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    String description = getDescription(customManagedBean != null ? customManagedBean : defaultManagedBean, objectName);
    ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
    ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
    ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
    ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
    LOG.trace("Created ModelMBeanInfo {}", info);
    return info;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ModelMBeanOperationInfo(javax.management.modelmbean.ModelMBeanOperationInfo) ModelMBeanNotificationInfo(javax.management.modelmbean.ModelMBeanNotificationInfo) ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) LinkedHashMap(java.util.LinkedHashMap) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) ModelMBeanInfoSupport(javax.management.modelmbean.ModelMBeanInfoSupport)

Example 7 with LinkedHashSet

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

the class HostUtils method getAddresses.

/**
     * Returns a {@link Set} of {@link InetAddress} that are non-loopback or mac.
     */
public static Set<InetAddress> getAddresses() {
    Set<InetAddress> allAddresses = new LinkedHashSet<InetAddress>();
    Map<String, Set<InetAddress>> interfaceAddressMap = getNetworkInterfaceAddresses();
    for (Map.Entry<String, Set<InetAddress>> entry : interfaceAddressMap.entrySet()) {
        Set<InetAddress> addresses = entry.getValue();
        if (!addresses.isEmpty()) {
            for (InetAddress address : addresses) {
                allAddresses.add(address);
            }
        }
    }
    return allAddresses;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) InetAddress(java.net.InetAddress) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 8 with LinkedHashSet

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

the class HostUtils method getNetworkInterfaceAddresses.

/**
     * Returns a {@link Map} of {@link InetAddress} per {@link NetworkInterface}.
     */
public static Map<String, Set<InetAddress>> getNetworkInterfaceAddresses() {
    //JVM returns interfaces in a non-predictable order, so to make this more predictable
    //let's have them sort by interface name (by using a TreeMap).
    Map<String, Set<InetAddress>> interfaceAddressMap = new TreeMap<String, Set<InetAddress>>();
    try {
        Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
        while (ifaces.hasMoreElements()) {
            NetworkInterface iface = ifaces.nextElement();
            //We only care about usable non-loopback interfaces.
            if (iface.isUp() && !iface.isLoopback() && !iface.isPointToPoint()) {
                String name = iface.getName();
                Enumeration<InetAddress> ifaceAdresses = iface.getInetAddresses();
                while (ifaceAdresses.hasMoreElements()) {
                    InetAddress ia = ifaceAdresses.nextElement();
                    //We want to filter out mac addresses
                    if (!ia.isLoopbackAddress() && !ia.getHostAddress().contains(":")) {
                        Set<InetAddress> addresses = interfaceAddressMap.get(name);
                        if (addresses == null) {
                            addresses = new LinkedHashSet<InetAddress>();
                        }
                        addresses.add(ia);
                        interfaceAddressMap.put(name, addresses);
                    }
                }
            }
        }
    } catch (SocketException ex) {
    //noop
    }
    return interfaceAddressMap;
}
Also used : SocketException(java.net.SocketException) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) NetworkInterface(java.net.NetworkInterface) TreeMap(java.util.TreeMap) InetAddress(java.net.InetAddress)

Example 9 with LinkedHashSet

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

the class IntrospectionSupport method findSetterMethods.

public static Set<Method> findSetterMethods(Class<?> clazz, String name, boolean allowBuilderPattern) {
    Set<Method> candidates = new LinkedHashSet<Method>();
    // Build the method name.
    name = "set" + ObjectHelper.capitalize(name);
    while (clazz != Object.class) {
        // Since Object.class.isInstance all the objects,
        // here we just make sure it will be add to the bottom of the set.
        Method objectSetMethod = null;
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.getName().equals(name) && isSetter(method, allowBuilderPattern)) {
                Class<?>[] params = method.getParameterTypes();
                if (params[0].equals(Object.class)) {
                    objectSetMethod = method;
                } else {
                    candidates.add(method);
                }
            }
        }
        if (objectSetMethod != null) {
            candidates.add(objectSetMethod);
        }
        clazz = clazz.getSuperclass();
    }
    return candidates;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Method(java.lang.reflect.Method)

Example 10 with LinkedHashSet

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

the class HttpComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    String addressUri = "http://" + remaining;
    if (uri.startsWith("https:")) {
        addressUri = "https://" + remaining;
    }
    Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters);
    // must extract well known parameters before we create the endpoint
    HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
    HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
    UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
    // http client can be configured from URI options
    HttpClientParams clientParams = new HttpClientParams();
    Map<String, Object> httpClientOptions = IntrospectionSupport.extractProperties(parameters, "httpClient.");
    IntrospectionSupport.setProperties(clientParams, httpClientOptions);
    // validate that we could resolve all httpClient. parameters as this component is lenient
    validateParameters(uri, httpClientOptions, null);
    // http client can be configured from URI options
    HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams();
    // setup the httpConnectionManagerParams
    Map<String, Object> httpConnectionManagerOptions = IntrospectionSupport.extractProperties(parameters, "httpConnectionManager.");
    IntrospectionSupport.setProperties(connectionManagerParams, httpConnectionManagerOptions);
    // validate that we could resolve all httpConnectionManager. parameters as this component is lenient
    validateParameters(uri, httpConnectionManagerOptions, null);
    // make sure the component httpConnectionManager is take effect
    HttpConnectionManager thisHttpConnectionManager = httpConnectionManager;
    if (thisHttpConnectionManager == null) {
        // only set the params on the new created http connection manager
        thisHttpConnectionManager = new MultiThreadedHttpConnectionManager();
        thisHttpConnectionManager.setParams(connectionManagerParams);
    }
    // create the configurer to use for this endpoint (authMethods contains the used methods created by the configurer)
    final Set<AuthMethod> authMethods = new LinkedHashSet<AuthMethod>();
    HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, authMethods);
    addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri);
    URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), httpClientParameters);
    // create the endpoint and connectionManagerParams already be set
    HttpEndpoint endpoint = createHttpEndpoint(endpointUri.toString(), this, clientParams, thisHttpConnectionManager, configurer);
    // configure the endpoint with the common configuration from the component
    if (getHttpConfiguration() != null) {
        Map<String, Object> properties = new HashMap<>();
        IntrospectionSupport.getProperties(getHttpConfiguration(), properties, null);
        setProperties(endpoint, properties);
    }
    if (headerFilterStrategy != null) {
        endpoint.setHeaderFilterStrategy(headerFilterStrategy);
    } else {
        setEndpointHeaderFilterStrategy(endpoint);
    }
    if (urlRewrite != null) {
        // let CamelContext deal with the lifecycle of the url rewrite
        // this ensures its being shutdown when Camel shutdown etc.
        getCamelContext().addService(urlRewrite);
        endpoint.setUrlRewrite(urlRewrite);
    }
    // prefer to use endpoint configured over component configured
    if (binding == null) {
        // fallback to component configured
        binding = getHttpBinding();
    }
    if (binding != null) {
        endpoint.setBinding(binding);
    }
    setProperties(endpoint, parameters);
    // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
    URI httpUri = URISupport.createRemainingURI(new URI(addressUri), parameters);
    // validate http uri that end-user did not duplicate the http part that can be a common error
    String part = httpUri.getSchemeSpecificPart();
    if (part != null) {
        part = part.toLowerCase();
        if (part.startsWith("//http//") || part.startsWith("//https//") || part.startsWith("//http://") || part.startsWith("//https://")) {
            throw new ResolveEndpointFailedException(uri, "The uri part is not configured correctly. You have duplicated the http(s) protocol.");
        }
    }
    endpoint.setHttpUri(httpUri);
    endpoint.setHttpClientOptions(httpClientOptions);
    return endpoint;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) UrlRewrite(org.apache.camel.http.common.UrlRewrite) HeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy) HttpRestHeaderFilterStrategy(org.apache.camel.http.common.HttpRestHeaderFilterStrategy) URI(java.net.URI) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClientParams(org.apache.commons.httpclient.params.HttpClientParams) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpBinding(org.apache.camel.http.common.HttpBinding) HttpConnectionManager(org.apache.commons.httpclient.HttpConnectionManager) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1252 ArrayList (java.util.ArrayList)241 Set (java.util.Set)154 HashSet (java.util.HashSet)128 HashMap (java.util.HashMap)115 File (java.io.File)102 IOException (java.io.IOException)97 Map (java.util.Map)97 Test (org.junit.Test)94 List (java.util.List)86 LinkedHashMap (java.util.LinkedHashMap)77 ProcessResult (org.asqatasun.entity.audit.ProcessResult)77 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 LinkedList (java.util.LinkedList)51 Iterator (java.util.Iterator)38 TreeSet (java.util.TreeSet)34 URL (java.net.URL)33 Collection (java.util.Collection)28 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)24 ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)23