Ejemplo n.º 1
0
  private void kick(RRDCommand cmd) {
    if (cmd instanceof RRDPoolMemberWrapper) {
      RRDPoolMember member = ((RRDPoolMemberWrapper) cmd).member;

      if (member.rrdp != null) {
        // this may happen in case of a previous error
        member.rrdp.finish();
      }
      member.requestcount = 0;
      member.rrdp = null;

      synchronized (this) {
        member.inuse = false;
        notify();
      }
    }
  }
Ejemplo n.º 2
0
  public RRDCommand getConnection() throws Exception {
    if (finished) throw new Exception("Already finished");
    RRDPoolMember member = null;

    synchronized (this) {
      while (true) {
        for (int i = 0; i < poolsize; i++) {
          if (pool[i] == null) {
            pool[i] = new RRDPoolMember();
            member = pool[i];
            break;
          } else if (!pool[i].inuse) {
            member = pool[i];
            break;
          }
        }
        if (member != null) {
          member.inuse = true;
          break;
        } else {
          try {
            wait();
          } catch (InterruptedException e) {
            // 		ignore
          }
          // next loop iteration
        }
      }
    }

    member.requestcount++;
    if (member.rrdp == null) {
      member.requestcount = 0;
      member.rrdp = factory.createRRDCommand();
    }

    return new RRDPoolMemberWrapper(member);
  }
Ejemplo n.º 3
0
 @Override
 public void finish() {
   member.rrdp.finish();
   member.rrdp = null;
 }