示例#1
0
文件: GMS.java 项目: jtoerber/JGroups
 @ManagedOperation
 public void suspect(String suspected_member) {
   if (suspected_member == null) return;
   Map<Address, String> contents = UUID.getContents();
   for (Map.Entry<Address, String> entry : contents.entrySet()) {
     String logical_name = entry.getValue();
     if (logical_name != null && logical_name.equals(suspected_member)) {
       Address suspect = entry.getKey();
       if (suspect != null) up(new Event(Event.SUSPECT, suspect));
     }
   }
 }
示例#2
0
文件: GMS.java 项目: jtoerber/JGroups
 public void becomeClient() {
   ClientGmsImpl tmp = (ClientGmsImpl) impls.get(CLIENT);
   if (tmp == null) {
     tmp = new ClientGmsImpl(this);
     impls.put(CLIENT, tmp);
   }
   try {
     tmp.init();
   } catch (Exception e) {
     log.error("exception switching to client role", e);
   }
   setImpl(tmp);
 }
示例#3
0
文件: GMS.java 项目: jtoerber/JGroups
 public void becomeCoordinator() {
   CoordGmsImpl tmp = (CoordGmsImpl) impls.get(COORD);
   if (tmp == null) {
     tmp = new CoordGmsImpl(this);
     impls.put(COORD, tmp);
   }
   try {
     tmp.init();
   } catch (Exception e) {
     log.error("exception switching to coordinator role", e);
   }
   setImpl(tmp);
 }
示例#4
0
文件: GMS.java 项目: jtoerber/JGroups
  public void becomeParticipant() {
    ParticipantGmsImpl tmp = (ParticipantGmsImpl) impls.get(PART);

    if (tmp == null) {
      tmp = new ParticipantGmsImpl(this);
      impls.put(PART, tmp);
    }
    try {
      tmp.init();
    } catch (Exception e) {
      log.error("exception switching to participant", e);
    }
    setImpl(tmp);
  }
示例#5
0
文件: GMS.java 项目: jtoerber/JGroups
  @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);
  }