Search in sources :

Example 1 with Keyword

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;
}
Also used : Entry(java.util.Map.Entry) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) JarEntry(java.util.jar.JarEntry) Keyword(clojure.lang.Keyword) HashMap(java.util.HashMap) ComponentObject(org.apache.storm.generated.ComponentObject) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 2 with Keyword

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;
    }
}
Also used : Keyword(clojure.lang.Keyword)

Example 3 with Keyword

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);
    }
}
Also used : Keyword(clojure.lang.Keyword) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with Keyword

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);
    }
}
Also used : Keyword(clojure.lang.Keyword) HeaderMap(org.httpkit.HeaderMap) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Keyword

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);
    }
}
Also used : IFn(clojure.lang.IFn) PersistentArrayMap(clojure.lang.PersistentArrayMap) Keyword(clojure.lang.Keyword) ArrayList(java.util.ArrayList)

Aggregations

Keyword (clojure.lang.Keyword)14 ArrayList (java.util.ArrayList)7 IFn (clojure.lang.IFn)6 PersistentArrayMap (clojure.lang.PersistentArrayMap)6 Map (java.util.Map)3 ByteBuffer (java.nio.ByteBuffer)2 HeaderMap (org.httpkit.HeaderMap)2 Entity (datomic.Entity)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 JarEntry (java.util.jar.JarEntry)1 ZipEntry (java.util.zip.ZipEntry)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 ComponentObject (org.apache.storm.generated.ComponentObject)1