예제 #1
1
파일: UDP.java 프로젝트: NZDIS/jgroups
 void start() {
   if (t == null) {
     t = new Thread(this, "UDP.OutgoingPacketHandler thread");
     t.setDaemon(true);
     t.start();
   }
 }
예제 #2
0
    /**
     * @param views Guaranteed to be non-null and to have >= 2 members, or else this thread would
     *     not be started
     */
    public synchronized void start(Map<Address, View> views) {
      if (thread == null || thread.isAlive()) {
        this.coords.clear();

        // now remove all members which don't have us in their view, so RPCs won't block (e.g.
        // FLUSH)
        // https://jira.jboss.org/browse/JGRP-1061
        sanitizeViews(views);

        // Add all different coordinators of the views into the hashmap and sets their members:
        Collection<Address> coordinators = Util.determineMergeCoords(views);
        for (Address coord : coordinators) {
          View view = views.get(coord);
          if (view != null) this.coords.put(coord, new ArrayList<Address>(view.getMembers()));
        }

        // For the merge participants which are not coordinator, we simply add them, and the
        // associated
        // membership list consists only of themselves
        Collection<Address> merge_participants = Util.determineMergeParticipants(views);
        merge_participants.removeAll(coordinators);
        for (Address merge_participant : merge_participants) {
          Collection<Address> tmp = new ArrayList<Address>();
          tmp.add(merge_participant);
          coords.putIfAbsent(merge_participant, tmp);
        }

        thread = gms.getThreadFactory().newThread(this, "MergeTask");
        thread.setDaemon(true);
        thread.start();
      }
    }
예제 #3
0
파일: UDP.java 프로젝트: NZDIS/jgroups
 public void start() {
   if (thread == null) {
     thread = new Thread(this, "UDP.UcastReceiverThread");
     thread.setDaemon(true);
     running = true;
     thread.start();
   }
 }
예제 #4
0
파일: GMS.java 프로젝트: NZDIS/jgroups
 private void startEventHandlerThread() {
   if (event_queue == null) event_queue = new Queue();
   if (evt_thread == null) {
     evt_thread = new Thread(this, "GMS.EventHandlerThread");
     evt_thread.setDaemon(true);
     evt_thread.start();
   }
 }
예제 #5
0
파일: GMS.java 프로젝트: jtoerber/JGroups
 synchronized void start() {
   if (queue.closed()) queue.reset();
   if (thread == null || !thread.isAlive()) {
     thread = getThreadFactory().newThread(this, "ViewHandler");
     thread.setDaemon(
         false); // thread cannot terminate if we have tasks left, e.g. when we as coord leave
     thread.start();
   }
 }
예제 #6
0
 public ReceiverThread() {
   nullifier =
       new Thread(
           new Runnable() {
             public void run() {
               // nullifies throughput display
               while (running) {
                 Util.sleep(2000);
                 if ((System.currentTimeMillis() - startTimeThroughput) > 2000) {
                   control.throughput.setText("0 KB/sec");
                 }
               }
             }
           });
   nullifier.start();
 }
예제 #7
0
파일: UDP.java 프로젝트: NZDIS/jgroups
  /** Starts the unicast and multicast receiver threads */
  void startThreads() throws Exception {
    if (ucast_receiver == null) {
      // start the listener thread of the ucast_recv_sock
      ucast_receiver = new UcastReceiver();
      ucast_receiver.start();
      if (Trace.trace) {
        Trace.info("UDP.startThreads()", "created unicast receiver thread");
      }
    }

    if (ip_mcast) {
      if (mcast_receiver != null) {
        if (mcast_receiver.isAlive()) {
          if (Trace.trace) {
            Trace.info(
                "UDP.createThreads()",
                "did not create new multicastreceiver thread as existing "
                    + "multicast receiver thread is still running");
          }
        } else {
          mcast_receiver = null; // will be created just below...
        }
      }

      if (mcast_receiver == null) {
        mcast_receiver = new Thread(this, "UDP mcast receiver");
        mcast_receiver.setPriority(Thread.MAX_PRIORITY); // needed ????
        mcast_receiver.setDaemon(true);
        mcast_receiver.start();
      }
    }
    if (use_outgoing_packet_handler) {
      outgoing_packet_handler.start();
    }
    if (use_incoming_packet_handler) {
      incoming_packet_handler.start();
    }
  }
예제 #8
0
  /** Tests 2 channels calling FLUSH simultaneously */
  @Test
  public void testConcurrentFlush() throws Exception {
    c1 = createChannel(true, 2);
    c1.connect("testConcurrentFlush");
    c2 = createChannel(c1);
    c2.connect("testConcurrentFlush");

    assertViewsReceived(c1, c2);

    final CountDownLatch startFlushLatch = new CountDownLatch(1);
    final CountDownLatch stopFlushLatch = new CountDownLatch(1);
    final CountDownLatch flushStartReceived = new CountDownLatch(2);
    final CountDownLatch flushStopReceived = new CountDownLatch(2);

    Thread t1 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              boolean rc = Util.startFlush(c1);
              System.out.println("t1: rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c1.stopFlush();
            }
          }
        };

    Thread t2 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              boolean rc = Util.startFlush(c2);
              System.out.println("t2: rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c2.stopFlush();
            }
          }
        };

    Listener l1 = new Listener("c1", c1, flushStartReceived, flushStopReceived);
    Listener l2 = new Listener("c2", c2, flushStartReceived, flushStopReceived);
    t1.start();
    t2.start();

    startFlushLatch.countDown();

    assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));

    // at this stage both channels should have started a flush
    stopFlushLatch.countDown();

    t1.join();
    t2.join();

    assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));

    assert l1.blockReceived;
    assert l1.unblockReceived;
    assert l2.blockReceived;
    assert l2.unblockReceived;
  }
예제 #9
0
  /** Tests 2 channels calling partial FLUSHes and one calling FLUSH simultaneously */
  @Test
  public void testConcurrentFlushAndPartialFlush() throws Exception {
    c1 = createChannel(true, 3);
    c1.connect("testConcurrentFlushAndPartialFlush");

    c2 = createChannel(c1);
    c2.connect("testConcurrentFlushAndPartialFlush");

    c3 = createChannel(c1);
    c3.connect("testConcurrentFlushAndPartialFlush");
    assertViewsReceived(c1, c2, c3);

    final CountDownLatch startFlushLatch = new CountDownLatch(1);
    final CountDownLatch stopFlushLatch = new CountDownLatch(1);

    // 2 because either total or partial has to finish first
    final CountDownLatch flushStartReceived = new CountDownLatch(2);

    // 5 because we have total and partial flush
    final CountDownLatch flushStopReceived = new CountDownLatch(5);

    Thread t1 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              boolean rc = Util.startFlush(c1);
              System.out.println("t1: rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c1.stopFlush();
            }
          }
        };

    Thread t2 =
        new Thread() {
          public void run() {
            try {
              startFlushLatch.await();
              // partial, only between c2 and c3
              boolean rc = Util.startFlush(c2, (Arrays.asList(c2.getAddress(), c3.getAddress())));
              System.out.println("t2: partial flush rc=" + rc);
            } catch (InterruptedException e) {
              interrupt();
            }

            try {
              stopFlushLatch.await();
            } catch (InterruptedException e) {
              interrupt();
            } finally {
              c2.stopFlush(Arrays.asList(c2.getAddress(), c3.getAddress()));
            }
          }
        };

    Listener l1 = new Listener("c1", c1, flushStartReceived, flushStopReceived);
    Listener l2 = new Listener("c2", c2, flushStartReceived, flushStopReceived);
    Listener l3 = new Listener("c3", c3, flushStartReceived, flushStopReceived);

    t1.start();
    t2.start();

    startFlushLatch.countDown();

    assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));

    // at this stage both channels should have started a flush?
    stopFlushLatch.countDown();

    t1.join();
    t2.join();

    assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));

    assert l1.blockReceived;
    assert l1.unblockReceived;
    assert l2.blockReceived;
    assert l2.unblockReceived;
    assert l3.blockReceived;
    assert l3.unblockReceived;
  }