Example #1
1
  /**
   * Start this server. If we manage an own HttpServer, then the HttpServer will be started as well.
   */
  public void start() {
    // URL as configured takes precedence
    String configUrl =
        NetworkUtil.replaceExpression(config.getJolokiaConfig().get(ConfigKey.DISCOVERY_AGENT_URL));
    jolokiaHttpHandler.start(
        lazy, configUrl != null ? configUrl : url, config.getAuthenticator() != null);

    if (httpServer != null) {
      // Starting our own server in an own thread group with a fixed name
      // so that the cleanup thread can recognize it.
      ThreadGroup threadGroup = new ThreadGroup("jolokia");
      threadGroup.setDaemon(false);

      Thread starterThread =
          new Thread(
              threadGroup,
              new Runnable() {
                @Override
                public void run() {
                  httpServer.start();
                }
              });
      starterThread.start();
      cleaner = new CleanupThread(httpServer, threadGroup);
      cleaner.start();
    }
  }
Example #2
0
 /**
  * Start the cleaner thread and pray to God it finishes.
  *
  * @param player Person to blame for the lag. Or null.
  */
 public static void clean(Player player) {
   if (cleanupThread != null && cleanupThread.done) {
     cleanupThread = null;
   }
   if (cleanupThread == null || !cleanupThread.isAlive()) {
     cleanupThread = new CleanupThread(player);
     cleanupThread.start();
   } else {
     if (player != null)
       player.chat(BigBrother.premessage + " Cleaner already busy.  Try again later.");
   }
 }
Example #3
0
  /** Stop the HTTP server */
  public void stop() {
    jolokiaHttpHandler.stop();

    if (cleaner != null) {
      cleaner.stopServer();
    }
  }
Example #4
0
 public void destroy() {
   try {
     if (cleanupThread != null) {
       cleanupThread.stopThread();
     }
   } finally {
     isDestroyed = true;
   }
 }
 @Override
 protected void finalize() throws Throwable {
   adapterCleanupThread.stopCleaner();
   for (ResourceSet rs : resourceSets.keySet()) {
     if (rs != null && adapter != null) {
       rs.eAdapters().remove(adapter);
     }
   }
   super.finalize();
 }
Example #6
0
 public ConcurrentLRUCache(
     int upperWaterMark,
     final int lowerWaterMark,
     int acceptableWatermark,
     int initialSize,
     boolean runCleanupThread,
     boolean runNewThreadForCleanup,
     EvictionListener<K, V> evictionListener) {
   if (upperWaterMark < 1) throw new IllegalArgumentException("upperWaterMark must be > 0");
   if (lowerWaterMark >= upperWaterMark)
     throw new IllegalArgumentException("lowerWaterMark must be  < upperWaterMark");
   map = new ConcurrentHashMap<Object, CacheEntry>(initialSize);
   newThreadForCleanup = runNewThreadForCleanup;
   this.upperWaterMark = upperWaterMark;
   this.lowerWaterMark = lowerWaterMark;
   this.acceptableWaterMark = acceptableWatermark;
   this.evictionListener = evictionListener;
   if (runCleanupThread) {
     cleanupThread = new CleanupThread(this);
     cleanupThread.start();
   }
 }
Example #7
0
  public Object put(K key, V val) {
    if (val == null) return null;
    CacheEntry e = new CacheEntry(key, val, stats.accessCounter.incrementAndGet());
    CacheEntry oldCacheEntry = map.put(key, e);
    if (oldCacheEntry == null) {
      stats.size.incrementAndGet();
    }
    if (islive) {
      stats.putCounter.incrementAndGet();
    } else {
      stats.nonLivePutCounter.incrementAndGet();
    }

    // Check if we need to clear out old entries from the cache.
    // isCleaning variable is checked instead of markAndSweepLock.isLocked()
    // for performance because every put invokation will check until
    // the size is back to an acceptable level.
    //
    // There is a race between the check and the call to markAndSweep, but
    // it's unimportant because markAndSweep actually aquires the lock or returns if it can't.
    //
    // Thread safety note: isCleaning read is piggybacked (comes after) other volatile reads
    // in this method.
    if (stats.size.get() > upperWaterMark && !isCleaning) {
      if (newThreadForCleanup) {
        new Thread() {
          public void run() {
            markAndSweep();
          }
        }.start();
      } else if (cleanupThread != null) {
        cleanupThread.wakeThread();
      } else {
        markAndSweep();
      }
    }
    return oldCacheEntry == null ? null : oldCacheEntry.value;
  }
 public EventManagerTableBased() {
   resourceSets = new WeakHashMap<ResourceSet, Object>();
   registrationManager = new RegistrationManagerTableBased();
   adapterCleanupThread = new CleanupThread(adaptersNoLongerStronglyReferenced, this);
   adapterCleanupThread.start();
 }