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;
}
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;
}
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);
}
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));
}
}
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"));
}
Aggregations