Exemplo n.º 1
0
  /**
   * Generates new UUID and sets local address. Sends down a REMOVE_ADDRESS (if existing address was
   * present) and a SET_LOCAL_ADDRESS
   */
  protected void setAddress() {
    Address old_addr = local_addr;
    local_addr = generateAddress();
    if (old_addr != null) down(new Event(Event.REMOVE_ADDRESS, old_addr));
    if (name == null || name.isEmpty()) // generate a logical name if not set
    name = Util.generateLocalName();
    if (name != null && !name.isEmpty()) UUID.add(local_addr, name);

    Event evt = new Event(Event.SET_LOCAL_ADDRESS, local_addr);
    down(evt);
    if (up_handler != null) up_handler.up(evt);
  }
Exemplo n.º 2
0
 @ManagedOperation(description = "Disconnects the channel if connected")
 public synchronized void disconnect() {
   switch (state) {
     case OPEN:
     case CLOSED:
       return;
     case CONNECTING:
     case CONNECTED:
       if (cluster_name != null) {
         // Send down a DISCONNECT event, which travels down to the GMS, where a response is
         // returned
         try {
           down(new Event(Event.DISCONNECT, local_addr)); // DISCONNECT is handled by each layer
         } catch (Throwable t) {
           log.error(Util.getMessage("DisconnectFailure"), local_addr, t);
         }
       }
       state = State.OPEN;
       stopStack(true, false);
       notifyChannelDisconnected(this);
       init(); // sets local_addr=null; changed March 18 2003 (bela) -- prevented successful
               // rejoining
       break;
     default:
       throw new IllegalStateException("state " + state + " unknown");
   }
 }
 private static void injectView(View view, JChannel... channels) {
   for (JChannel ch : channels) {
     ch.down(new Event(Event.VIEW_CHANGE, view));
     ch.up(new Event(Event.VIEW_CHANGE, view));
   }
   for (JChannel ch : channels) {
     MyReceiver receiver = (MyReceiver) ch.getReceiver();
     System.out.println("[" + receiver.name + "] view=" + ch.getView());
   }
 }
Exemplo n.º 4
0
 protected void _connect(Event connect_event) throws Exception {
   try {
     down(connect_event);
   } catch (Throwable t) {
     stopStack(true, false);
     state = State.OPEN;
     init();
     throw new Exception("connecting to channel \"" + connect_event.getArg() + "\" failed", t);
   }
 }
Exemplo n.º 5
0
  public void startFlush(boolean automatic_resume) throws Exception {
    if (!flushSupported())
      throw new IllegalStateException(
          "Flush is not supported, add pbcast.FLUSH protocol to your configuration");

    try {
      down(new Event(Event.SUSPEND));
    } catch (Exception e) {
      throw new Exception("Flush failed", e.getCause());
    } finally {
      if (automatic_resume) stopFlush();
    }
  }
Exemplo n.º 6
0
  protected void getState(Address target, long timeout, Callable<Boolean> flushInvoker)
      throws Exception {
    checkClosedOrNotConnected();
    if (!state_transfer_supported)
      throw new IllegalStateException(
          "fetching state will fail as state transfer is not supported. "
              + "Add one of the state transfer protocols to your configuration");

    if (target == null) target = determineCoordinator();
    if (target != null && local_addr != null && target.equals(local_addr)) {
      log.trace(
          local_addr
              + ": cannot get state from myself ("
              + target
              + "): probably the first member");
      return;
    }

    boolean initiateFlush = flushSupported() && flushInvoker != null;

    if (initiateFlush) {
      boolean successfulFlush = false;
      try {
        successfulFlush = flushInvoker.call();
      } catch (Throwable e) {
        successfulFlush = false; // http://jira.jboss.com/jira/browse/JGRP-759
      }
      if (!successfulFlush)
        throw new IllegalStateException(
            "Node " + local_addr + " could not flush the cluster for state retrieval");
    }

    state_promise.reset();
    StateTransferInfo state_info = new StateTransferInfo(target, timeout);
    long start = System.currentTimeMillis();
    down(new Event(Event.GET_STATE, state_info));
    StateTransferResult result = state_promise.getResult(state_info.timeout);

    if (initiateFlush) stopFlush();

    if (result == null)
      throw new StateTransferException(
          "timeout during state transfer (" + (System.currentTimeMillis() - start) + "ms)");
    if (result.hasException())
      throw new StateTransferException("state transfer failed", result.getException());
  }
Exemplo n.º 7
0
 public void startFlush(List<Address> flushParticipants, boolean automatic_resume)
     throws Exception {
   if (!flushSupported())
     throw new IllegalStateException(
         "Flush is not supported, add pbcast.FLUSH protocol to your configuration");
   View v = getView();
   boolean validParticipants = v != null && v.getMembers().containsAll(flushParticipants);
   if (!validParticipants)
     throw new IllegalArgumentException(
         "Current view " + v + " does not contain all flush participants " + flushParticipants);
   try {
     down(new Event(Event.SUSPEND, flushParticipants));
   } catch (Exception e) {
     throw new Exception("Flush failed", e.getCause());
   } finally {
     if (automatic_resume) stopFlush(flushParticipants);
   }
 }
Exemplo n.º 8
0
  public void testFlushWithCrashedFlushCoordinator() throws Exception {
    JChannel a = null, b = null, c = null;
    try {
      a = createChannel(true, 3, "A");
      changeProps(a);
      a.connect("testFlushWithCrashedFlushCoordinator");

      b = createChannel(a, "B");
      changeProps(b);
      b.connect("testFlushWithCrashedFlushCoordinator");

      c = createChannel(a, "C");
      changeProps(c);
      c.connect("testFlushWithCrashedFlushCoordinator");

      System.out.println("shutting down flush coordinator B");
      b.down(new Event(Event.SUSPEND_BUT_FAIL)); // send out START_FLUSH and then return

      // now shut down B. This means, after failure detection kicks in and the new coordinator takes
      // over
      // (either A or C), that the current flush started by B will be cancelled and a new flush (by
      // A or C)
      // will be started
      Util.shutdown(b);

      a.getProtocolStack().findProtocol(FLUSH.class).setLevel("debug");
      c.getProtocolStack().findProtocol(FLUSH.class).setLevel("debug");

      Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, c);

      // cluster should not hang and two remaining members should have a correct view
      assertTrue("correct view size", a.getView().size() == 2);
      assertTrue("correct view size", c.getView().size() == 2);

      a.getProtocolStack().findProtocol(FLUSH.class).setLevel("warn");
      c.getProtocolStack().findProtocol(FLUSH.class).setLevel("warn");

    } finally {
      Util.close(c, b, a);
    }
  }
Exemplo n.º 9
0
 /**
  * Initializes all variables. Used after <tt>close()</tt> or <tt>disconnect()</tt>, to be ready
  * for new <tt>connect()</tt>
  */
 protected void init() {
   if (local_addr != null) down(new Event(Event.REMOVE_ADDRESS, local_addr));
   local_addr = null;
   cluster_name = null;
   my_view = null;
 }
Exemplo n.º 10
0
 public void send(Message msg) throws Exception {
   checkClosedOrNotConnected();
   if (msg == null) throw new NullPointerException("msg is null");
   down(new Event(Event.MSG, msg));
 }
Exemplo n.º 11
0
 public void stopFlush(List<Address> flushParticipants) {
   if (!flushSupported())
     throw new IllegalStateException(
         "Flush is not supported, add pbcast.FLUSH protocol to your configuration");
   down(new Event(Event.RESUME, flushParticipants));
 }
Exemplo n.º 12
0
 public void stopFlush() {
   if (!flushSupported())
     throw new IllegalStateException(
         "Flush is not supported, add pbcast.FLUSH protocol to your configuration");
   down(new Event(Event.RESUME));
 }