use of java.util.Collection in project elasticsearch by elastic.
the class UnicastZenPingTests method testResolveReuseExistingNodeConnections.
public void testResolveReuseExistingNodeConnections() throws ExecutionException, InterruptedException {
final Settings settings = Settings.builder().put("cluster.name", "test").put(TransportSettings.PORT.getKey(), 0).build();
NetworkService networkService = new NetworkService(settings, Collections.emptyList());
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockTcpTransport(s, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()), networkService, v);
NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
closeables.push(handleA.transportService);
NetworkHandle handleB = startServices(settings, threadPool, "UZP_B", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
closeables.push(handleB.transportService);
final boolean useHosts = randomBoolean();
final Settings.Builder hostsSettingsBuilder = Settings.builder().put("cluster.name", "test");
if (useHosts) {
hostsSettingsBuilder.putArray("discovery.zen.ping.unicast.hosts", NetworkAddress.format(new InetSocketAddress(handleB.address.address().getAddress(), handleB.address.address().getPort())));
} else {
hostsSettingsBuilder.put("discovery.zen.ping.unicast.hosts", (String) null);
}
final Settings hostsSettings = hostsSettingsBuilder.build();
final ClusterState state = ClusterState.builder(new ClusterName("test")).version(randomNonNegativeLong()).build();
// connection to reuse
handleA.transportService.connectToNode(handleB.node);
// install a listener to check that no new connections are made
handleA.transportService.addConnectionListener(new TransportConnectionListener() {
@Override
public void onConnectionOpened(DiscoveryNode node) {
fail("should not open any connections. got [" + node + "]");
}
});
final TestUnicastZenPing zenPingA = new TestUnicastZenPing(hostsSettings, threadPool, handleA, EMPTY_HOSTS_PROVIDER);
zenPingA.start(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {
return DiscoveryNodes.builder().add(handleA.node).add(handleB.node).localNodeId("UZP_A").build();
}
@Override
public ClusterState clusterState() {
return ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)).build();
}
});
closeables.push(zenPingA);
TestUnicastZenPing zenPingB = new TestUnicastZenPing(hostsSettings, threadPool, handleB, EMPTY_HOSTS_PROVIDER);
zenPingB.start(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {
return DiscoveryNodes.builder().add(handleB.node).localNodeId("UZP_B").build();
}
@Override
public ClusterState clusterState() {
return state;
}
});
closeables.push(zenPingB);
Collection<ZenPing.PingResponse> pingResponses = zenPingA.pingAndWait().toList();
assertThat(pingResponses.size(), equalTo(1));
ZenPing.PingResponse ping = pingResponses.iterator().next();
assertThat(ping.node().getId(), equalTo("UZP_B"));
assertThat(ping.getClusterStateVersion(), equalTo(state.version()));
}
use of java.util.Collection in project elasticsearch by elastic.
the class Lucene method files.
/**
* Returns an iterable that allows to iterate over all files in this segments info
*/
public static Iterable<String> files(SegmentInfos infos) throws IOException {
final List<Collection<String>> list = new ArrayList<>();
list.add(Collections.singleton(infos.getSegmentsFileName()));
for (SegmentCommitInfo info : infos) {
list.add(info.files());
}
return Iterables.flatten(list);
}
use of java.util.Collection in project che by eclipse.
the class TemplateReaderWriter method read.
/**
* Reads templates from an <code>InputSource</code> and adds them to the templates.
*
* @param source the input source
* @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
* @param singleId the template id to extract, or <code>null</code> to read in all templates
* @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
* @throws IOException if reading from the stream fails
*/
private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle, String singleId) throws IOException {
try {
Collection templates = new ArrayList();
Set ids = new HashSet();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Document document = parser.parse(source);
NodeList elements = document.getElementsByTagName(TEMPLATE_ELEMENT);
int count = elements.getLength();
for (int i = 0; i != count; i++) {
Node node = elements.item(i);
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
continue;
String id = getStringValue(attributes, ID_ATTRIBUTE, null);
if (id != null && ids.contains(id))
//$NON-NLS-1$
throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.duplicate.id"));
if (singleId != null && !singleId.equals(id))
continue;
boolean deleted = getBooleanValue(attributes, DELETED_ATTRIBUTE, false);
String name = getStringValue(attributes, NAME_ATTRIBUTE);
name = translateString(name, bundle);
//$NON-NLS-1$
String description = getStringValue(attributes, DESCRIPTION_ATTRIBUTE, "");
description = translateString(description, bundle);
String context = getStringValue(attributes, CONTEXT_ATTRIBUTE);
if (name == null || context == null)
//$NON-NLS-1$
throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute"));
boolean enabled = getBooleanValue(attributes, ENABLED_ATTRIBUTE, true);
boolean autoInsertable = getBooleanValue(attributes, AUTO_INSERTABLE_ATTRIBUTE, true);
StringBuffer buffer = new StringBuffer();
NodeList children = node.getChildNodes();
for (int j = 0; j != children.getLength(); j++) {
String value = children.item(j).getNodeValue();
if (value != null)
buffer.append(value);
}
String pattern = buffer.toString();
pattern = translateString(pattern, bundle);
Template template = new Template(name, description, context, pattern, autoInsertable);
TemplatePersistenceData data = new TemplatePersistenceData(template, enabled, id);
data.setDeleted(deleted);
templates.add(data);
if (singleId != null && singleId.equals(id))
break;
}
return (TemplatePersistenceData[]) templates.toArray(new TemplatePersistenceData[templates.size()]);
} catch (ParserConfigurationException e) {
Assert.isTrue(false);
} catch (SAXException e) {
//$NON-NLS-1$
throw (IOException) new IOException("Could not read template file").initCause(e);
}
// dummy
return null;
}
use of java.util.Collection in project che by eclipse.
the class ContributionTemplateStore method readContributedTemplates.
private Collection readContributedTemplates() throws /*IConfigurationElement[] extensions*/
IOException {
Collection templates = new ArrayList();
// for (int i= 0; i < extensions.length; i++) {
// if (extensions[i].getName().equals(TEMPLATE))
// createTemplate(templates, extensions[i]);
// else if (extensions[i].getName().equals(INCLUDE)) {
// readIncludedTemplates(templates, extensions[i]);
// }
// }
readIncludedTemplates(templates, "/org/eclipse/templates/default-templates.xml");
readIncludedTemplates(templates, "/org/eclipse/templates/default-codetemplates.xml");
return templates;
}
use of java.util.Collection in project che by eclipse.
the class ContributionTemplateStore method loadContributedTemplates.
/**
* Loads the templates contributed via the templates extension point.
*
* @throws IOException {@inheritDoc}
*/
protected void loadContributedTemplates() throws IOException {
// IConfigurationElement[] extensions= getTemplateExtensions();
Collection contributed = readContributedTemplates();
for (Iterator it = contributed.iterator(); it.hasNext(); ) {
TemplatePersistenceData data = (TemplatePersistenceData) it.next();
internalAdd(data);
}
}
Aggregations