当前位置: 首页>>代码示例>>Java>>正文


Java IFn类代码示例

本文整理汇总了Java中clojure.lang.IFn的典型用法代码示例。如果您正苦于以下问题:Java IFn类的具体用法?Java IFn怎么用?Java IFn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IFn类属于clojure.lang包,在下文中一共展示了IFn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onLoad

import clojure.lang.IFn; //导入依赖的package包/类
@Override
public void onLoad() {
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    instance = this;
    logger = getLogger();
    try (InputStream stream = getResource("clojure.yml")) {
        clojureConfig = YamlConfiguration.loadConfiguration(stream);
        mainNs = clojureConfig.getString("clojure");
        if (mainNs == null) {
            setEnabled(false);
            throw new RuntimeException("The plugin couldn't be enabled due to Clojure ns missing.");
        }
        require.invoke(Clojure.read(mainNs));
    } catch (IOException e) {
        e.printStackTrace();
    }

    IFn setData = Clojure.var(mainNs, "setData");
    if (setData == null) {
        setEnabled(false);
        throw new RuntimeException("The clojure plugin couldn't be enabled due to missing setData method.");
    }
    setData.invoke(this, getDataFolder(), getConfig(), getDescription(), getServer(), getLogger());
    callIfExists("onLoad");
}
 
开发者ID:Proximyst,项目名称:Bukkit4Clojure,代码行数:26,代码来源:Main.java

示例2: onCommand

import clojure.lang.IFn; //导入依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    IFn command = commands.get(cmd);
    if (command == null) {
        return true;
    }
    try {
        command.invoke(sender, command, label, args);
    } catch (Exception ex) {
        //noinspection ConstantConditions
        if (ex instanceof Return) {
            return true;
        }
        sender.sendMessage(ChatColor.RED + "An error occurred within the code. Ask an admin about the stacktrace.");
        getLogger().log(Level.SEVERE, "An error occurred!", ex);
    }
    return true;
}
 
开发者ID:Proximyst,项目名称:Bukkit4Clojure,代码行数:19,代码来源:Main.java

示例3: pipe

import clojure.lang.IFn; //导入依赖的package包/类
@Override
public Consumer<String> pipe( String command, PrintStream out, PrintStream err ) {
    @Nullable Object fn = runCommand( command, out, err );

    if ( fn instanceof IFn ) {
        return ( line ) -> {
            @Nullable Object result = ( ( IFn ) fn ).invoke( line );
            if ( result != null ) {
                out.println( result );
            }
        };
    }

    throw new RuntimeException( "When used in a pipeline, the Clojure script must return a " +
            "lambda that takes one text line of the input at a time.\n" +
            "Example:\nsome-command | clj (fn [line] (str \"- \" line))" );
}
 
开发者ID:renatoathaydes,项目名称:osgiaas,代码行数:18,代码来源:ClojureCommand.java

示例4: onPreInitialization

import clojure.lang.IFn; //导入依赖的package包/类
@EventHandler
public void onPreInitialization(FMLPreInitializationEvent event) {
	logger = event.getModLog();
	
	String path = "./mods/cljsh-mods/";
	File directory = new File(path);
	File[] fileListing = directory.listFiles();
	for (File file : fileListing) {
		if (file.isFile() && file.getName().endsWith(".mod.clj")) {
			String contents = "";
			try {
				contents = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			IFn mainFunction = (IFn) execute(contents);

			mainFunction.invoke(this);
			
			logger.info("Cljsh sucsessfully loaded " + file.getName());
		}
	}
}
 
开发者ID:setupminimal,项目名称:Cljsh,代码行数:26,代码来源:Cljsh.java

示例5: expectationsRunner

import clojure.lang.IFn; //导入依赖的package包/类
@Test
public void expectationsRunner() {
    try {
        IFn require = Clojure.var("clojure.core", "require");
        require.invoke(Clojure.read("expectations"));
        IFn disableRun = Clojure.var("expectations", "disable-run-on-shutdown");
        disableRun.invoke();

        List<Symbol> namespaces = Util.importNsDeclarations(TestRunner.getTestNamespaces());
        Util.tryInitNeko();

        IFn runTests = Clojure.var("expectations", "run-all-tests");
        Object result = runTests.invoke();

        IFn shutdownAgents = Clojure.var("clojure.core", "shutdown-agents");
        shutdownAgents.invoke();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:clojure-android,项目名称:droid-test,代码行数:21,代码来源:ExpectationsWrapper.java

示例6: specljRunner

import clojure.lang.IFn; //导入依赖的package包/类
@Test
public void specljRunner() {
    try {
        List<Symbol> namespaces = Util.importNsDeclarations(TestRunner.getTestNamespaces());
        Util.tryInitNeko();

        IFn require = Clojure.var("clojure.core", "require");

        require.invoke(Clojure.read("speclj.cli"));
        require.invoke(Clojure.read("speclj.run.standard"));

        IFn runSpecs = Clojure.var("speclj.run.standard", "run-specs");
        runSpecs.invoke();

        IFn shutdownAgents = Clojure.var("clojure.core", "shutdown-agents");
        shutdownAgents.invoke();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:clojure-android,项目名称:droid-test,代码行数:21,代码来源:SpecljWrapper.java

示例7: nreplStarter

import clojure.lang.IFn; //导入依赖的package包/类
@Test
public void nreplStarter() {
    try {
        Util.importNsDeclarations(TestRunner.getTestNamespaces());
        Util.tryInitNeko();

        IFn require = Clojure.var("clojure.core", "require");
        require.invoke(Clojure.read("clojure.tools.nrepl.server"));
        IFn startServer = Clojure.var("clojure.tools.nrepl.server",
                                      "start-server");
        startServer.invoke(Clojure.read(":port"), 8888);
        System.out.println("Started nREPL server on port " + 8888);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:clojure-android,项目名称:droid-test,代码行数:17,代码来源:ReplWrapper.java

示例8: prepare

import clojure.lang.IFn; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:26,代码来源:ClojureBolt.java

示例9: open

import clojure.lang.IFn; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:26,代码来源:ClojureSpout.java

示例10: reduce

import clojure.lang.IFn; //导入依赖的package包/类
@Override
public Object reduce(Object o, Iterator<Object> objectIterator) {

    if(fn == null) {
        IFn require = Clojure.var("clojure.core", "require");
        require.invoke(Clojure.read(ns));
        fn = Clojure.var(ns, sym);
    }

    Object result = seed;
    while(objectIterator.hasNext()){
        Object x = objectIterator.next();
        result = fn.invoke(o, result, x);
    }
    return result;
}
 
开发者ID:danstone,项目名称:immutant-mr,代码行数:17,代码来源:InfinispanReducer.java

示例11: map

import clojure.lang.IFn; //导入依赖的package包/类
public void map(Object key, Object value, Collector<Object, Object> collector){

        if(fn == null) {
            IFn require = Clojure.var("clojure.core", "require");
            require.invoke(Clojure.read(ns));
            fn = Clojure.var(ns, sym);
        }

        for (Object o : (Iterable)fn.invoke(key, value)){
            Seqable s = (Seqable)o;
            ISeq seq = s.seq();
            Object k = seq.first();
            Object v = seq.next().first();
            collector.emit(k, v);
        }
    }
 
开发者ID:danstone,项目名称:immutant-mr,代码行数:17,代码来源:InfinispanMapper.java

示例12: serverClose

import clojure.lang.IFn; //导入依赖的package包/类
public boolean serverClose(int status) {
    if (!unsafe.compareAndSwapInt(this, closedRanOffset, 0, 1)) {
        return false; // already closed
    }
    if (isWebSocket()) {
        server.tryWrite(key, WsEncode(OPCODE_CLOSE, ByteBuffer.allocate(2)
                .putShort((short) status).array()));
    } else {
        server.tryWrite(key, ByteBuffer.wrap(finalChunkBytes));
    }
    IFn f = closeHandler;
    if (f != null) {
        f.invoke(readable(0)); // server close is 0
    }
    return true;
}
 
开发者ID:nLight,项目名称:jruby-http-kit,代码行数:17,代码来源:AsyncChannel.java

示例13: loadClojureFn

import clojure.lang.IFn; //导入依赖的package包/类
private static void loadClojureFn() {
    ClassLoader previous = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(IcepickProcessor.class.getClassLoader());
    try {
        Object ns = Clojure.read("icepick.processor");
        IFn require = Clojure.var("clojure.core", "require");
        require.invoke(ns);
        PROCESS = Clojure.var("icepick.processor", "process");
    } finally {
        Thread.currentThread().setContextClassLoader(previous);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:IcepickProcessor.java

示例14: callIfExists

import clojure.lang.IFn; //导入依赖的package包/类
public void callIfExists(String namespace, String name, Object... args) {
    require.invoke(namespace);
    IFn method = Clojure.var(namespace, name);
    if (method != null) {
        if (args != null && args.length != 0) {
            method.invoke(args);
        } else {
            method.invoke();
        }
    }
}
 
开发者ID:Proximyst,项目名称:Bukkit4Clojure,代码行数:12,代码来源:Main.java

示例15: registerEvent

import clojure.lang.IFn; //导入依赖的package包/类
@SuppressWarnings({"WeakerAccess", "SameParameterValue"})
public void registerEvent(final Class<? extends Event> event, final EventPriority priority, final IFn method, final boolean ignoreCancelled) {
    Set<IFn> methods = events.getOrDefault(event, new HashSet<>());
    methods.add(method);
    events.put(event, methods);
    getServer().getPluginManager().registerEvent(event, new Listener() {
    }, priority, executor, this, ignoreCancelled);
}
 
开发者ID:Proximyst,项目名称:Bukkit4Clojure,代码行数:9,代码来源:Main.java


注:本文中的clojure.lang.IFn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。