本文整理汇总了Java中org.jgroups.util.Util.sleep方法的典型用法代码示例。如果您正苦于以下问题:Java Util.sleep方法的具体用法?Java Util.sleep怎么用?Java Util.sleep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.sleep方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFailureDetectionRule
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void testFailureDetectionRule() {
SUPERVISOR sva=(SUPERVISOR)a.getProtocolStack().findProtocol(SUPERVISOR.class);
sva.installRule(500, new RestartFailureDetector());
SUPERVISOR svb=(SUPERVISOR)b.getProtocolStack().findProtocol(SUPERVISOR.class);
svb.installRule(500, new RestartFailureDetector());
assertFailureDetectorRunning(a, b);
System.out.println("stopping failure detection, waiting for failure detection restart rule to restart failure detection");
stopFailureDetection(a, b);
for(int i=0; i < 10; i++) {
if(isFailureDetectionRunning(a, b))
break;
Util.sleep(500);
}
assertFailureDetectorRunning(a, b);
}
示例2: testSingleChannel
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void testSingleChannel() throws Exception {
Semaphore s = new Semaphore(1);
FlushTestReceiver receivers[] ={ new FlushTestReceiver("c1", s, 0, FlushTestReceiver.CONNECT_ONLY) };
receivers[0].start();
s.release(1);
// Make sure everyone is in sync
Channel[] tmp = new Channel[receivers.length];
for (int i = 0; i < receivers.length; i++)
tmp[i] = receivers[i].getChannel();
Util.waitUntilAllChannelsHaveSameSize(10000, 1000, tmp);
// Reacquire the semaphore tickets; when we have them all we know the threads are done
s.tryAcquire(1, 10, TimeUnit.SECONDS);
receivers[0].cleanup();
Util.sleep(1000);
checkEventStateTransferSequence(receivers[0]);
}
示例3: create
import org.jgroups.util.Util; //导入方法依赖的package包/类
private static JChannel[] create(boolean use_flush_props, boolean simple_ids, String cluster_name, String ... names) throws Exception {
JChannel[] retval=new JChannel[names.length];
for(int i=0; i < retval.length; i++) {
JChannel ch;
Protocol[] props=use_flush_props? getFlushProps() : getProps();
if(simple_ids) {
ch=new MyChannel(props);
((MyChannel)ch).setId(i+1);
}
else
ch=new JChannel(props);
ch.setName(names[i]);
retval[i]=ch;
ch.connect(cluster_name);
if(i == 0)
Util.sleep(3000);
}
return retval;
}
示例4: run
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void run() {
Message msg=null, copy;
while(true) {
synchronized(this) {
try {
msg=send_queue.poll(1000, TimeUnit.MILLISECONDS);
if(msg == null) {
Util.sleep(1000);
continue;
}
}
catch(InterruptedException e) {
return;
}
copy=msg.copy().putHeader(id, new ABPHeader(Type.data, bit));
}
log.trace("%s: --> %s.msg(%d). Msg: %s", local_addr, copy.dest(), bit, copy.printHeaders());
down_prot.down(new Event(Event.MSG, copy));
}
}
示例5: setUp
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeMethod
void setUp() throws Exception {
channels = new JChannel[2];
dispatchers = new RpcDispatcher[2];
muxDispatchers = new RpcDispatcher[2][2];
channels[0] = createChannel(true, 2, "A");
channels[1] = createChannel(channels[0], "B");
for (int i = 0; i < dispatchers.length; i++) {
dispatchers[i] = new RpcDispatcher(channels[i], new Server("dispatcher[" + i + "]"));
channels[i].setUpHandler(new MuxUpHandler(dispatchers[i].getProtocolAdapter()));
for (int j = 0; j < muxDispatchers[i].length; j++) {
muxDispatchers[i][j] = new MuxRpcDispatcher((short) j, channels[i], null, null, new Server("muxDispatcher[" + i + "][" + j + "]"));
}
channels[i].connect("MuxRpcDispatcherTest");
Util.sleep(1000);
}
Util.waitUntilAllChannelsHaveSameSize(10000, 1000, channels);
}
示例6: run
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void run() {
while(!Thread.currentThread().isInterrupted()) {
lock.lock();
try {
for(Iterator<Entry<Address,V>> it=conns.entrySet().iterator();it.hasNext();) {
Entry<Address,V> entry=it.next();
V c=entry.getValue();
if(c.isExpired(System.nanoTime())) {
Util.close(c);
it.remove();
}
}
}
finally {
lock.unlock();
}
Util.sleep(reaperInterval);
}
}
示例7: setUp
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeClass
void setUp() throws Exception {
channels[0] = createChannel(true);
channels[1] = createChannel(channels[0]);
for (int i = 0; i < dispatchers.length; i++) {
dispatchers[i] = new MessageDispatcher(channels[i], null, null, new MuxRequestListener("dispatcher[" + i + "]"));
channels[i].setUpHandler(new MuxUpHandler(dispatchers[i].getProtocolAdapter()));
for (int j = 0; j < muxDispatchers[i].length; j++) {
muxDispatchers[i][j] = new MuxMessageDispatcher((short) j, channels[i], null, null, new MuxRequestListener("muxDispatcher[" + i + "][" + j + "]"));
}
channels[i].connect("MuxMessageDispatcherTest");
Util.sleep(1000);
}
}
示例8: start
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void start() throws Exception {
channel=new JChannel(props);
disp=new MessageDispatcher(channel, null, this, this);
channel.connect("MessageDispatcherSpeedTestGroup");
try {
if(server) {
System.out.println("-- Started as server. Press ctrl-c to kill");
while(true) {
Util.sleep(10000);
}
}
else {
sendMessages(num);
}
}
catch(Throwable t) {
t.printStackTrace(System.err);
}
finally {
channel.close();
disp.stop();
}
}
示例9: run
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void run() {
lock(lock, LOCK);
try {
Util.sleep(500);
if (all) {
signallingAll(lock.newCondition(), LOCK);
}
else {
signalling(lock.newCondition(), LOCK);
}
}
catch(Exception e) {
e.printStackTrace();
}
finally {
unlock(lock, LOCK);
}
}
示例10: testRandomRegularAndOOBMulticasts
import org.jgroups.util.Util; //导入方法依赖的package包/类
@Test(invocationCount=5)
@SuppressWarnings("unchecked")
public void testRandomRegularAndOOBMulticasts() throws Exception {
DISCARD discard=new DISCARD();
discard.setLocalAddress(a.getAddress());
discard.setUpDiscardRate(0.5);
ProtocolStack stack=a.getProtocolStack();
stack.insertProtocol(discard, ProtocolStack.ABOVE, TP.class);
MyReceiver r1=new MyReceiver("A"), r2=new MyReceiver("B");
a.setReceiver(r1);
b.setReceiver(r2);
final int NUM_MSGS=20;
final int NUM_THREADS=10;
send(null, NUM_MSGS, NUM_THREADS, 0.5); // send on random channel (a or b)
Collection<Integer> one=r1.getMsgs(), two=r2.getMsgs();
for(int i=0; i < 20; i++) {
if(one.size() == NUM_MSGS && two.size() == NUM_MSGS)
break;
System.out.println("A: size=" + one.size() + ", B: size=" + two.size());
sendStableMessages(a,b);
Util.sleep(1000);
}
System.out.println("A: size=" + one.size() + ", B: size=" + two.size());
stack.removeProtocol(DISCARD.class);
System.out.println("A received " + one.size() + " messages (" + NUM_MSGS + " expected)" +
"\nB received " + two.size() + " messages (" + NUM_MSGS + " expected)");
check(NUM_MSGS, one, "A");
check(NUM_MSGS, two, "B");
}
示例11: testMultipleFutures
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void testMultipleFutures() throws Exception {
MethodCall sleep=new MethodCall("sleep", new Object[]{100L}, new Class[]{long.class});
List<Future<RspList<Long>>> futures=new ArrayList<>();
long target=System.currentTimeMillis() + 30000L;
Future<RspList<Long>> future;
RequestOptions options=new RequestOptions(ResponseMode.GET_ALL, 30000L);
for(int i=0; i < 10; i++) {
future=disp1.callRemoteMethodsWithFuture(null, sleep, options);
futures.add(future);
}
List<Future<RspList<Long>>> rsps=new ArrayList<>();
while(!futures.isEmpty() && System.currentTimeMillis() < target) {
for(Iterator<Future<RspList<Long>>> it=futures.iterator(); it.hasNext();) {
future=it.next();
if(future.isDone()) {
it.remove();
rsps.add(future);
}
}
System.out.println("pending responses: " + futures.size());
Util.sleep(200);
}
System.out.println("\n" + rsps.size() + " responses:\n");
for(Future<RspList<Long>> tmp: rsps) {
System.out.println(tmp);
}
}
示例12: sleep
import org.jgroups.util.Util; //导入方法依赖的package包/类
public static long sleep(long timeout) {
// System.out.println("sleep()");
long start=System.currentTimeMillis();
Util.sleep(timeout);
//throw new NullPointerException("boom");
return System.currentTimeMillis() - start;
}
示例13: receive
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void receive(Message msg) {
Util.sleep(SLEEP_TIME);
Short scope=msg.getScope();
if(scope > 0) {
List<Long> list=msgs.get(scope);
if(list == null) {
list=new ArrayList<>(5);
List<Long> tmp=msgs.putIfAbsent(scope, list);
if(tmp != null)
list=tmp;
}
list.add((Long)msg.getObject());
}
}
示例14: receive
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void receive(Message msg) {
Util.sleep(SLEEPTIME);
Address sender=msg.getSrc();
List<Integer> list=msgs.get(sender);
if(list == null) {
list=new LinkedList<>();
List<Integer> tmp=msgs.putIfAbsent(sender, list);
if(tmp != null)
list=tmp;
}
Integer num=(Integer)msg.getObject();
list.add(num); // no concurrent access: FIFO per sender ! (No need to synchronize on list)
count.incrementAndGet();
}
示例15: start
import org.jgroups.util.Util; //导入方法依赖的package包/类
public void start() throws Exception {
channel=new JChannel(props);
channel.setDiscardOwnMessages(true);
disp=new RpcDispatcher(channel, null, this, this); // no concurrent processing on incoming method calls
disp.setMethodLookup(new MethodLookup() {
public Method findMethod(short id) {
return METHODS[0];
}
});
if(jmx) {
MBeanServer srv=Util.getMBeanServer();
if(srv == null)
throw new Exception("No MBeanServers found;" +
"\nDraw needs to be run with an MBeanServer present, or inside JDK 5");
JmxConfigurator.registerChannel((JChannel)channel, srv, "jgroups", channel.getClusterName(), true);
}
channel.connect("RpcDispatcherSpeedTestGroup");
try {
if(server) {
System.out.println("-- Started as server. Press ctrl-c to kill");
while(true) {
Util.sleep(10000);
}
}
else {
invokeRpcs(num, num_threads, async, oob);
}
}
catch(Throwable t) {
t.printStackTrace(System.err);
}
finally {
channel.close();
disp.stop();
}
}