modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java | 41 ++++++---- modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java | 8 + modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java | 23 ++--- 3 files changed, 46 insertions(+), 26 deletions(-)
New commits: commit 5ef9c47ee8edab0fd0558a208911cc31dfb5d1dc Author: Jay Shaughnessy jshaughn@redhat.com Date: Wed Feb 27 09:15:20 2013 -0500
Try to stop generating as many ERRORs in the agent.log when the PC is shut down, typically for normal reasons.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java index 0470d9b..7c0a21b 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainer.java @@ -259,6 +259,21 @@ public class PluginContainer { }
/** + * If the plugin container has been initialized, the plugins have started work, and the container is + * not actively shutting down, this returns <code>true</code>. + * + * @return <code>true</code> if the plugin container was initialized, started and is not shutting down; <code>false</code> otherwise + */ + public boolean isRunning() { + Lock lock = obtainReadLock(); + try { + return started && !shuttingDown; + } finally { + releaseLock(lock); + } + } + + /** * Initializes the plugin container which initializes all internal managers. Once initialized, all plugins will be * activated, metrics will begin getting collected and automatic discovery will start. * @@ -360,8 +375,8 @@ public class PluginContainer {
if (configuration.isWaitForShutdownServiceTermination()) { log.info("Plugin container shutdown will wait up to " - + configuration.getShutdownServiceTerminationTimeout() - + " seconds for shut down background threads to terminate."); + + configuration.getShutdownServiceTerminationTimeout() + + " seconds for shut down background threads to terminate."); }
driftManager.shutdown(); @@ -389,12 +404,12 @@ public class PluginContainer { if (configuration.isWaitForShutdownServiceTermination()) { if (shutdownGracefully) { long elapsedMillis = System.currentTimeMillis() - this.shutdownStartTime; - String elapsedTimeString = (elapsedMillis >= 1000) ? - (elapsedMillis / 1000) + " seconds" : "less than 1 second"; + String elapsedTimeString = (elapsedMillis >= 1000) ? (elapsedMillis / 1000) + " seconds" + : "less than 1 second"; log.info("All shut down background threads have terminated (" + elapsedTimeString + " elapsed)."); } else { log.warn("Timed out after " + configuration.getShutdownServiceTerminationTimeout() - + " seconds while waiting for shut down background threads to terminate."); + + " seconds while waiting for shut down background threads to terminate."); } }
@@ -770,14 +785,14 @@ public class PluginContainer { try { logWaitingForExecutorServiceTerminationDebugMessage(executorService, remainingShutdownTimeoutMillis); boolean executorTerminated = executorService.awaitTermination(remainingShutdownTimeoutMillis, - TimeUnit.MILLISECONDS); + TimeUnit.MILLISECONDS); if (!executorTerminated) { String poolName = getPoolName(executorService); if (poolName != null) { int activeThreadsInPool = getActiveThreadCount(poolName); log.warn("Timed out after [" + (remainingShutdownTimeoutMillis / 1000) - + "] seconds while waiting for all threads in pool [" + poolName + "] to terminate - [" - + activeThreadsInPool + "] threads in the pool are still active."); + + "] seconds while waiting for all threads in pool [" + poolName + "] to terminate - [" + + activeThreadsInPool + "] threads in the pool are still active."); } } } catch (InterruptedException e) { @@ -795,13 +810,13 @@ public class PluginContainer { }
private void logWaitingForExecutorServiceTerminationDebugMessage(ExecutorService executorService, - long remainingShutdownTimeoutMillis) { + long remainingShutdownTimeoutMillis) { if (log.isDebugEnabled()) { String poolName = getPoolName(executorService); if (poolName != null) { int activeThreadsInPool = getActiveThreadCount(poolName); log.debug("Waiting up to [" + (remainingShutdownTimeoutMillis / 1000) + "] seconds for [" - + activeThreadsInPool + "] threads in pool [" + poolName + "] to terminate..."); + + activeThreadsInPool + "] threads in pool [" + poolName + "] to terminate..."); } } } @@ -812,8 +827,8 @@ public class PluginContainer { int activeThreadsInPool = getActiveThreadCount(poolName); if (activeThreadsInPool > 0) { log.debug("Not waiting for all threads in pool [" + poolName - + "] to terminate, since the configured plugin container shutdown timeout has already elapsed - [" - + activeThreadsInPool + "] threads in the pool are still active."); + + "] to terminate, since the configured plugin container shutdown timeout has already elapsed - [" + + activeThreadsInPool + "] threads in the pool are still active."); } } } @@ -822,7 +837,7 @@ public class PluginContainer { if (executorService instanceof ThreadPoolExecutor) { ThreadFactory threadFactory = ((ThreadPoolExecutor) executorService).getThreadFactory(); if (threadFactory instanceof LoggingThreadFactory) { - return ((LoggingThreadFactory)threadFactory).getPoolName(); + return ((LoggingThreadFactory) threadFactory).getPoolName(); } } return null; diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java index 7231360..caa9260 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java @@ -2614,8 +2614,12 @@ public class InventoryManager extends AgentService implements ContainerService, } catch (Throwable e) { // TODO GH: Add server/parent - up/down semantics so this won't happen just because a server is not up long elapsedTime = System.currentTimeMillis() - startTime; - log.warn("Failure during discovery for [" + resourceType.getName() + "] Resources - failed after " - + elapsedTime + " ms.", e); + if (!PluginContainer.getInstance().isRunning()) { + log.warn("Could not complete discovery, plugin container was shut down."); + } else { + log.warn("Failure during discovery for [" + resourceType.getName() + "] Resources - failed after " + + elapsedTime + " ms.", e); + } return Collections.EMPTY_SET; }
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java index 61733b9..c160b78 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/DiscoveryComponentProxyFactory.java @@ -74,8 +74,8 @@ public class DiscoveryComponentProxyFactory { */ @SuppressWarnings("unchecked") public <T> T getDiscoveryComponentProxy(ResourceType type, ResourceDiscoveryComponent component, long timeout, - Class<T> componentInterface, ResourceContainer parentResourceContainer) - throws PluginContainerException, BlacklistedException { + Class<T> componentInterface, ResourceContainer parentResourceContainer) throws PluginContainerException, + BlacklistedException {
if (isResourceTypeBlacklisted(type)) { throw new BlacklistedException("Discovery component for resource type [" + type + "] has been blacklisted"); @@ -84,8 +84,8 @@ public class DiscoveryComponentProxyFactory { try { PluginComponentFactory pluginComponentFactory = PluginContainer.getInstance().getPluginComponentFactory();
- ClassLoader pluginClassLoader = - pluginComponentFactory.getDiscoveryComponentClassLoader(parentResourceContainer, type.getPlugin()); + ClassLoader pluginClassLoader = pluginComponentFactory.getDiscoveryComponentClassLoader( + parentResourceContainer, type.getPlugin());
// This is the handler that will actually invoke the method calls. ResourceDiscoveryComponentInvocationHandler handler = new ResourceDiscoveryComponentInvocationHandler(type, @@ -120,11 +120,10 @@ public class DiscoveryComponentProxyFactory { */ @SuppressWarnings("unchecked") public ResourceDiscoveryComponent getDiscoveryComponentProxy(ResourceType type, - ResourceDiscoveryComponent component, long timeout, - ResourceContainer parentResourceContainer) - throws PluginContainerException, BlacklistedException { + ResourceDiscoveryComponent component, long timeout, ResourceContainer parentResourceContainer) + throws PluginContainerException, BlacklistedException { return getDiscoveryComponentProxy(type, component, timeout, ResourceDiscoveryComponent.class, - parentResourceContainer); + parentResourceContainer); }
public void initialize() { @@ -181,7 +180,7 @@ public class DiscoveryComponentProxyFactory { private final ResourceType resourceType; private final ClassLoader pluginClassLoader; private Class<?> componentInterface; - + public ResourceDiscoveryComponentInvocationHandler(ResourceType type, ResourceDiscoveryComponent component, long timeout, ClassLoader pluginClassLoader, Class<?> componentInterface) { if (timeout <= 0) { @@ -220,7 +219,9 @@ public class DiscoveryComponentProxyFactory { try { return future.get(this.timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { - log.error("Thread [" + Thread.currentThread().getName() + "] was interrupted."); + if (log.isDebugEnabled()) { + log.debug("Thread [" + Thread.currentThread().getName() + "] was interrupted."); + } future.cancel(true); // this is a daemon thread, let's try to cancel it throw new RuntimeException(invokedMethodString(method, args, "was interrupted."), e); } catch (ExecutionException e) { @@ -236,7 +237,7 @@ public class DiscoveryComponentProxyFactory { if (thread != null) { StackTraceElement[] stackTrace = thread.getStackTrace(); cause = new Exception(thread + " with id [" + thread.getId() - + "] is hung. This exception contains its stack trace."); + + "] is hung. This exception contains its stack trace."); cause.setStackTrace(stackTrace); } else { cause = null;
rhq-commits@lists.fedorahosted.org