Exemplo n.º 1
0
  public void ping(IbisIdentifier ibis) throws IOException {
    long start = System.currentTimeMillis();
    Connection connection =
        new Connection(ibis, CONNECTION_TIMEOUT, true, socketFactory, Protocol.VIRTUAL_PORT);

    connection.out().writeByte(Protocol.MAGIC_BYTE);
    connection.out().writeByte(Protocol.OPCODE_PING);

    connection.getAndCheckReply();
    IbisIdentifier result = new IbisIdentifier(connection.in());

    connection.close();

    if (!result.equals(ibis)) {
      throw new IOException("tried to ping " + ibis + ", reached " + result + " instead");
    }
    if (statistics != null) {
      statistics.add(
          Protocol.OPCODE_PING,
          System.currentTimeMillis() - start,
          connection.read(),
          connection.written(),
          false);
    }
  }
Exemplo n.º 2
0
  private void handleGossip(Connection connection) throws IOException {
    IbisIdentifier peer = new IbisIdentifier(connection.in());

    if (peer.equals(registry.getIbisIdentifier())) {
      logger.error("eep! talking to ourselves");
      connection.closeWithError("talking to self");
    }

    if (!peer.poolName().equals(registry.getIbisIdentifier().poolName())) {
      connection.closeWithError("wrong pool");
    }

    pool.readGossipData(connection.in());
    elections.readGossipData(connection.in());

    connection.sendOKReply();

    pool.writeGossipData(connection.out(), gossipSize);
    elections.writeGossipData(connection.out());

    connection.close();
  }
Exemplo n.º 3
0
 @Override
 public String toString() {
   return ibis.toString() + "@T" + getCurrentTime();
 }
Exemplo n.º 4
0
 String getID() {
   return ibis.getID();
 }
Exemplo n.º 5
0
 public void writeTo(DataOutput out) throws IOException {
   ibis.writeTo(out);
   event.writeTo(out);
 }
Exemplo n.º 6
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);
    }
  }