Exemple #1
0
  public static void joinHerd(
      final String dc, final String herd, final Endpoint endpoint, Endpoint shepardAddress) {
    Thread.dumpStack();

    final Endpoint shepard = Networking.resolve(shepardAddress.getHost(), PORT);
    final RpcEndpoint sock = Networking.rpcConnect(TransportProvider.DEFAULT).toDefaultService();

    Log.info(IP.localHostname() + " Contacting shepard at: " + shepard + " to join: " + herd);
    System.err.println(
        IP.localHostname() + " Contacting shepard at: " + shepard + " to join: " + herd);

    new PeriodicTask(2.0, 1.0) {
      public void run() {
        try {
          sock.send(
              shepard,
              new JoinHerdRequest(dc, herd, endpoint),
              new HerdProtoHandler() {
                public void onReceive(JoinHerdReply r) {
                  herds = r.herds();
                  lastChange = System.currentTimeMillis() - r.age();
                  Log.info(
                      String.format(
                          "Received Herd information: lastChange : [%.1f s] ago, data: %s\n",
                          age() / 1000.0, herds));

                  Threading.synchronizedNotifyAllOn(herds);
                }
              },
              0);
          if (stopProbing) cancel();

        } catch (Exception x) {
          Log.warning("Cannot connect to shepard at: " + shepard + " to join: " + herd);
        }
      }
    };
  }