Пример #1
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();
  }
Пример #2
0
  public void gossip() {
    VirtualSocketAddress address = arrg.getRandomMember();

    if (address == null || address.equals(serverSocket.getLocalSocketAddress())) {
      logger.debug("noone to gossip with, or (not) gossiping with self");
      return;
    }

    try {
      long start = System.currentTimeMillis();
      Connection connection = new Connection(address, CONNECTION_TIMEOUT, true, socketFactory);

      connection.out().writeByte(Protocol.MAGIC_BYTE);
      connection.out().writeByte(Protocol.OPCODE_GOSSIP);
      registry.getIbisIdentifier().writeTo(connection.out());

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

      connection.getAndCheckReply();

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

      connection.close();
      if (statistics != null) {
        statistics.add(
            Protocol.OPCODE_GOSSIP,
            System.currentTimeMillis() - start,
            connection.read(),
            connection.written(),
            false);
      }
    } catch (IOException e) {
      logger.debug("could not gossip with " + address, e);
    }
  }