org.jgroups.util.Util.sleepRandom()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(220)

本文整理了Java中org.jgroups.util.Util.sleepRandom()方法的一些代码示例,展示了Util.sleepRandom()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.sleepRandom()方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:sleepRandom

Util.sleepRandom介绍

[英]Sleeps between 1 and timeout milliseconds, chosen randomly. Timeout must be > 1
[中]睡眠时间在1到超时毫秒之间,随机选择。超时必须大于1

代码示例

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Performs the flush of the given channel within the specfied number of attempts along with random
  3. * sleep time after each such attempt.
  4. * @param c the channel
  5. * @param numberOfAttempts the number of flush attempts
  6. * @param randomSleepTimeoutFloor the minimum sleep time between attempts in ms
  7. * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
  8. * @return true if channel was flushed successfully, false otherwise
  9. * @see JChannel#startFlush(boolean)
  10. */
  11. public static boolean startFlush(JChannel c,int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  12. int attemptCount=0;
  13. while(attemptCount < numberOfAttempts) {
  14. try {
  15. c.startFlush(false);
  16. return true;
  17. }
  18. catch(Exception e) {
  19. Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
  20. attemptCount++;
  21. }
  22. }
  23. return false;
  24. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Performs the flush of the given channel for the specified flush participants and the given
  3. * number of attempts along with random sleep time after each such attempt.
  4. * @param c the channel
  5. * @param flushParticipants the flush participants in this flush attempt
  6. * @param numberOfAttempts the number of flush attempts
  7. * @param randomSleepTimeoutFloor the minimum sleep time between attempts in ms
  8. * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
  9. * @return true if channel was flushed successfully, false otherwise
  10. * @see JChannel#startFlush(List,boolean)
  11. */
  12. public static boolean startFlush(JChannel c,List<Address> flushParticipants,
  13. int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  14. int attemptCount=0;
  15. while(attemptCount < numberOfAttempts) {
  16. try {
  17. c.startFlush(flushParticipants,false);
  18. return true;
  19. }
  20. catch(Exception e) {
  21. Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
  22. attemptCount++;
  23. }
  24. }
  25. return false;
  26. }

代码示例来源:origin: wildfly/wildfly

  1. while (attemptCount < maxAttempts) {
  2. if (attemptCount > 0)
  3. Util.sleepRandom(randomFloor, randomCeiling);
  4. try {
  5. up_prot.up(new Event(Event.SUSPEND, new ArrayList<>(new_view.getMembers())));

代码示例来源:origin: wildfly/wildfly

  1. protected void applyNewConfig(byte[] buffer) {
  2. final InputStream in=new ByteArrayInputStream(buffer);
  3. Thread thread=new Thread(() -> {
  4. try {
  5. JChannel ch=new JChannel(in);
  6. Util.sleepRandom(1000, 5000);
  7. channel.disconnect();
  8. JChannel tmp=channel;
  9. channel=ch;
  10. channel.setName(name);
  11. channel.setReceiver(MPerf.this);
  12. channel.connect("mperf");
  13. local_addr=channel.getAddress();
  14. JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
  15. Util.close(tmp);
  16. JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
  17. }
  18. catch(Exception e) {
  19. System.err.println("failed creating new channel");
  20. }
  21. });
  22. System.out.println("<< restarting channel");
  23. thread.start();
  24. }

代码示例来源:origin: wildfly/wildfly

  1. protected void handleEvent(Event evt) {
  2. switch(evt.getType()) {
  3. case Event.VIEW_CHANGE:
  4. View old_view=view, new_view=evt.getArg();
  5. this.view=new_view;
  6. if(old_view == null) { // first join
  7. Util.sleepRandom(0, stagger_timeout);
  8. // 1. send my own mapping to all
  9. multicastOwnMapping();
  10. // 2. ask the coordinator to send us the cache contents
  11. Address coord=new_view.getCoord();
  12. if(Objects.equals(local_addr, coord))
  13. return;
  14. Message msg=new Message(coord).setFlag(Message.Flag.OOB).putHeader(id, new Header(Type.CACHE_REQ));
  15. down_prot.down(msg);
  16. return;
  17. }
  18. if(new_view instanceof MergeView) {
  19. Util.sleepRandom(0, stagger_timeout);
  20. multicastOwnMapping();
  21. }
  22. break;
  23. case Event.SET_LOCAL_ADDRESS:
  24. local_addr=evt.getArg();
  25. break;
  26. }
  27. }

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. /**
  2. * Performs the flush of the given channel within the specfied number of attempts along with random
  3. * sleep time after each such attempt.
  4. * @param c the channel
  5. * @param numberOfAttempts the number of flush attempts
  6. * @param randomSleepTimeoutFloor the minimum sleep time between attempts in ms
  7. * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
  8. * @return true if channel was flushed successfully, false otherwise
  9. * @see JChannel#startFlush(boolean)
  10. */
  11. public static boolean startFlush(JChannel c,int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  12. int attemptCount=0;
  13. while(attemptCount < numberOfAttempts) {
  14. try {
  15. c.startFlush(false);
  16. return true;
  17. }
  18. catch(Exception e) {
  19. Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
  20. attemptCount++;
  21. }
  22. }
  23. return false;
  24. }

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. /**
  2. * Performs the flush of the given channel for the specified flush participants and the given
  3. * number of attempts along with random sleep time after each such attempt.
  4. * @param c the channel
  5. * @param flushParticipants the flush participants in this flush attempt
  6. * @param numberOfAttempts the number of flush attempts
  7. * @param randomSleepTimeoutFloor the minimum sleep time between attempts in ms
  8. * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
  9. * @return true if channel was flushed successfully, false otherwise
  10. * @see JChannel#startFlush(List,boolean)
  11. */
  12. public static boolean startFlush(JChannel c,List<Address> flushParticipants,
  13. int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  14. int attemptCount=0;
  15. while(attemptCount < numberOfAttempts) {
  16. try {
  17. c.startFlush(flushParticipants,false);
  18. return true;
  19. }
  20. catch(Exception e) {
  21. Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
  22. attemptCount++;
  23. }
  24. }
  25. return false;
  26. }

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. while (attemptCount < maxAttempts) {
  2. if (attemptCount > 0)
  3. Util.sleepRandom(randomFloor, randomCeiling);
  4. try {
  5. up_prot.up(new Event(Event.SUSPEND, new ArrayList<>(new_view.getMembers())));

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. protected void applyNewConfig(byte[] buffer) {
  2. final InputStream in=new ByteArrayInputStream(buffer);
  3. Thread thread=new Thread(() -> {
  4. try {
  5. JChannel ch=new JChannel(in);
  6. Util.sleepRandom(1000, 5000);
  7. channel.disconnect();
  8. JChannel tmp=channel;
  9. channel=ch;
  10. channel.setName(name);
  11. channel.setReceiver(MPerf.this);
  12. channel.connect("mperf");
  13. local_addr=channel.getAddress();
  14. JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
  15. Util.close(tmp);
  16. JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
  17. }
  18. catch(Exception e) {
  19. System.err.println("failed creating new channel");
  20. }
  21. });
  22. System.out.println("<< restarting channel");
  23. thread.start();
  24. }

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. protected void handleEvent(Event evt) {
  2. switch(evt.getType()) {
  3. case Event.VIEW_CHANGE:
  4. View old_view=view, new_view=evt.getArg();
  5. this.view=new_view;
  6. if(old_view == null) { // first join
  7. Util.sleepRandom(0, stagger_timeout);
  8. // 1. send my own mapping to all
  9. multicastOwnMapping();
  10. // 2. ask the coordinator to send us the cache contents
  11. Address coord=new_view.getCoord();
  12. if(Objects.equals(local_addr, coord))
  13. return;
  14. Message msg=new Message(coord).setFlag(Message.Flag.OOB).putHeader(id, new Header(Type.CACHE_REQ));
  15. down_prot.down(msg);
  16. return;
  17. }
  18. if(new_view instanceof MergeView) {
  19. Util.sleepRandom(0, stagger_timeout);
  20. multicastOwnMapping();
  21. }
  22. break;
  23. case Event.SET_LOCAL_ADDRESS:
  24. local_addr=evt.getArg();
  25. break;
  26. }
  27. }

相关文章

Util类方法