Search in sources :

Example 11 with Keyword

use of clojure.lang.Keyword in project storm by apache.

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)

Example 12 with Keyword

use of clojure.lang.Keyword in project storm by apache.

the class ClojureSpout method open.

@Override
public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector 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(conf);
                add(context);
                add(collectorMap);
            }
        };
        _spout = (ISpout) preparer.applyTo(RT.seq(args));
        //this is kind of unnecessary for clojure
        try {
            _spout.open(conf, 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)

Example 13 with Keyword

use of clojure.lang.Keyword in project http-kit by http-kit.

the class AsyncChannel method firstWrite.

// Write first HTTP header and [first chunk data]? to client
private void firstWrite(Object data, boolean close) throws IOException {
    ByteBuffer[] buffers;
    int status = 200;
    Object body = data;
    HeaderMap headers;
    if (data instanceof Map) {
        Map<Keyword, Object> resp = (Map<Keyword, Object>) data;
        headers = HeaderMap.camelCase((Map) resp.get(HEADERS));
        status = getStatus(resp);
        body = resp.get(BODY);
    } else {
        headers = new HeaderMap();
    }
    if (headers.isEmpty()) {
        // default 200 and text/html
        headers.put("Content-Type", "text/html; charset=utf-8");
    }
    if (request.isKeepAlive && request.version == HttpVersion.HTTP_1_0) {
        headers.put("Connection", "Keep-Alive");
    }
    if (close) {
        // normal response, Content-Length. Every http client understand it
        buffers = HttpEncode(status, headers, body);
    } else {
        if (request.version == HttpVersion.HTTP_1_1) {
            // first chunk
            headers.put("Transfer-Encoding", "chunked");
        }
        ByteBuffer[] bb = HttpEncode(status, headers, body);
        if (body == null) {
            buffers = bb;
        } else {
            buffers = new ByteBuffer[] { // header
            bb[0], // chunk size
            chunkSize(bb[1].remaining()), // chunk data
            bb[1], // terminating CRLF sequence
            ByteBuffer.wrap(newLineBytes) };
        }
    }
    if (close) {
        onClose(0);
    }
    server.tryWrite(key, !close, buffers);
}
Also used : HeaderMap(org.httpkit.HeaderMap) Keyword(clojure.lang.Keyword) ByteBuffer(java.nio.ByteBuffer) HeaderMap(org.httpkit.HeaderMap) Map(java.util.Map)

Example 14 with Keyword

use of clojure.lang.Keyword in project storm by nathanmarz.

the class ClojureSpout method open.

@Override
public void open(final Map conf, final TopologyContext context, final SpoutOutputCollector 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(conf);
                add(context);
                add(collectorMap);
            }
        };
        _spout = (ISpout) preparer.applyTo(RT.seq(args));
        //this is kind of unnecessary for clojure
        try {
            _spout.open(conf, 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