Example #1
0
 // It's important that this be the _only_ thread removing things from pendingDynamicCloses!
 // This is single-threaded, but I tried a multi-threaded approach and didn't see any performance
 // gains, so
 // there's no good justification for the complexity. I suspect that the locking on things like
 // DefaultSolrCoreState
 // essentially create a single-threaded process anyway.
 @Override
 public void run() {
   while (!container.isShutDown()) {
     synchronized (solrCores.getModifyLock()) { // need this so we can wait and be awoken.
       try {
         solrCores.getModifyLock().wait();
       } catch (InterruptedException e) {
         // Well, if we've been told to stop, we will. Otherwise, continue on and check to see if
         // there are
         // any cores to close.
       }
     }
     for (SolrCore removeMe = solrCores.getCoreToClose();
         removeMe != null && !container.isShutDown();
         removeMe = solrCores.getCoreToClose()) {
       try {
         removeMe.close();
       } finally {
         solrCores.removeFromPendingOps(removeMe.getName());
       }
     }
   }
 }
Example #2
0
  public static boolean injectNonGracefullClose(CoreContainer cc) {
    if (cc.isShutDown() && nonGracefullClose != null) {
      Random rand = random();
      if (null == rand) return true;

      Pair<Boolean, Integer> pair = parseValue(nonGracefullClose);
      boolean enabled = pair.first();
      int chanceIn100 = pair.second();
      if (enabled && rand.nextInt(100) >= (100 - chanceIn100)) {
        if (rand.nextBoolean()) {
          throw new TestShutdownFailError("Test exception for non graceful close");
        } else {

          final Thread cthread = Thread.currentThread();
          TimerTask task =
              new TimerTask() {
                @Override
                public void run() {
                  // as long as places that catch interruptedexception reset that
                  // interrupted status,
                  // we should only need to do it once

                  try {
                    // call random() again to get the correct one for this thread
                    Random taskRand = random();
                    Thread.sleep(taskRand.nextInt(1000));
                  } catch (InterruptedException e) {

                  }

                  cthread.interrupt();
                  timers.remove(this);
                  cancel();
                }
              };
          Timer timer = new Timer();
          timers.add(timer);
          timer.schedule(task, rand.nextInt(500));
        }
      }
    }
    return true;
  }