Example #1
0
  @SuppressWarnings("unchecked")
  public Object down(Event evt) {
    int type = evt.getType();

    switch (type) {
      case Event.CONNECT:
      case Event.CONNECT_USE_FLUSH:
      case Event.CONNECT_WITH_STATE_TRANSFER:
      case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
        boolean use_flush =
            type == Event.CONNECT_USE_FLUSH || type == Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH;
        boolean state_transfer =
            type == Event.CONNECT_WITH_STATE_TRANSFER
                || type == Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH;

        if (print_local_addr) {
          PhysicalAddress physical_addr =
              print_physical_addrs
                  ? (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr))
                  : null;
          System.out.println(
              "\n-------------------------------------------------------------------\n"
                  + "GMS: address="
                  + local_addr
                  + ", cluster="
                  + evt.getArg()
                  + (physical_addr != null ? ", physical address=" + physical_addr : "")
                  + "\n-------------------------------------------------------------------");
        } else {
          if (log.isDebugEnabled()) {
            PhysicalAddress physical_addr =
                print_physical_addrs
                    ? (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr))
                    : null;
            log.debug(
                "address="
                    + local_addr
                    + ", cluster="
                    + evt.getArg()
                    + (physical_addr != null ? ", physical address=" + physical_addr : ""));
          }
        }
        down_prot.down(evt);
        if (local_addr == null) throw new IllegalStateException("local_addr is null");
        try {
          if (state_transfer) impl.joinWithStateTransfer(local_addr, use_flush);
          else impl.join(local_addr, use_flush);
        } catch (Throwable e) {
          return e;
        }
        return null; // don't pass down: event has already been passed down

      case Event.DISCONNECT:
        impl.leave((Address) evt.getArg());
        if (!(impl instanceof CoordGmsImpl)) {
          initState(); // in case connect() is called again
        }
        down_prot.down(evt); // notify the other protocols, but ignore the result
        return null;

      case Event.CONFIG:
        Map<String, Object> config = (Map<String, Object>) evt.getArg();
        if ((config != null && config.containsKey("flush_supported"))) {
          flushProtocolInStack = true;
        }
        break;

      case Event.SET_LOCAL_ADDRESS:
        local_addr = (Address) evt.getArg();
        break;
    }

    return down_prot.down(evt);
  }