Example usage for io.netty.util.concurrent ImmediateEventExecutor INSTANCE

List of usage examples for io.netty.util.concurrent ImmediateEventExecutor INSTANCE

Introduction

In this page you can find the example usage for io.netty.util.concurrent ImmediateEventExecutor INSTANCE.

Prototype

ImmediateEventExecutor INSTANCE

To view the source code for io.netty.util.concurrent ImmediateEventExecutor INSTANCE.

Click Source Link

Usage

From source file:biz.paluch.spinach.support.TestEventLoopGroupProvider.java

License:Apache License

@Override
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout,
        TimeUnit unit) {//  w w w.j a v a  2  s.  co  m
    DefaultPromise<Boolean> result = new DefaultPromise<Boolean>(ImmediateEventExecutor.INSTANCE);
    result.setSuccess(true);

    return result;
}

From source file:com.addthis.hydra.data.query.op.OpGroupBy.java

License:Apache License

/**
 * Generate new promise for the child operation.
 *
 * @param opPromise promise of the 'groupby' query operation
 *
 * @return generated promise/* www . jav a2s  .c o m*/
 */
private ChannelProgressivePromise generateNewPromise(ChannelProgressivePromise opPromise) {
    final ChannelProgressivePromise result;
    if (opPromise.channel() == null) {
        result = new DefaultChannelProgressivePromise(null, ImmediateEventExecutor.INSTANCE);
    } else {
        result = opPromise.channel().newProgressivePromise();
    }
    result.addListener(errorForwarder);
    return result;
}

From source file:com.addthis.hydra.data.query.source.LiveQueryReference.java

License:Apache License

@Override
public VirtualFileInput getInput(Map<String, String> options) {
    try {//from ww w  .  j  av  a  2 s .c o m
        // ideally the channel here would be some kind of meshy construct, but null should
        // be fine for now -- we never call await/sync etc in the worker
        final DataChannelToInputStream bridge = new DataChannelToInputStream(
                new DefaultChannelProgressivePromise(null, ImmediateEventExecutor.INSTANCE));
        if (options == null) {
            log.warn("Invalid request to getInput.  Options cannot be null");
            return null;
        }
        SearchRunner.querySearchPool.execute(new LiveSearchRunner(options, dirString, bridge, queryEngine));
        return bridge;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.addthis.hydra.data.query.source.QueryReference.java

License:Apache License

/**
 * Submits the query to the query search pool as a SearchRunner and creates the bridge that will
 * hand the query response data to meshy.
 *
 * @param options/*from w w  w .  java  2  s.  co m*/
 * @return the response bridge (DataChannelToInputStream)
 */
@Override
public VirtualFileInput getInput(Map<String, String> options) {
    try {
        // ideally the channel here would be some kind of meshy construct, but null should
        // be fine for now -- we never call await/sync etc in the worker
        final DataChannelToInputStream bridge = new DataChannelToInputStream(
                new DefaultChannelProgressivePromise(null, ImmediateEventExecutor.INSTANCE));
        if (options == null) {
            log.warn("Invalid request to getInput.  Options cannot be null");
            return null;
        }
        final String flag = options.get("flag");
        if (flag != null) {
            if (flag.equals("die")) {
                System.exit(1);
            } else if (flag.equals("DIE")) {
                Runtime.getRuntime().halt(1);
            }
        }
        SearchRunner.querySearchPool.execute(new SearchRunner(options, dirString, bridge));
        return bridge;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.addthis.hydra.data.query.source.SearchRunner.java

License:Apache License

/**
 * Part 1 - SETUP/*  ww w .j  a  va2  s .com*/
 * Initialize query run -- parse options, create Query object
 */
protected void setup() throws Exception {
    long startTime = System.currentTimeMillis();
    MeshQuerySource.queueTimes.update(creationTime - startTime, TimeUnit.MILLISECONDS);
    query = CodecJSON.decodeString(new Query(), options.get("query"));
    // set as soon as possible (and especially before creating op processor)
    query.queryPromise = bridge.queryPromise;
    // Parse the query and return a reference to the last QueryOpProcessor.
    ChannelProgressivePromise opPromise = new DefaultChannelProgressivePromise(null,
            ImmediateEventExecutor.INSTANCE);
    queryOpProcessor = query.newProcessor(bridge, opPromise);
}

From source file:com.addthis.hydra.query.util.QueryChannelUtil.java

License:Apache License

/** */
private static void runQuery(String[] args) throws Exception {
    HashMap<String, String> qparam = new HashMap<>();
    String sep = null;/*from w w  w  .  j  a  va  2s .c  o  m*/
    boolean quiet = false;
    boolean traced = false;
    int iter = 1;
    ArrayList<String> paths = new ArrayList<>(1);
    ArrayList<String> ops = new ArrayList<>(1);
    ArrayList<String> lops = new ArrayList<>(1);
    String job = null;
    String data = null;
    String out = null;
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        int eqpos;
        if (arg.equals("help")) {
            System.out.println(
                    "job=[job] path=[path] ops=[ops] lops=[lops] data=[datadir] [iter=#] [quiet] [sep=separator] [out=file] [trace] [param=val]");
            return;
        }
        if (arg.equals("trace")) {
            traced = true;
        } else if (arg.equals("quiet")) {
            quiet = true;
        } else if (arg.equals("csv")) {
            sep = ",";
        } else if (arg.equals("tsv")) {
            sep = "\t";
        } else if (arg.startsWith("sep=")) {
            sep = arg.substring(4);
        } else if (arg.startsWith("iter=")) {
            iter = Integer.parseInt(arg.substring(5));
        } else if (arg.startsWith("lops=")) {
            lops.add(arg.substring(5));
        } else if (arg.startsWith("ops=")) {
            ops.add(arg.substring(4));
        } else if (arg.startsWith("job=")) {
            job = arg.substring(4);
        } else if (arg.startsWith("path=")) {
            paths.add(arg.substring(5));
        } else if (arg.startsWith("fpath=")) {
            paths.add(Bytes.toString(Files.read(new File(arg.substring(6)))).trim());
        } else if (arg.startsWith("data=")) {
            data = arg.substring(5);
        } else if (arg.startsWith("out=")) {
            out = arg.substring(4);
        } else if ((eqpos = arg.indexOf("=")) > 0) {
            String key = arg.substring(0, eqpos);
            String val = arg.substring(eqpos + 1);
            qparam.put(key, val);
        }
    }
    Query query = new Query(job, paths.toArray(new String[paths.size()]), ops.toArray(new String[ops.size()]));
    query.setTraced(traced);
    for (Entry<String, String> e : qparam.entrySet()) {
        query.setParameter(e.getKey(), e.getValue());
    }
    if (!quiet) {
        System.out.println(">>> query " + query);
    }
    QuerySource client;
    if (data != null) {
        final File dir = new File(data);
        client = new QueryEngineSource() {
            @Override
            public QueryEngine getEngineLease() {
                try {
                    return new QueryEngine(new ReadTree(dir));
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        };
    } else {
        throw new RuntimeException("no data directory specified");
    }

    while (iter-- > 0) {
        long start = System.currentTimeMillis();
        File tempDir = Files.createTempDir();
        BlockingNullConsumer consumer = new BlockingNullConsumer();
        QueryOpProcessor proc = new QueryOpProcessor.Builder(consumer, lops.toArray(new String[lops.size()]))
                .tempDir(tempDir).build();
        proc.appendOp(new BundleOutputWrapper(new PrintOp(sep, out),
                new DefaultChannelProgressivePromise(null, ImmediateEventExecutor.INSTANCE)));
        client.query(query, proc);
        consumer.waitComplete();
        Files.deleteDir(tempDir);
        if (!quiet) {
            System.out.println(
                    ">>> done " + proc + " in " + ((System.currentTimeMillis() - start) / 1000.0) + " sec");
        }
    }
    System.exit(0);
}

From source file:com.addthis.hydra.task.output.tree.PathOutput.java

License:Apache License

public void exec(DataTree tree) {
    synchronized (this) {
        if (engine == null) {
            engine = new QueryEngine(tree);
        }/*ww w.  ja va 2s.  co  m*/
    }
    QueryOpProcessor rp = new QueryOpProcessor.Builder(output, opsString).memTip(maxmem).build();
    if (ops != null) {
        for (QueryOp op : ops) {
            rp.appendOp(op);
        }
    }
    rp.appendOp(new OutputOp(rp));
    try {
        output.open();
        engine.search(query, rp, new DefaultChannelProgressivePromise(null, ImmediateEventExecutor.INSTANCE));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        output.sendComplete();
    }
}

From source file:com.addthis.meshy.AggregateChannelFuture.java

License:Apache License

AggregateChannelFuture(Collection<ChannelFuture> futures) {
    this(futures, ImmediateEventExecutor.INSTANCE);
}

From source file:com.caricah.iotracah.server.netty.channelgroup.IotChannelGroupFuture.java

License:Apache License

@Override
protected void checkDeadLock() {
    EventExecutor e = executor();/*from www .  j av  a2s  . c  o  m*/
    if (e != null && e != ImmediateEventExecutor.INSTANCE && e.inEventLoop()) {
        throw new BlockingOperationException();
    }
}

From source file:com.cloudera.livy.client.local.rpc.Rpc.java

License:Apache License

@VisibleForTesting
static Rpc createEmbedded(RpcDispatcher dispatcher) {
    EmbeddedChannel c = new EmbeddedChannel(new LoggingHandler(Rpc.class),
            new KryoMessageCodec(0, MessageHeader.class, NullMessage.class), dispatcher);
    Rpc rpc = new Rpc(new LocalConf(null), c, ImmediateEventExecutor.INSTANCE);
    rpc.dispatcher = dispatcher;//from  w w w . ja  v a 2  s  .  c o  m
    return rpc;
}