Examples of IFn


Examples of clojure.lang.IFn

        }
    }

    @Override
    public Map<String, Object> getComponentConfiguration() {
        IFn hof = Utils.loadClojureFn(_confSpec.get(0), _confSpec.get(1));
        try {
            return (Map) hof.applyTo(RT.seq(_params));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of clojure.lang.IFn

    }
   

    @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) {
               
View Full Code Here

Examples of clojure.lang.IFn

        }
    }
   
    @Override
    public Map<String, Object> getComponentConfiguration() {
        IFn hof = Utils.loadClojureFn(_confSpec.get(0), _confSpec.get(1));
        try {
            return (Map) hof.applyTo(RT.seq(_params));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of clojure.lang.IFn

                 
                  if (monitor != null) {
                    // Thread watching user cancellation requests
                    new Thread(new Runnable() {
                @Override public void run() {
                  IFn realized = Clojure.var("clojure.core", "realized?");
                  while (true) {
                    if ((Boolean) realized.invoke(replURLPromise)) {
                      // repl promise has been delivered
                      return;
                    }
                    if (getResult() != null) {
                      // Job has finished
                      return;
                    }
                    if (monitor.isCanceled()) {
                      IFn deliver = Clojure.var("clojure.core", "deliver");
                      deliver.invoke(replURLPromise, cancelObject);
                      return;
                    }
                    try {
                      Thread.sleep(100);
                    } catch (InterruptedException e) {
                      CCWPlugin.logError("Error in the thread monitoring user cancellation for REPL launch of " + launchName, e);
                      return;
                    }
                  }
                }}).start();
                  }
                 
                  IFn deref = Clojure.var("clojure.core", "deref");
                  Object timeOutObject = new Object();
                  Object replURL = (Object) deref.invoke(replURLPromise, REPL_START_TIMEOUT_MS, timeOutObject);
                 
                  if (replURL == timeOutObject) {
                          CCWPlugin.logError("Waiting for new REPL process ack timed out");
                          return CCWPlugin.createErrorStatus("Waiting for new REPL process ack timed out");
                  } else if (replURL == cancelObject) {
View Full Code Here

Examples of clojure.lang.IFn

            throw new RuntimeException(e);
        }
    }
   
    private Object promise() {
      IFn promise = clojure.java.api.Clojure.var("clojure.core", "promise");
      return promise.invoke();
    }
View Full Code Here

Examples of clojure.lang.IFn

  @Test
  public void testSimpleFnOutofCoroutine() {
    RT.var("clojure.core", "require").invoke(Symbol.create("nginx.clojure.fns-for-test"));
//    System.out.println("rq cl :" + rq.getClass().getClassLoader());
    final IFn  fn = (IFn)RT.var("nginx.clojure.fns-for-test", "fn-out-of-coroutine").fn();
    fn.invoke(messages);
    assertEquals(4, messages.size());
    assertEquals("entering fn-out-of-coroutine", messages.get(0));
    for (int i = 0; i < 3; i++) {
      assertEquals("echo:" + i, messages.get(i+1));
    }
View Full Code Here

Examples of clojure.lang.IFn

 
  @Test
  public void testSimpleFn() {
    RT.var("clojure.core", "require").invoke(Symbol.create("nginx.clojure.fns-for-test"));
//    System.out.println("rq cl :" + rq.getClass().getClassLoader());
    final IFn  fn = (IFn)RT.var("nginx.clojure.fns-for-test", "simplefn").fn();
    Coroutine cr = new Coroutine(new Runnable() {
      @Override
      public void run() throws SuspendExecution {
        fn.invoke(messages);
      }
    });
   
    cr.resume();
    assertEquals(1, messages.size());
View Full Code Here

Examples of clojure.lang.IFn

  @Test
  public void testReduce() {
    for (int k = 0; k < 10; k++) {
      RT.var("clojure.core", "require").invoke(Symbol.create("nginx.clojure.fns-for-test"));
//      System.out.println("rq cl :" + rq.getClass().getClassLoader());
      final IFn  fn = (IFn)RT.var("nginx.clojure.fns-for-test", "coreduce-test").fn();
      ArrayList<Long> ma = new ArrayList<Long>();
      Coroutine cr = (Coroutine)fn.invoke(ma);
      cr.resume();
      for (int i = 0; i < 4; i++) {
        cr.resume();
      }
      assertEquals(25L, (Number)ma.get(0));
View Full Code Here

Examples of clojure.lang.IFn

  }
 
  @Test
  public void testBinding() {
    RT.var("clojure.core", "require").invoke(Symbol.create("nginx.clojure.fns-for-test"));
    IFn  cafn = (IFn)RT.var("nginx.clojure.fns-for-test", "ca").fn();
    IFn  cbfn = (IFn)RT.var("nginx.clojure.fns-for-test", "cb").fn();
    ArrayList<String> ma = new ArrayList<String>();
    Coroutine ca = (Coroutine) cafn.invoke(ma);
    ArrayList<String> mb = new ArrayList<String>();
    Coroutine cb = (Coroutine) cbfn.invoke(mb);
    ca.resume();
    cb.resume();
    assertTrue(ma.isEmpty());
    assertTrue(mb.isEmpty());
    ca.resume();
View Full Code Here

Examples of clojure.lang.IFn

      }else {
        code = name;
      }
     
    }
    IFn f = (IFn)RT.var("clojure.core", "eval").invoke(RT.var("clojure.core","read-string").invoke(code));
    return new NginxClojureHandler(f);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.