use of clojure.lang.Keyword in project storm by apache.
the class Utils method convertClojureMapToJavaMap.
/**
* converts a clojure PersistentMap to java HashMap
*/
public static Map<String, Object> convertClojureMapToJavaMap(Map map) {
Map<String, Object> ret = new HashMap<>(map.size());
for (Object obj : map.entrySet()) {
Map.Entry entry = (Map.Entry) obj;
Keyword keyword = (Keyword) entry.getKey();
String key = keyword.getName();
if (key.startsWith(":")) {
key = key.substring(1, key.length());
}
Object value = entry.getValue();
ret.put(key, value);
}
return ret;
}
use of clojure.lang.Keyword in project fluxgraph by datablend.
the class FluxIndex method count.
public long count(final String key, final Object value) {
boolean matched = ((indexKeys == null) || ((indexKeys != null) && indexKeys.contains(key)));
Keyword attribute = null;
if ((this.getIndexClass().isAssignableFrom(FluxEdge.class)) && ("label".equals(key))) {
attribute = Keyword.intern("graph.edge/label");
} else {
attribute = FluxUtil.createKey(key, value.getClass(), clazz);
}
if (matched && FluxUtil.existingAttributeDefinition(attribute, graph)) {
if (this.getIndexClass().isAssignableFrom(FluxVertex.class)) {
return getElements(attribute, value, Keyword.intern("graph.element.type/vertex"), getDatabase()).size();
}
if (this.getIndexClass().isAssignableFrom(FluxEdge.class)) {
return getElements(attribute, value, Keyword.intern("graph.element.type/edge"), getDatabase()).size();
}
throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE);
} else {
return 0;
}
}
use of clojure.lang.Keyword in project fluxgraph by datablend.
the class FluxIndex method get.
public CloseableIterable<T> get(final String key, final Object value) {
boolean matched = ((indexKeys == null) || ((indexKeys != null) && indexKeys.contains(key)));
Keyword attribute = null;
if ((this.getIndexClass().isAssignableFrom(FluxEdge.class)) && ("label".equals(key))) {
attribute = Keyword.intern("graph.edge/label");
} else {
attribute = FluxUtil.createKey(key, value.getClass(), clazz);
}
if (matched && FluxUtil.existingAttributeDefinition(attribute, graph)) {
if (this.getIndexClass().isAssignableFrom(FluxVertex.class)) {
return new FluxIterable(getElements(attribute, value, Keyword.intern("graph.element.type/vertex"), getDatabase()), graph, database, Vertex.class);
}
if (this.getIndexClass().isAssignableFrom(FluxEdge.class)) {
return new FluxIterable(getElements(attribute, value, Keyword.intern("graph.element.type/edge"), getDatabase()), graph, database, Edge.class);
}
throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE);
} else {
if (this.getIndexClass().isAssignableFrom(FluxVertex.class)) {
return new FluxIterable(new ArrayList<List<Object>>(), graph, database, Vertex.class);
}
if (this.getIndexClass().isAssignableFrom(FluxEdge.class)) {
return new FluxIterable(new ArrayList<List<Object>>(), graph, database, Edge.class);
}
throw new RuntimeException(FluxGraph.DATOMIC_ERROR_EXCEPTION_MESSAGE);
}
}
use of clojure.lang.Keyword in project http-kit by http-kit.
the class AsyncChannel method writeChunk.
// for streaming, send a chunk of data to client
private void writeChunk(Object body, boolean close) throws IOException {
if (body instanceof Map) {
// only get body if a map
body = ((Map<Keyword, Object>) body).get(BODY);
}
if (body != null) {
// null is ignored
ByteBuffer t = bodyBuffer(body);
if (t.hasRemaining()) {
ByteBuffer[] buffers = new ByteBuffer[] { chunkSize(t.remaining()), // actual data
t, // terminating CRLF sequence
ByteBuffer.wrap(newLineBytes) };
server.tryWrite(key, !close, buffers);
}
}
if (close) {
serverClose(0);
}
}
use of clojure.lang.Keyword in project storm by nathanmarz.
the class ClojureBolt method prepare.
@Override
public void prepare(final Map stormConf, final TopologyContext context, final OutputCollector collector) {
IFn hof = Utils.loadClojureFn(_fnSpec.get(0), _fnSpec.get(1));
try {
IFn preparer = (IFn) hof.applyTo(RT.seq(_params));
final Map<Keyword, Object> collectorMap = new PersistentArrayMap(new Object[] { Keyword.intern(Symbol.create("output-collector")), collector, Keyword.intern(Symbol.create("context")), context });
List<Object> args = new ArrayList<Object>() {
{
add(stormConf);
add(context);
add(collectorMap);
}
};
_bolt = (IBolt) preparer.applyTo(RT.seq(args));
//this is kind of unnecessary for clojure
try {
_bolt.prepare(stormConf, context, collector);
} catch (AbstractMethodError ame) {
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations