Esempio n. 1
1
 private void shutdown() {
   writerRunner.shutdown();
   readerRunner.shutdown();
   if (writerThread.isAlive()) {
     writerThread.interrupt();
   }
   if (readerThread.isAlive()) {
     readerThread.interrupt();
   }
 }
Esempio n. 2
1
  public static void killAWTThreads(ThreadGroup threadGroup) {
    Thread[] threadList = new Thread[threadGroup.activeCount()];

    threadGroup.enumerate(threadList);

    for (int i = 0; i < threadList.length; i++) {

      Thread t = threadList[i];

      if (t != null) {

        String name = t.getName();

        if (name.startsWith("AWT")) {

          out("Interrupting thread '".concat(t.toString()).concat("'"));

          t.interrupt();
        }
      }
    }

    if (threadGroup.getParent() != null) {

      killAWTThreads(threadGroup.getParent());
    }
  }
  @Test
  public void testAPIMPubAndReceipt() throws Exception {

    // Create a listener
    CountDownLatch listeningSignal = new CountDownLatch(1);
    CountDownLatch doneSignal = new CountDownLatch(1);
    Thread listener = new ListenerThread(listeningSignal, doneSignal);
    listener.start();
    listeningSignal.await();

    // Publish an APIM event
    try {
      Map<String, List<String>> mdMap = new HashMap<String, List<String>>();
      List<String> destinations = new ArrayList<String>();
      destinations.add("fedora.apim.update");
      mdMap.put(MessageType.apimUpdate.toString(), destinations);
      Messaging msg = new MessagingImpl(getBaseURL(), mdMap, jmsMgr);
      Object[] invocationHandlers = {new NotificationInvocationHandler(msg)};
      Management mgmt = new MockManagementDelegate();
      Management proxy = (Management) ProxyFactory.getProxy(mgmt, invocationHandlers);
      proxy.purgeObject(new MockContext(), "demo:test", null);
    } catch (Exception e) {
      listener.interrupt();
      throw e;
    }
    // await message receipt & evaluation
    doneSignal.await();
  }
Esempio n. 4
0
 private static <R> void verifyInvocationCannotBeInterrupted(final WSTester<R> inTester)
     throws Exception {
   resetServiceParameters();
   getMockSAService().setSleep(true);
   inTester.setReturnValue(false);
   final Semaphore sema = new Semaphore(0);
   final AtomicReference<Exception> interruptFailure = new AtomicReference<Exception>();
   Thread t =
       new Thread() {
         @Override
         public void run() {
           sema.release();
           try {
             inTester.invokeApi(false);
           } catch (Exception ex) {
             interruptFailure.set(ex);
           }
         }
       };
   t.start();
   // Wait for the thread to be started
   sema.acquire();
   // Interrupt it as soon as it is found started
   t.interrupt();
   // wait for it to end
   t.join();
   // verify that we are not able to interrupt it
   assertNull("API invocation got interrupted!", interruptFailure.get());
 }
Esempio n. 5
0
  /** Stops unicast and multicast receiver threads */
  void stopThreads() {
    Thread tmp;

    // 1. Stop the multicast receiver thread
    if (mcast_receiver != null) {
      if (mcast_receiver.isAlive()) {
        tmp = mcast_receiver;
        mcast_receiver = null;
        closeMulticastSocket(); // will cause the multicast thread to terminate
        tmp.interrupt();
        try {
          tmp.join(100);
        } catch (Exception e) {
        }
        tmp = null;
      }
      mcast_receiver = null;
    }

    // 2. Stop the unicast receiver thread
    if (ucast_receiver != null) {
      ucast_receiver.stop();
      ucast_receiver = null;
    }

    // 3. Stop the in_packet_handler thread
    if (incoming_packet_handler != null) {
      incoming_packet_handler.stop();
    }
  }
Esempio n. 6
0
 @Override
 protected void onCancelPressed() {
   super.onUpdatePressed();
   if (installerThread != null) {
     installerThread.interrupt();
   }
 }
Esempio n. 7
0
 public void run() {
   if (Thread.currentThread() != this.mt)
     throw (new RuntimeException("MainFrame is being run from an invalid context"));
   Thread ui = new HackThread(p, "Haven UI thread");
   ui.start();
   try {
     try {
       Session sess = null;
       while (true) {
         UI.Runner fun;
         if (sess == null) {
           Bootstrap bill = new Bootstrap(Config.defserv, Config.mainport);
           if ((Config.authuser != null) && (Config.authck != null)) {
             bill.setinitcookie(Config.authuser, Config.authck);
             Config.authck = null;
           }
           fun = bill;
           setTitle(String.format("Amish Paradise %s", version));
         } else {
           fun = new RemoteUI(sess);
           setTitle(String.format("Amish Paradise %s \u2013 %s", version, sess.username));
         }
         sess = fun.run(p.newui(sess));
       }
     } catch (InterruptedException e) {
     }
     savewndstate();
   } finally {
     ui.interrupt();
     dispose();
   }
 }
  public void onDestroy() {
    running = false;
    if (scanThread != null) scanThread.interrupt();

    if (myWLocate != null) myWLocate.doPause();

    sensorManager.unregisterListener(
        this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER));

    if (scanData.getmView() != null) {
      ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(scanData.getmView());
      scanData.setmView(null);
    }
    try {
      if (wl != null) wl.release();
    } catch (RuntimeException re) {
    }
    wl = null;
    try {
      scanThread.join(1000);
    } catch (InterruptedException ie) {

    }
    System.exit(0);
  }
Esempio n. 9
0
 /** Stop listening on the server port. */
 public void shutdown() {
   if (listener != null) {
     Thread l = listener;
     listener = null;
     l.interrupt();
   }
 }
  /** awaitUninterruptibly is uninterruptible */
  public void testAwaitUninterruptibly() {
    final Mutex sync = new Mutex();
    final ConditionObject c = sync.newCondition();
    final BooleanLatch pleaseInterrupt = new BooleanLatch();
    Thread t =
        newStartedThread(
            new CheckedRunnable() {
              public void realRun() {
                sync.acquire();
                assertTrue(pleaseInterrupt.releaseShared(0));
                c.awaitUninterruptibly();
                assertTrue(Thread.interrupted());
                assertHasWaitersLocked(sync, c, NO_THREADS);
                sync.release();
              }
            });

    pleaseInterrupt.acquireShared(0);
    sync.acquire();
    assertHasWaitersLocked(sync, c, t);
    sync.release();
    t.interrupt();
    assertHasWaitersUnlocked(sync, c, t);
    assertThreadStaysAlive(t);
    sync.acquire();
    assertHasWaitersLocked(sync, c, t);
    assertHasExclusiveQueuedThreads(sync, NO_THREADS);
    c.signal();
    assertHasWaitersLocked(sync, c, NO_THREADS);
    assertHasExclusiveQueuedThreads(sync, t);
    sync.release();
    awaitTermination(t);
  }
Esempio n. 11
0
 public void stopEvaluate() {
   // user requested run be stopped so tell
   // run thread to stop
   Thread tmp = runThread;
   runThread = null;
   tmp.interrupt();
 }
 /** getSharedQueuedThreads returns all shared waiting threads */
 public void testGetSharedQueuedThreads_Shared() {
   final BooleanLatch l = new BooleanLatch();
   assertHasSharedQueuedThreads(l, NO_THREADS);
   Thread t1 =
       newStartedThread(
           new CheckedInterruptedRunnable() {
             public void realRun() throws InterruptedException {
               l.acquireSharedInterruptibly(0);
             }
           });
   waitForQueuedThread(l, t1);
   assertHasSharedQueuedThreads(l, t1);
   Thread t2 =
       newStartedThread(
           new CheckedRunnable() {
             public void realRun() throws InterruptedException {
               l.acquireSharedInterruptibly(0);
             }
           });
   waitForQueuedThread(l, t2);
   assertHasSharedQueuedThreads(l, t1, t2);
   t1.interrupt();
   awaitTermination(t1);
   assertHasSharedQueuedThreads(l, t2);
   assertTrue(l.releaseShared(0));
   awaitTermination(t2);
   assertHasSharedQueuedThreads(l, NO_THREADS);
 }
Esempio n. 13
0
 private void timeoutIfStillRunning(Thread t) {
   if (t.isAlive()) {
     log.warn("Scenario timed out after " + scenarioTimeoutMillis + " millis, will interrupt");
     stepProcessor.setInterruptingOnTimeout(true);
     t.interrupt(); // first try to interrupt to see if this can unblock/fail the scenario
   }
 }
  /** {@inheritDoc} */
  public void updateBlock(Block oldblock, Block newblock) throws IOException {
    if (oldblock.getBlockId() != newblock.getBlockId()) {
      throw new IOException(
          "Cannot update oldblock (=" + oldblock + ") to newblock (=" + newblock + ").");
    }

    for (; ; ) {
      final List<Thread> threads = tryUpdateBlock(oldblock, newblock);
      if (threads == null) {
        return;
      }

      // interrupt and wait for all ongoing create threads
      for (Thread t : threads) {
        t.interrupt();
      }
      for (Thread t : threads) {
        try {
          t.join();
        } catch (InterruptedException e) {
          DataNode.LOG.warn("interruptOngoingCreates: t=" + t, e);
        }
      }
    }
  }
Esempio n. 15
0
 public synchronized void stop() {
   running = false;
   try {
     thread.join();
   } catch (InterruptedException e) {
     thread.interrupt();
   }
 }
Esempio n. 16
0
 public synchronized void countDownInterrupt() {
   // In MetaSearchImpl.topTask_search() we schedule multiple MetaSearchResult.topTask_run()
   // tasks which then call countDownInterrupt
   // because we synchronize we don't check here even though that's a little more dangerous that I
   // would like it to be...
   // perm.checkWrite(this);
   if (thread_ != null && --counter_ == 0) thread_.interrupt();
 }
Esempio n. 17
0
 /** Request that the loading of the applet be stopped. */
 protected synchronized void stopLoading() {
   // REMIND: fill in the body
   if (loaderThread != null) {
     // System.out.println("Interrupting applet loader thread: " + loaderThread);
     loaderThread.interrupt();
   } else {
     setLoadAbortRequest();
   }
 }
Esempio n. 18
0
 void setMessage(Animator a) {
   anim = a;
   who.setText(a.author());
   ref.setText(a.description());
   pan.remove(last);
   last = a.container();
   pan.add(last, "Center");
   if (T != null) T.interrupt();
 }
 @Override
 public void interrupt() {
   try {
     jmsMgr.close();
   } catch (MessagingException e) {
     fail(e.getMessage());
   } finally {
     super.interrupt();
   }
 }
  @Override
  public void testEnded(String host) {
    workerThread.interrupt();
    shutdownConnectors();

    // reset autoFileName for next test run
    autoFileBaseName = null;
    counter = 0;

    super.testEnded(host);
  }
Esempio n. 21
0
 protected void handleInterruptRequest(Address source, long requestId) {
   Owner owner = new Owner(source, requestId);
   Runnable runnable = removeKeyForValue(_running, owner);
   Thread thread = null;
   if (runnable != null) {
     thread = _runnableThreads.remove(runnable);
   }
   if (thread != null) {
     thread.interrupt();
   } else if (log.isTraceEnabled())
     log.trace("Message could not be interrupted due to it already returned");
 }
Esempio n. 22
0
 public void stop() {
   Thread tmp;
   if (thread != null && thread.isAlive()) {
     running = false;
     tmp = thread;
     thread = null;
     closeSocket(); // this will cause the thread to break out of its loop
     tmp.interrupt();
     tmp = null;
   }
   thread = null;
 }
Esempio n. 23
0
  @Test
  public void testMapRecordIdleEvictionOnMigration() throws InterruptedException {
    Config cfg = new Config();
    final String name = "testMapRecordIdleEvictionOnMigration";
    MapConfig mc = cfg.getMapConfig(name);
    int maxIdleSeconds = 10;
    int size = 100;
    final int nsize = size / 5;
    mc.setMaxIdleSeconds(maxIdleSeconds);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);

    HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
    final IMap map = instance1.getMap(name);
    final CountDownLatch latch = new CountDownLatch(size - nsize);
    map.addEntryListener(
        new EntryAdapter() {
          public void entryEvicted(EntryEvent event) {
            latch.countDown();
          }
        },
        false);

    for (int i = 0; i < size; i++) {
      map.put(i, i);
    }
    final Thread thread =
        new Thread(
            new Runnable() {
              public void run() {
                while (!Thread.currentThread().isInterrupted()) {
                  try {
                    for (int i = 0; i < nsize; i++) {
                      map.get(i);
                    }
                    Thread.sleep(1000);
                  } catch (HazelcastInstanceNotActiveException e) {
                    return;
                  } catch (InterruptedException e) {
                    return;
                  }
                }
              }
            });
    thread.start();
    HazelcastInstance instance2 = factory.newHazelcastInstance(cfg);
    HazelcastInstance instance3 = factory.newHazelcastInstance(cfg);

    assertTrue(latch.await(1, TimeUnit.MINUTES));
    Assert.assertEquals(nsize, map.size());

    thread.interrupt();
    thread.join(5000);
  }
 /** Disconnects from running debugged process. */
 public void disconnect() throws DebuggerException {
   threadGroup.setRemoteThreadGroup(null);
   if (remoteDebugger != null) {
     remoteDebugger.close();
     remoteDebugger = null;
   }
   if (debuggerThread != null) {
     debuggerThread.interrupt();
     debuggerThread.stop();
   }
   super.finishDebugger();
   synchronizer = null;
 }
 @Override
 public synchronized void close() {
   logger.info("closing Remote River on this node");
   closed = true;
   if (coordinatorThread != null) {
     coordinatorThread.interrupt();
   }
   // free instances created in #start()
   coordinatorThread = null;
   coordinatorInstance = null;
   synchronized (riverInstances) {
     riverInstances.remove(riverName().getName());
   }
 }
Esempio n. 26
0
  @Override
  public void stop() {
    isStopped = true;

    if (schedulingThread != null) {
      synchronized (schedulingThread) {
        schedulingThread.interrupt();
      }
    }
    candidateWorkers.clear();
    scheduledRequests.clear();
    LOG.info("Task Scheduler stopped");
    super.stop();
  }
  /** tryAcquireNanos is interruptible */
  public void testTryAcquireNanos_Interruptible() {
    final Mutex sync = new Mutex();
    sync.acquire();
    Thread t =
        newStartedThread(
            new CheckedInterruptedRunnable() {
              public void realRun() throws InterruptedException {
                sync.tryAcquireNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
              }
            });

    waitForQueuedThread(sync, t);
    t.interrupt();
    awaitTermination(t);
  }
 /** @see java.lang.Runnable#run() */
 public void run() {
   final Thread thread = Thread.currentThread();
   while (!Thread.interrupted()) {
     m_set.add(m_touchable);
     m_list.add(m_touchable);
     try {
       synchronized (thread) {
         thread.wait();
       }
     } catch (InterruptedException e) {
       // propagate interrupt
       thread.interrupt();
     }
   }
 }
 /** Disconnects from running debugged process. */
 public void disconnect() throws DebuggerException {
   if (breakpointMain != null) {
     for (int x = 0; x < breakpointMain.length; x++) breakpointMain[x].remove();
     breakpointMain = null;
   }
   try {
     if (virtualMachine != null) virtualMachine.dispose();
   } catch (VMDisconnectedException e) {
   }
   if (threadManager != null) threadManager.finish();
   if (debuggerThread != null) {
     debuggerThread.interrupt();
     debuggerThread.stop();
   }
   super.finishDebugger();
 }
Esempio n. 30
0
 public void shutdown(boolean join) {
   shutdown = true;
   if (q2Thread != null) {
     log.info("shutting down");
     q2Thread.interrupt();
     if (join) {
       try {
         q2Thread.join();
         log.info("shutdown done");
       } catch (InterruptedException e) {
         log.warn(e);
       }
     }
   }
   q2Thread = null;
 }