use of java.util.LinkedHashSet in project zipkin by openzipkin.
the class NativeClient method bulkSpanIndexer.
@Override
protected BulkSpanIndexer bulkSpanIndexer() {
return new SpanBytesBulkSpanIndexer() {
final List<IndexRequestBuilder> indexRequests = new LinkedList<>();
final Set<String> indicesToFlush = new LinkedHashSet<>();
@Override
protected void add(String index, byte[] spanBytes) {
indexRequests.add(client.prepareIndex(index, SPAN).setSource(spanBytes));
if (flushOnWrites)
indicesToFlush.add(index);
}
// Creates a bulk request when there is more than one span to store
@Override
public void execute(final Callback<Void> callback) {
ActionListener callbackAdapter = new ActionListener() {
@Override
public void onResponse(Object input) {
callback.onSuccess(null);
}
@Override
public void onFailure(Throwable throwable) {
callback.onError(throwable);
}
};
// Conditionally create a bulk action depending on the count of index requests
ListenableActionFuture<? extends ActionResponse> future;
if (indexRequests.size() == 1) {
future = indexRequests.get(0).execute();
} else {
BulkRequestBuilder request = client.prepareBulk();
for (IndexRequestBuilder span : indexRequests) {
request.add(span);
}
future = request.execute();
}
// Unless we are in a unit test, this should always be true
if (indicesToFlush.isEmpty()) {
future.addListener(callbackAdapter);
return;
}
// If we are in a unit test, we need to flush so that we can read our writes
future.addListener(new ActionListener() {
@Override
public void onResponse(Object input) {
client.admin().indices().prepareFlush(indicesToFlush.toArray(new String[indicesToFlush.size()])).execute().addListener(callbackAdapter);
}
@Override
public void onFailure(Throwable throwable) {
callbackAdapter.onFailure(throwable);
}
});
}
};
}
use of java.util.LinkedHashSet in project jodd by oblac.
the class MixTest method testCollections.
@Test
public void testCollections() {
List list1 = TypeConverterManager.convertType(arri(1, 2, 3), List.class);
assertEquals(listo(1, 2, 3), list1);
list1 = TypeConverterManager.convertType("1,2,3", List.class);
assertEquals(listo("1", "2", "3"), list1);
Set set1 = TypeConverterManager.convertType(arrl(1, 2, 3), LinkedHashSet.class);
assertTrue(set1 instanceof LinkedHashSet);
Iterator i = set1.iterator();
assertEquals(Long.valueOf(1), i.next());
assertEquals(Long.valueOf(2), i.next());
assertEquals(Long.valueOf(3), i.next());
list1 = TypeConverterManager.convertType("hello", List.class);
assertEquals(listo("hello"), list1);
list1 = TypeConverterManager.convertType(Long.valueOf(4), List.class);
assertEquals(listo(Long.valueOf(4)), list1);
}
use of java.util.LinkedHashSet in project jodd by oblac.
the class DbOomQuery method listSet.
@SuppressWarnings({ "unchecked" })
protected <T> Set<T> listSet(Class[] types, int max, boolean close) {
Set<T> result = new LinkedHashSet<>(initialCollectionSize(max));
ResultSetMapper rsm = executeAndBuildResultSetMapper();
if (types == null) {
types = rsm.resolveTables();
}
Object previousElement = null;
while (rsm.next()) {
Object[] objects = rsm.parseObjects(types);
Object row = resolveRowResults(objects);
int size = result.size();
T newElement = (T) row;
if (entityAwareMode && size > 0) {
if (previousElement != null && newElement != null) {
boolean equals;
if (newElement.getClass().isArray()) {
equals = Arrays.equals((Object[]) previousElement, (Object[]) newElement);
} else {
equals = previousElement.equals(newElement);
}
if (equals) {
continue;
}
}
}
if (size == max) {
break;
}
result.add(newElement);
previousElement = newElement;
}
close(rsm, close);
return result;
}
use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class UpgradeStepProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.processingOver()) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(UpgradeStepInfo.class);
for (Element element : elements) {
Set<DependencyInfo> depends = new LinkedHashSet<DependencyInfo>(2);
String annotatedType = element.asType().toString();
UpgradeStepInfo annotation = element.getAnnotation(UpgradeStepInfo.class);
for (String name : annotation.dependsOn()) {
DependencyInfo depInfo = stepMappings.get(name);
if (depInfo == null) {
depInfo = new DependencyInfo(name);
stepMappings.put(name, depInfo);
}
depends.add(depInfo);
}
DependencyInfo depInfo = stepMappings.get(annotatedType);
if (depInfo == null) {
depInfo = new DependencyInfo(annotatedType);
stepMappings.put(annotatedType, depInfo);
}
for (DependencyInfo dep : depends) {
depInfo.dependencies.add(dep);
}
}
createDAG();
}
return true;
}
use of java.util.LinkedHashSet in project OpenAM by OpenRock.
the class SiteConfiguration method getSiteInfo.
private static Set getSiteInfo(ServiceConfig rootNode, String name) throws SMSException, SSOException {
Set info = new LinkedHashSet();
ServiceConfig sc = rootNode.getSubConfig(name);
ServiceConfig accessPoint = sc.getSubConfig(SUBCONFIG_ACCESS_URL);
Map map = accessPoint.getAttributes();
Set setId = (Set) map.get(ATTR_PRIMARY_SITE_ID);
Set setURL = (Set) map.get(ATTR_PRIMARY_SITE_URL);
if ((setId != null) && (!setId.isEmpty()) && (setURL != null) && (!setURL.isEmpty())) {
info.add(NormalizedURL.normalize((String) setURL.iterator().next()) + "|" + (String) setId.iterator().next());
}
Set secURLs = accessPoint.getSubConfigNames("*");
if ((secURLs != null) && !secURLs.isEmpty()) {
for (Iterator i = secURLs.iterator(); i.hasNext(); ) {
String secName = (String) i.next();
ServiceConfig s = accessPoint.getSubConfig(secName);
Map mapValues = s.getAttributes();
setId = (Set) mapValues.get(ATTR_SEC_ID);
info.add(NormalizedURL.normalize(secName) + "|" + (String) setId.iterator().next());
}
}
return info;
}
Aggregations