Example usage for org.apache.solr.common.util NamedList clone

List of usage examples for org.apache.solr.common.util NamedList clone

Introduction

In this page you can find the example usage for org.apache.solr.common.util NamedList clone.

Prototype

@Override
public NamedList<T> clone() 

Source Link

Document

Makes a shallow copy of the named list.

Usage

From source file:com.pjaol.ESB.core.Controller.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override/*from www  .  j  ava 2 s  .com*/
public NamedList process(NamedList input) throws ModuleRunException {

    CountDownLatch start = new CountDownLatch(1);

    CountDownLatch stop = new CountDownLatch(pipes.size()) {
        @Override
        public boolean await(long timeout, TimeUnit unit) throws InterruptedException {

            return super.await(timeout, unit);
        }
    };

    TimerThread timer = new TimerThread(getTimeout(), getName(), "controller") {
        @Override
        public void timeout() {
            timeoutCountBean.inc(1);
            super.timeout();
            throw new RuntimeException("Timed out controller: " + getName());
        }
    };

    NamedList allOutput = new NamedList();
    List<ModuleRunner> moduleRunners = new ArrayList<ModuleRunner>();

    // Pipes have little to no value
    // TODO: should pipes be converted to run in parallel?

    for (String p : pipes) {

        // run each pipe in parallel
        List<String> pipeLinesToRun = pipelines.get(p);

        for (String pipename : pipeLinesToRun) {
            PipeLine pipeline = core.getPipeLineByName(pipename);

            // all pipelines should have a clean version of the input
            NamedList pipeLineInput = input.clone();

            ModuleRunner runner = new ModuleRunner(start, stop, pipeline, pipeLineInput, errorBean,
                    timeoutCountBean);
            executorService.execute(runner);
            moduleRunners.add(runner);

        }

        // The output of a pipeline should be added to
        // all output
        // allOutput.addAll(pipeLineOutput);

    }

    //
    // input.addAll(allOutput);

    if (_logger.isDebugEnabled())
        _logger.debug("******* Starting *******");

    long startT = System.currentTimeMillis();
    start.countDown();
    timer.start();

    try {
        executorService.shutdown();
        executorService.awaitTermination(getTimeout(), TimeUnit.MILLISECONDS);
        stop.await(getTimeout(), TimeUnit.MILLISECONDS);

    } catch (InterruptedException e) {
        // should really be thrown from the ModuleRunner method
        errorBean.inc(1);
        timeoutCountBean.inc(1);
        throw new ModuleRunException(e.getMessage());

    } finally {
        executorService.shutdownNow();
    }

    for (ModuleRunner runner : moduleRunners) {
        NamedList data = runner.getOutput();
        if (data != null)
            allOutput.addAll(data);
    }

    // System.out.println("Shutdown called with "+ allOutput+"::");

    long endT = System.currentTimeMillis();

    if (_logger.isDebugEnabled())
        _logger.debug("******* Shutting down ******* taken: " + (endT - startT) + " ms");

    // run limiters in serial
    if (limiterName != null) {
        // Input should be cloned and output added from previous pipelines
        NamedList limiterOutput = new NamedList();
        input.addAll(allOutput);
        NamedList limiterInput = input.clone();

        for (String pipeLine : limiterPipeLines) {

            PipeLine p = core.getPipeLineByName(pipeLine);
            try {
                // TODO: do i want to set this exclusively ?
                limiterOutput.addAll(p.process(limiterInput));
            } catch (Exception e) {
                errorBean.inc(1);
                throw new ModuleRunException(e.getMessage());
            }
        }

        allOutput = limiterOutput;
    }

    long timeTaken = endT - startT;

    timer.halt();
    allOutput.add("QTime", timeTaken);
    performanceBean.inc(Long.valueOf(endT - startT).intValue()); // log the
    // time
    errorBean.incCardinal(); // allow averages be calculated against all
    // requests
    timeoutCountBean.incCardinal();

    return allOutput;
}