Beispiel #1
0
  public synchronized boolean mustReportMaybeDead(ibis.ipl.IbisIdentifier ibisIdentifier) {
    Member member = members.get(ibisIdentifier.name());

    if (member == null) {
      logger.debug(
          "user reporting ibis " + ibisIdentifier + "  which is not in pool, not reporting");
      return false;
    }

    if (member.getTime() > (System.currentTimeMillis() - heartbeatInterval)) {
      logger.debug(
          "user reporting member "
              + ibisIdentifier
              + "  recently reported already, skiping this time");
      return false;
    }

    member.updateTime();
    return true;
  }
Beispiel #2
0
  void writeState(DataOutputStream out, int joinTime) throws IOException {
    ByteArrayOutputStream arrayOut = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(arrayOut);

    synchronized (this) {
      if (!initialized) {
        throw new IOException("state not initialized yet");
      }

      dataOut.writeInt(time);

      members.writeTo(dataOut);
      elections.writeTo(dataOut);

      Event[] signals = eventList.getSignalEvents(joinTime, time);
      dataOut.writeInt(signals.length);
      for (Event event : signals) {
        event.writeTo(dataOut);
      }

      dataOut.writeBoolean(closed);
      if (closed) {
        closeEvent.writeTo(out);
      }
      dataOut.writeBoolean(terminated);
      if (terminated) {
        terminateEvent.writeTo(out);
      }
    }

    dataOut.flush();
    dataOut.close();
    byte[] bytes = arrayOut.toByteArray();
    out.writeInt(bytes.length);
    out.write(bytes);
    logger.debug("pool state size = " + bytes.length);
  }
Beispiel #3
0
 public synchronized Member[] getChildren() {
   return members.getChildren(registry.getIbisIdentifier());
 }
Beispiel #4
0
  private synchronized void handleEvent(Event event) {
    logger.debug("handling event: " + event);

    switch (event.getType()) {
      case Event.JOIN:
        members.add(new Member(event.getIbis(), event));
        if (statistics != null) {
          statistics.newPoolSize(members.size());
        }
        break;
      case Event.LEAVE:
        members.remove(event.getIbis());
        if (statistics != null) {
          statistics.newPoolSize(members.size());
        }
        break;
      case Event.DIED:
        IbisIdentifier died = event.getIbis();
        members.remove(died);
        if (statistics != null) {
          statistics.newPoolSize(members.size());
        }
        if (died.equals(registry.getIbisIdentifier())) {
          logger.debug("we were declared dead");
          stop();
        }
        break;
      case Event.SIGNAL:
        // Not handled here
        break;
      case Event.ELECT:
        elections.put(new Election(event));
        if (statistics != null) {
          statistics.electionEvent();
        }
        break;
      case Event.UN_ELECT:
        elections.remove(event.getDescription());
        if (statistics != null) {
          statistics.electionEvent();
        }
        break;
      case Event.POOL_CLOSED:
        closed = true;
        closeEvent = event;
        break;
      case Event.POOL_TERMINATED:
        terminated = true;
        terminateEvent = event;
        break;
      default:
        logger.error("unknown event type: " + event.getType());
    }

    // wake up threads waiting for events
    notifyAll();

    if (logger.isDebugEnabled()) {
      logger.debug("member list now: " + members);
    }
  }
Beispiel #5
0
  void init(DataInputStream stream) throws IOException {
    long start = System.currentTimeMillis();
    // copy over data first so we are not blocked while reading data
    byte[] bytes = new byte[stream.readInt()];
    stream.readFully(bytes);

    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));

    long read = System.currentTimeMillis();

    // we have all the data in the array now, read from that...
    synchronized (this) {
      long locked = System.currentTimeMillis();

      if (initialized) {
        // already initialized, ignore
        return;
      }

      logger.debug("reading bootstrap state");

      time = in.readInt();

      members.init(in);

      long membersDone = System.currentTimeMillis();

      elections.init(in);
      int nrOfSignals = in.readInt();
      if (nrOfSignals < 0) {
        throw new IOException("negative number of signals");
      }

      ArrayList<Event> signals = new ArrayList<Event>();
      for (int i = 0; i < nrOfSignals; i++) {
        signals.add(new Event(in));
      }

      closed = in.readBoolean();
      if (closed) {
        closeEvent = new Event(in);
      }

      terminated = in.readBoolean();
      if (terminated) {
        terminateEvent = new Event(in);
      }

      // Create list of "old" events

      SortedSet<Event> events = new TreeSet<Event>();
      events.addAll(members.getJoinEvents());
      events.addAll(elections.getEvents());
      events.addAll(signals);
      if (closed) {
        events.add(closeEvent);
      }
      if (terminated) {
        events.add(terminateEvent);
      }

      long used = System.currentTimeMillis();

      // pass old events to the registry
      // CALLS REGISTRY WHILE POOL IS LOCKED!
      for (Event event : events) {
        registry.handleEvent(event);
      }

      long handled = System.currentTimeMillis();

      initialized = true;
      notifyAll();

      if (statistics != null) {
        statistics.newPoolSize(members.size());
      }
      long statted = System.currentTimeMillis();

      logger.info(
          "pool init, read = "
              + (read - start)
              + ", locked = "
              + (locked - read)
              + ", membersDone = "
              + (membersDone - locked)
              + ", used = "
              + (used - membersDone)
              + ", handled = "
              + (handled - used)
              + ", statted = "
              + (statted - handled));
    }

    handleEvents();
    logger.debug("bootstrap complete");
  }
Beispiel #6
0
 synchronized boolean isMember(IbisIdentifier ibis) {
   return members.contains(ibis);
 }
Beispiel #7
0
 synchronized Member getRandomMember() {
   return members.getRandom();
 }