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


Java Util.keyPress方法代码示例

本文整理汇总了Java中org.jgroups.util.Util.keyPress方法的典型用法代码示例。如果您正苦于以下问题:Java Util.keyPress方法的具体用法?Java Util.keyPress怎么用?Java Util.keyPress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jgroups.util.Util的用法示例。


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

示例1: start

import org.jgroups.util.Util; //导入方法依赖的package包/类
public void start(String props, String name, boolean unicast) throws Exception {
    ch=new JChannel(props);
    if(name != null)
        ch.setName(name);
    ch.setReceiver(this);
    ch.connect("ping");

    while(true) {
        Util.keyPress("enter to ping");
        Address dest=null;
        if(unicast)
            dest=(Address)Util.pickRandomElement(members);
        
        Message msg=new Message(dest, null, PING_REQ);
        msg.setFlag(Message.Flag.DONT_BUNDLE, Message.NO_FC);
        start=System.nanoTime();
        ch.send(msg);
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:20,代码来源:PingPong.java

示例2: loop

import org.jgroups.util.Util; //导入方法依赖的package包/类
protected void loop() {
    int c;

    final String INPUT="[1] Send [x] Exit";

    while(looping) {
        try {
            c=Util.keyPress(String.format(INPUT));
            switch(c) {
                case '1':
                    sendMessages();
                    break;
                case 'x':
                    looping=false;
                    break;
            }
        }
        catch(Throwable t) {
            System.err.println(t);
        }
    }
    stop();
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:24,代码来源:UdpPerf.java

示例3: start

import org.jgroups.util.Util; //导入方法依赖的package包/类
public void start() throws Exception {
    mcast_sock=new MulticastSocket(7500);
    mcast_sock.joinGroup(MCAST_GROUP, NetworkInterface.getByName("192.168.1.5"));

    Receiver receiver=new Receiver();
    receiver.start();

    while(true) {
        Util.keyPress("enter to ping");
        DatagramPacket packet=new DatagramPacket(PING_REQ, 0, PING_REQ.length, MCAST_GROUP);
        start=System.nanoTime();
        mcast_sock.send(packet);
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:15,代码来源:PingPongDatagram.java

示例4: start

import org.jgroups.util.Util; //导入方法依赖的package包/类
protected void start(InetAddress host, boolean direct, int num_threads) throws Exception {
    boolean looping=true;
    while(looping) {
        int c=Util.keyPress("[1] send [x] exit");
        switch(c) {
            case '1':
                sendMessages(host, direct, num_threads);
                break;
            case 'x':
                looping=false;
                break;
        }
    }
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:15,代码来源:NioClient.java

示例5: main

import org.jgroups.util.Util; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String props="udp.xml";
    boolean migrate_data=false;

    for(int i=0; i < args.length; i++) {
        if(args[i].equals("-props")) {
            props=args[++i];
            continue;
        }
        if(args[i].equals("-migrate_data")) {
            migrate_data=true;
            continue;
        }
        help();
        return;
    }



    PartitionedHashMap<String,String> map=new PartitionedHashMap<>(props, "demo-cluster");
    Cache<String,String> l1_cache=new Cache<>();
    l1_cache.setMaxNumberOfEntries(5);
    l1_cache.disableReaping();
    map.setL1Cache(l1_cache);
    Cache<String, String> l2_cache=map.getL2Cache();
    l2_cache.enableReaping(10000);
    map.setMigrateData(migrate_data);
    map.start();

    while(true) {
        int ch=Util.keyPress("[1] put [2] get [3] remove [4] print [q] quit");

        switch(ch) {
            case '1':
                String key=readLine("key: ");
                String val=readLine("val: ");
                String caching_time=readLine("ttl: ");
                map.put(key, val, Long.parseLong(caching_time));
                break;
            case '2':
                key=readLine("key: ");
                val=map.get(key);
                System.out.println("val = " + val);
                break;
            case '3':
                key=readLine("key: ");
                map.remove(key);
                break;
            case '4':
                System.out.println("address: " + map.getLocalAddress());
                System.out.println("L1 cache:\n" + map.getL1Cache());
                System.out.println("L2 cache:\n" + map.getL2Cache());
                break;
            case 'q':
                l1_cache.stop();
                map.stop();
                return;
        }
    }

}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:62,代码来源:PartitionedHashMapDemo.java

示例6: loop

import org.jgroups.util.Util; //导入方法依赖的package包/类
void loop() throws Exception {
    CounterService counter_service=new CounterService(ch);
    ch.connect("counter-cluster");
    Counter counter=counter_service.getOrCreateCounter("mycounter", 1);

    boolean looping=true;
    while(looping) {
        try {
            int key=Util.keyPress("[1] Increment [2] Decrement [3] Compare and set\n" +
                                    "[4] Create counter [5] Delete counter\n" +
                                    "[6] Print counters [7] Get counter\n" +
                                    "[8] Increment 1M times [9] Dump pending requests [x] Exit\n");
            switch(key) {
                case '1':
                    long val=counter.incrementAndGet();
                    System.out.println("counter: " + val);
                    break;
                case '2':
                    val=counter.decrementAndGet();
                    System.out.println("counter: " + val);
                    break;
                case '3':
                    long expect=Util.readLongFromStdin("expected value: ");
                    long update=Util.readLongFromStdin("update: ");
                    if(counter.compareAndSet(expect, update)) {
                        System.out.println("-- set counter \"" + counter.getName() + "\" to " + update + "\n");
                    }
                    else {
                        System.err.println("failed setting counter \"" + counter.getName() + "\" from " + expect +
                                             " to " + update + ", current value is " + counter.get() + "\n");
                    }
                    break;
                case '4':
                    String counter_name=Util.readStringFromStdin("counter name: ");
                    counter=counter_service.getOrCreateCounter(counter_name, 1);
                    break;
                case '5':
                    counter_name=Util.readStringFromStdin("counter name: ");
                    counter_service.deleteCounter(counter_name);
                    break;
                case '6':
                    System.out.println("Counters (current=" + counter.getName() + "):\n\n" + counter_service.printCounters());
                    break;
                case '7':
                    counter.get();
                    break;
                case '8':
                    int NUM=Util.readIntFromStdin("num: ");
                    System.out.println("");
                    int print=NUM / 10;
                    long retval=0;
                    long start=System.currentTimeMillis();
                    for(int i=0; i < NUM; i++) {
                        retval=counter.incrementAndGet();
                        if(i > 0 && i % print == 0)
                            System.out.println("-- count=" + retval);
                    }
                    long diff=System.currentTimeMillis() - start;
                    System.out.println("\n" + NUM + " incrs took " + diff + " ms; " + (NUM / (diff / 1000.0)) + " ops /sec\n");
                    break;
                case '9':
                    System.out.println("Pending requests:\n" + counter_service.dumpPendingRequests());
                    break;
                case 'x':
                    looping=false;
                    break;
            }
        }
        catch(Throwable t) {
            System.err.println(t);
        }
    }
    Util.close(ch);
}
 
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:75,代码来源:CounterServiceDemo.java


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