本文整理汇总了Java中org.jgroups.util.Util.readStringFromStdin方法的典型用法代码示例。如果您正苦于以下问题:Java Util.readStringFromStdin方法的具体用法?Java Util.readStringFromStdin怎么用?Java Util.readStringFromStdin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.readStringFromStdin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.jgroups.util.Util; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Protocol[] prot_stack={
new UDP().setValue("bind_addr", InetAddress.getByName("127.0.0.1")),
new PING(),
new MERGE3(),
new FD_SOCK(),
new FD_ALL(),
new VERIFY_SUSPECT(),
new BARRIER(),
new NAKACK2(),
new UNICAST3(),
new STABLE(),
new GMS(),
new UFC(),
new MFC(),
new FRAG2()};
JChannel ch=new JChannel(prot_stack).name(args[0]);
ch.setReceiver(new ReceiverAdapter() {
public void viewAccepted(View new_view) {
System.out.println("view: " + new_view);
}
public void receive(Message msg) {
System.out.println("<< " + msg.getObject() + " [" + msg.getSrc() + "]");
}
});
ch.connect("ChatCluster");
for(;;) {
String line=Util.readStringFromStdin(": ");
ch.send(null, line);
}
}
示例2: main
import org.jgroups.util.Util; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String props="udp.xml";
String name=null;
for(int i=0; i < args.length; i++) {
if(args[i].equals("-props")) {
props=args[++i];
continue;
}
if(args[i].equals("-name")) {
name=args[++i];
continue;
}
System.out.println("RelayDemo [-props props] [-name name]");
return;
}
final JChannel ch=new JChannel(props);
if(name != null)
ch.setName(name);
ch.setReceiver(new ReceiverAdapter() {
public void receive(Message msg) {
Address sender=msg.getSrc();
System.out.println("<< " + msg.getObject() + " from " + sender);
Address dst=msg.getDest();
if(dst == null) {
Message rsp=new Message(msg.getSrc(), null, "this is a response");
try {
ch.send(rsp);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
public void viewAccepted(View new_view) {
System.out.println(print(new_view));
}
});
ch.connect("RelayDemo");
for(;;) {
String line=Util.readStringFromStdin(": ");
ch.send(null, line);
}
}
示例3: 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);
}