Пример #1
0
  void sendLeave(VirtualSocketAddress address) {
    if (address.equals(serverSocket.getLocalSocketAddress())) {
      // do not connect to self
      return;
    }

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

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

      connection.getAndCheckReply();

      connection.close();
      if (statistics != null) {
        statistics.add(
            Protocol.OPCODE_LEAVE,
            System.currentTimeMillis() - start,
            connection.read(),
            connection.written(),
            false);
      }
    } catch (IOException e) {
      logger.debug(serverSocket.getLocalSocketAddress() + " could not send leave to " + address);
    }
  }
Пример #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);
    }
  }
Пример #3
0
  private void gossip(VirtualSocketAddress victim, int timeout, boolean fillTimeout)
      throws IOException {
    long start = System.currentTimeMillis();

    if (victim == null) {
      logger.debug("no victim specified");
      return;
    }

    if (victim.equals(self.getAddress())) {
      logger.debug("not gossiping with outselves");
      return;
    }

    logger.debug("gossiping with " + victim);

    ARRGCacheEntry[] sendEntries = cache.getRandomEntries(GOSSIP_SIZE, true);

    Connection connection = null;
    try {

      connection = new Connection(victim, timeout, fillTimeout, socketFactory);

      // header

      connection.out().writeByte(Protocol.MAGIC_BYTE);
      connection.out().writeByte(Protocol.OPCODE_ARRG_GOSSIP);
      connection.out().writeUTF(poolName);

      // data

      self.writeTo(connection.out());

      connection.out().writeInt(sendEntries.length);
      for (ARRGCacheEntry entry : sendEntries) {
        entry.writeTo(connection.out());
      }

      connection.getAndCheckReply();

      ARRGCacheEntry peerEntry = new ARRGCacheEntry(connection.in());

      int receiveCount = connection.in().readInt();

      ARRGCacheEntry[] receivedEntries = new ARRGCacheEntry[receiveCount];

      for (int i = 0; i < receiveCount; i++) {
        receivedEntries[i] = new ARRGCacheEntry(connection.in());
      }

      connection.close();

      cache.add(peerEntry);
      cache.add(receivedEntries);

      resetLastGossip();

      if (statistics != null) {
        statistics.add(
            Protocol.OPCODE_ARRG_GOSSIP,
            System.currentTimeMillis() - start,
            connection.read(),
            connection.written(),
            false);
      }
    } finally {
      if (connection != null) {
        connection.close();
      }
    }
  }