/** Execute when new member join or leave Group */
  public void viewAccepted(View v) {
    memberSize = v.size();
    if (mainFrame != null) setTitle();
    members.clear();
    members.addAll(v.getMembers());

    if (v instanceof MergeView) {
      System.out.println("** " + v);

      // This is a simple merge function, which fetches the state from the coordinator
      // on a merge and overwrites all of its own state
      if (useState && !members.isEmpty()) {
        Address coord = members.get(0);
        Address local_addr = channel.getAddress();
        if (local_addr != null && !local_addr.equals(coord)) {
          try {

            // make a copy of our state first
            Map<Point, Color> copy = null;
            if (send_own_state_on_merge) {
              synchronized (drawPanel.state) {
                copy = new LinkedHashMap<Point, Color>(drawPanel.state);
              }
            }
            System.out.println("fetching state from " + coord);
            channel.getState(coord, 5000);
            if (copy != null)
              sendOwnState(copy); // multicast my own state so everybody else has it too
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    } else System.out.println("** View=" + v);
  }
Example #2
0
 public void connect() {
   try {
     channel.connect("TOTAL_TOKEN_DEMO_GROUP");
   } catch (ChannelException e) {
     e.printStackTrace();
   }
   receiverThread = new ReceiverThread();
   receiverThread.start();
   Address a = channel.getAddress();
   if (a != null) setTitle(a.toString());
   else setTitle("Not connected");
   control.connected();
 }
 public static Address randomAddress() {
   Address a = create(Address.class);
   a.setAddressee(randomize(ADDRESSEE));
   if (rand.nextBoolean()) {
     a.setAddressLine1(randomize(ADDRESS));
     a.setAddressLine2("");
   } else {
     a.setAddressLine1("");
     a.setAddressLine2(randomize(ADDRESS));
   }
   a.setCity(randomize(CITY));
   a.setPostalCode(generateKey(5));
   a.setState(randomize(STATE));
   return (a);
 }
 private String addressToString(Address a) {
   if (a == null) {
     if (is64Bit) {
       return "0x0000000000000000";
     } else {
       return "0x00000000";
     }
   }
   return a.toString();
 }