Search in sources :

Example 11 with Set

use of java.util.Set 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 12 with Set

use of java.util.Set 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 13 with Set

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

the class FlexibleAggregationStrategiesTest method testHashSet.

@Test
public void testHashSet() throws Exception {
    HashSet<String> r = new HashSet<>();
    r.add("FIRST");
    r.add("SECOND");
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).and().whenExactlyFailed(0).create();
    Set result = template.requestBody("direct:hashset", Arrays.asList("FIRST", "SECOND"), Set.class);
    assertTrue(notify.matches(10, TimeUnit.SECONDS));
    assertEquals(r, result);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Set(java.util.Set) HashSet(java.util.HashSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with Set

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

the class JcloudsSpringComputeTest method testRunScript.

@SuppressWarnings("unchecked")
@Ignore("For now not possible to combine stub provider with ssh module, required for runScript")
@Test
public void testRunScript() throws InterruptedException {
    Map<String, Object> runScriptHeaders = new HashMap<String, Object>();
    runScriptHeaders.put(JcloudsConstants.OPERATION, JcloudsConstants.RUN_SCRIPT);
    Set<? extends NodeMetadata> nodeMetadatas = (Set<? extends NodeMetadata>) template.requestBodyAndHeaders("direct:in-out", null, createHeaders("1", "default"));
    assertEquals("There should be a node running", 1, nodeMetadatas.size());
    for (NodeMetadata nodeMetadata : nodeMetadatas) {
        runScriptHeaders.put(JcloudsConstants.NODE_ID, nodeMetadata.getId());
        template.requestBodyAndHeaders("direct:in-out", null, runScriptHeaders);
        template.sendBodyAndHeaders("direct:in-out", null, destroyHeaders(nodeMetadata.getId(), null));
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) Set(java.util.Set) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with Set

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

the class JdbcRSMetaDataTest method testJdbcRSMetaData.

@Test
@SuppressWarnings("unchecked")
public void testJdbcRSMetaData() {
    Endpoint directHelloEndpoint = context.getEndpoint("direct:hello");
    Exchange directHelloExchange = directHelloEndpoint.createExchange();
    directHelloExchange.getIn().setBody("select * from customer order by ID");
    Exchange out = template.send(directHelloEndpoint, directHelloExchange);
    assertNotNull(out);
    assertNotNull(out.getOut());
    List<Map<String, Object>> returnValues = out.getOut().getBody(List.class);
    assertNotNull(returnValues);
    assertEquals(3, returnValues.size());
    Map<String, Object> row = returnValues.get(0);
    assertEquals("cust1", row.get("ID"));
    assertEquals("jstrachan", row.get("NAME"));
    Set<String> columnNames = (Set<String>) out.getOut().getHeader(JdbcConstants.JDBC_COLUMN_NAMES);
    assertNotNull(columnNames);
    assertEquals(2, columnNames.size());
    assertTrue(columnNames.contains("ID"));
    assertTrue(columnNames.contains("NAME"));
}
Also used : Exchange(org.apache.camel.Exchange) Set(java.util.Set) Endpoint(org.apache.camel.Endpoint) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Set (java.util.Set)6789 HashSet (java.util.HashSet)4372 HashMap (java.util.HashMap)2090 Map (java.util.Map)1865 Iterator (java.util.Iterator)1774 ArrayList (java.util.ArrayList)1113 List (java.util.List)980 Test (org.junit.Test)920 TreeSet (java.util.TreeSet)536 IOException (java.io.IOException)501 SSOException (com.iplanet.sso.SSOException)467 LinkedHashSet (java.util.LinkedHashSet)418 SMSException (com.sun.identity.sm.SMSException)347 IdRepoException (com.sun.identity.idm.IdRepoException)268 Collection (java.util.Collection)259 ImmutableSet (com.google.common.collect.ImmutableSet)256 File (java.io.File)245 SSOToken (com.iplanet.sso.SSOToken)226 Collectors (java.util.stream.Collectors)219 Test (org.testng.annotations.Test)209