Example #1
0
  public void __setStatus(String resource, int priority, byte index, String statusText) {
    if (StatusInfo.STATUS_OFFLINE == index) {
      resource = StringUtils.notNull(resource);
      if (resource.equals(currentResource)) {
        currentResource = null;
      }
      removeSubContact(resource);
      if (0 == subContacts.size()) {
        setOfflineStatus();
      }

    } else {
      SubContact c = getSubContact(resource);
      c.priority = (byte) Math.min(127, Math.max(priority, -127));
      c.status = index;
      c.statusText = statusText;
    }
  }
Example #2
0
  // Generates int of money amount spent on connection
  protected int generateCostSum(int in, int out, boolean thisSession) {
    int cost = 0;
    int costOf1M = Options.getInt(Options.OPTION_COST_OF_1M) * 100;
    int costPacketLength = Math.max(Options.getInt(Options.OPTION_COST_PACKET_LENGTH), 1);

    long packets = 0;
    if (0 != in) {
      packets += (in + costPacketLength - 1) / costPacketLength;
    }
    if (0 != out) {
      packets += (out + costPacketLength - 1) / costPacketLength;
    }
    cost += (int) (packets * costPacketLength * costOf1M / (1024 * 1024));
    if (!usedToday() && (0 != sessionInTraffic) && (0 == costPerDaySum)) {
      costPerDaySum = costPerDaySum + Options.getInt(Options.OPTION_COST_PER_DAY);
      lastTimeUsed.setTime(new Date().getTime());
    }
    return cost + costPerDaySum;
  }