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

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

本文整理了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

/**
 * Performs the flush of the given channel within the specfied number of attempts along with random
 * sleep time after each such attempt.
 * @param c                         the channel
 * @param numberOfAttempts          the number of flush attempts
 * @param randomSleepTimeoutFloor   the minimum sleep time between attempts in ms
 * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
 * @return true if channel was flushed successfully, false otherwise
 * @see JChannel#startFlush(boolean)
 */
public static boolean startFlush(JChannel c,int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  int attemptCount=0;
  while(attemptCount < numberOfAttempts) {
    try {
      c.startFlush(false);
      return true;
    }
    catch(Exception e) {
      Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
      attemptCount++;
    }
  }
  return false;
}

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

/**
 * Performs the flush of the given channel for the specified flush participants and the given
 * number of attempts along with random sleep time after each such attempt.
 * @param c                         the channel
 * @param flushParticipants         the flush participants in this flush attempt
 * @param numberOfAttempts          the number of flush attempts
 * @param randomSleepTimeoutFloor   the minimum sleep time between attempts in ms
 * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
 * @return true if channel was flushed successfully, false otherwise
 * @see JChannel#startFlush(List,boolean)
 */
public static boolean startFlush(JChannel c,List<Address> flushParticipants,
                 int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  int attemptCount=0;
  while(attemptCount < numberOfAttempts) {
    try {
      c.startFlush(flushParticipants,false);
      return true;
    }
    catch(Exception e) {
      Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
      attemptCount++;
    }
  }
  return false;
}

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

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

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

protected void applyNewConfig(byte[] buffer) {
  final InputStream in=new ByteArrayInputStream(buffer);
  Thread thread=new Thread(() -> {
    try {
      JChannel ch=new JChannel(in);
      Util.sleepRandom(1000, 5000);
      channel.disconnect();
      JChannel tmp=channel;
      channel=ch;
      channel.setName(name);
      channel.setReceiver(MPerf.this);
      channel.connect("mperf");
      local_addr=channel.getAddress();
      JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
      Util.close(tmp);
      JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
    }
    catch(Exception e) {
      System.err.println("failed creating new channel");
    }
  });
  System.out.println("<< restarting channel");
  thread.start();
}

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

protected void handleEvent(Event evt) {
  switch(evt.getType()) {
    case Event.VIEW_CHANGE:
      View old_view=view, new_view=evt.getArg();
      this.view=new_view;
      if(old_view == null) { // first join
        Util.sleepRandom(0, stagger_timeout);
        // 1. send my own mapping to all
        multicastOwnMapping();
        // 2. ask the coordinator to send us the cache contents
        Address coord=new_view.getCoord();
        if(Objects.equals(local_addr, coord))
          return;
        Message msg=new Message(coord).setFlag(Message.Flag.OOB).putHeader(id, new Header(Type.CACHE_REQ));
        down_prot.down(msg);
        return;
      }
      if(new_view instanceof MergeView) {
        Util.sleepRandom(0, stagger_timeout);
        multicastOwnMapping();
      }
      break;
    case Event.SET_LOCAL_ADDRESS:
      local_addr=evt.getArg();
      break;
  }
}

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

/**
 * Performs the flush of the given channel within the specfied number of attempts along with random
 * sleep time after each such attempt.
 * @param c                         the channel
 * @param numberOfAttempts          the number of flush attempts
 * @param randomSleepTimeoutFloor   the minimum sleep time between attempts in ms
 * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
 * @return true if channel was flushed successfully, false otherwise
 * @see JChannel#startFlush(boolean)
 */
public static boolean startFlush(JChannel c,int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  int attemptCount=0;
  while(attemptCount < numberOfAttempts) {
    try {
      c.startFlush(false);
      return true;
    }
    catch(Exception e) {
      Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
      attemptCount++;
    }
  }
  return false;
}

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

/**
 * Performs the flush of the given channel for the specified flush participants and the given
 * number of attempts along with random sleep time after each such attempt.
 * @param c                         the channel
 * @param flushParticipants         the flush participants in this flush attempt
 * @param numberOfAttempts          the number of flush attempts
 * @param randomSleepTimeoutFloor   the minimum sleep time between attempts in ms
 * @param randomSleepTimeoutCeiling the maximum sleep time between attempts in ms
 * @return true if channel was flushed successfully, false otherwise
 * @see JChannel#startFlush(List,boolean)
 */
public static boolean startFlush(JChannel c,List<Address> flushParticipants,
                 int numberOfAttempts,long randomSleepTimeoutFloor,long randomSleepTimeoutCeiling) {
  int attemptCount=0;
  while(attemptCount < numberOfAttempts) {
    try {
      c.startFlush(flushParticipants,false);
      return true;
    }
    catch(Exception e) {
      Util.sleepRandom(randomSleepTimeoutFloor,randomSleepTimeoutCeiling);
      attemptCount++;
    }
  }
  return false;
}

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

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

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

protected void applyNewConfig(byte[] buffer) {
  final InputStream in=new ByteArrayInputStream(buffer);
  Thread thread=new Thread(() -> {
    try {
      JChannel ch=new JChannel(in);
      Util.sleepRandom(1000, 5000);
      channel.disconnect();
      JChannel tmp=channel;
      channel=ch;
      channel.setName(name);
      channel.setReceiver(MPerf.this);
      channel.connect("mperf");
      local_addr=channel.getAddress();
      JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
      Util.close(tmp);
      JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
    }
    catch(Exception e) {
      System.err.println("failed creating new channel");
    }
  });
  System.out.println("<< restarting channel");
  thread.start();
}

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

protected void handleEvent(Event evt) {
  switch(evt.getType()) {
    case Event.VIEW_CHANGE:
      View old_view=view, new_view=evt.getArg();
      this.view=new_view;
      if(old_view == null) { // first join
        Util.sleepRandom(0, stagger_timeout);
        // 1. send my own mapping to all
        multicastOwnMapping();
        // 2. ask the coordinator to send us the cache contents
        Address coord=new_view.getCoord();
        if(Objects.equals(local_addr, coord))
          return;
        Message msg=new Message(coord).setFlag(Message.Flag.OOB).putHeader(id, new Header(Type.CACHE_REQ));
        down_prot.down(msg);
        return;
      }
      if(new_view instanceof MergeView) {
        Util.sleepRandom(0, stagger_timeout);
        multicastOwnMapping();
      }
      break;
    case Event.SET_LOCAL_ADDRESS:
      local_addr=evt.getArg();
      break;
  }
}

相关文章

Util类方法