modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/component/ComponentInvocationContext.java
| 44 +++
modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
| 59 +++-
modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/operation/OperationFacet.java
| 22 -
modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/upgrade/ResourceUpgradeContext.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
| 21 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/component/ComponentInvocationContextImpl.java
| 84 ++++++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
| 8
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
| 20 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AvailabilityExecutor.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
| 28 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
| 60 ++--
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
| 20 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/TimeoutException.java
| 21 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
| 18 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
| 21 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentUtil.java
| 49 +--
modules/core/plugin-container/src/test/java/org/rhq/core/pc/component/ComponentInvocationContextImplTest.java
| 92 ++++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/ResourceContainerTest.java
| 139 +++++++---
modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
| 16 -
modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractDestinationTest.java
| 20 -
modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractResourceTest.java
| 22 -
modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/util/AppServerUtils.java
| 22 -
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
| 50 +--
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
| 8
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/WebConnectorComponentTest.java
| 2
modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/AppServerUtils.java
| 20 -
modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/CacheComponentTest.java
| 8
modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/OperationTest.java
| 21 +
modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
| 21 +
34 files changed, 679 insertions(+), 363 deletions(-)
New commits:
commit ba84865a0e0172cda10c1350fef054248c43ceed
Author: Thomas Segismont <tsegismo(a)redhat.com>
Date: Thu Jun 27 16:09:58 2013 +0200
Bug 966777 - EAP 6 plug-in is using a hard-coded operation timeout for start and stop
instead of using the operation timeout or agent's default operation timeout of 10
minutes
The component invocation handler now has a transferInterrupt parameter. If set to
true, the component invocation thread will be interrupted when the caller thread is.
Introduce ComponentInvocationContext class. An instance of this class is created by
the plugin container and bound to facet-locked component invocation thread.
Make BaseServerComponent use ComponentInvocationContext to deal with operation timeout
or cancellation.
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/component/ComponentInvocationContext.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/component/ComponentInvocationContext.java
new file mode 100644
index 0000000..4ccfc9d
--- /dev/null
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/component/ComponentInvocationContext.java
@@ -0,0 +1,44 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package org.rhq.core.pluginapi.component;
+
+/**
+ * An instance of this class is created by the plugin container and bound to facet-locked
component invocation
+ * thread.
+ *
+ * It helps to detect interrupted component invocations (canceled or timed out).
+ *
+ * @author Thomas Segismont
+ */
+public interface ComponentInvocationContext {
+
+ /**
+ * Whether the component invocation has been interrupted or not.
+ *
+ * @return true if component invocation has been interrupted, false otherwise.
+ */
+ boolean isInterrupted();
+
+
+ /**
+ * Mark this context as interrupted.
+ */
+ void markInterrupted();
+}
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
index f466df7..8c708db 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/inventory/ResourceContext.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pluginapi.inventory;
@@ -40,6 +36,7 @@ import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pluginapi.availability.AvailabilityCollectorRunnable;
import org.rhq.core.pluginapi.availability.AvailabilityContext;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
+import org.rhq.core.pluginapi.component.ComponentInvocationContext;
import org.rhq.core.pluginapi.content.ContentContext;
import org.rhq.core.pluginapi.event.EventContext;
import org.rhq.core.pluginapi.operation.OperationContext;
@@ -86,6 +83,7 @@ public class ResourceContext<T extends ResourceComponent<?>>
{
private final InventoryContext inventoryContext;
private final PluginContainerDeployment pluginContainerDeployment;
private final ResourceTypeProcesses trackedProcesses;
+ private final ComponentInvocationContext componentInvocationContext;
private static class Children {
public ResourceType resourceType;
@@ -122,6 +120,32 @@ public class ResourceContext<T extends
ResourceComponent<?>> {
private static Map<Children, ResourceTypeProcesses>
PROCESSES_PER_PARENT_PER_RESOURCE_TYPE = new HashMap<Children,
ResourceTypeProcesses>();
/**
+ * Creates a new {@link ResourceContext} object with a default {@link
ComponentInvocationContext}.
+ *
+ * @deprecated as of RHQ 4.9.
+ */
+ @Deprecated
+ public ResourceContext(Resource resource, T parentResourceComponent,
ResourceContext<?> parentResourceContext,
+ ResourceDiscoveryComponent<T> resourceDiscoveryComponent, SystemInfo
systemInfo, File temporaryDirectory,
+ File dataDirectory, String pluginContainerName, EventContext eventContext,
OperationContext operationContext,
+ ContentContext contentContext, AvailabilityContext availabilityContext,
InventoryContext inventoryContext,
+ PluginContainerDeployment pluginContainerDeployment) {
+ this(resource, parentResourceComponent, parentResourceContext,
resourceDiscoveryComponent, systemInfo,
+ temporaryDirectory, dataDirectory, pluginContainerName, eventContext,
operationContext, contentContext,
+ availabilityContext, inventoryContext, pluginContainerDeployment, new
ComponentInvocationContext() {
+ @Override
+ public boolean isInterrupted() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void markInterrupted() {
+ throw new UnsupportedOperationException();
+ }
+ });
+ }
+
+ /**
* Creates a new {@link ResourceContext} object.
*
* <b>NOTE:</b> The plugin container is responsible for instantiating
these objects; plugin writers should never
@@ -154,7 +178,7 @@ public class ResourceContext<T extends
ResourceComponent<?>> {
ResourceDiscoveryComponent<T> resourceDiscoveryComponent, SystemInfo
systemInfo, File temporaryDirectory,
File dataDirectory, String pluginContainerName, EventContext eventContext,
OperationContext operationContext,
ContentContext contentContext, AvailabilityContext availabilityContext,
InventoryContext inventoryContext,
- PluginContainerDeployment pluginContainerDeployment) {
+ PluginContainerDeployment pluginContainerDeployment, ComponentInvocationContext
componentInvocationContext) {
this.resourceKey = resource.getResourceKey();
this.resourceType = resource.getResourceType();
@@ -187,6 +211,7 @@ public class ResourceContext<T extends
ResourceComponent<?>> {
this.trackedProcesses = getTrackedProcesses(parentResourceUuid, resourceType);
this.resourceUuid = resource.getUuid();
+ this.componentInvocationContext = componentInvocationContext;
}
/**
@@ -562,4 +587,14 @@ public class ResourceContext<T extends
ResourceComponent<?>> {
return messageDigest.getDigestString();
}
-}
\ No newline at end of file
+
+ /**
+ * Return the {@link ComponentInvocationContext} object which plugins can use to
determine if the component
+ * invocation has been interrupted.
+ *
+ * @return a {@link ComponentInvocationContext} object
+ */
+ public ComponentInvocationContext getComponentInvocationContext() {
+ return componentInvocationContext;
+ }
+}
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/operation/OperationFacet.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/operation/OperationFacet.java
index 11ae84a..5834d83 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/operation/OperationFacet.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/operation/OperationFacet.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pluginapi.operation;
@@ -55,6 +51,10 @@ public interface OperationFacet {
* {@link OperationResult#setErrorMessage(String) error message} set, in which case,
the operation is also
* assumed to have failed.</p>
*
+ * <strong>From RHQ4.9 on, plugin developers should check {@link
org.rhq.core.pluginapi.component.ComponentInvocationContext#isInterrupted()}
+ * instead of {@link Thread#isInterrupted()}.</strong> An instance of this
class is created by the plugin container
+ * and can be returned by calling {@link
org.rhq.core.pluginapi.inventory.ResourceContext#getComponentInvocationContext()}.
+ *
* @param name the name of the operation
* @param parameters the parameters passed to the operation; even for operations
with no parameters, an empty
* config will be passed in by the plugin container
@@ -65,4 +65,4 @@ public interface OperationFacet {
* @throws Exception if failed to invoke the operation on the resource
*/
OperationResult invokeOperation(String name, Configuration parameters) throws
InterruptedException, Exception;
-}
\ No newline at end of file
+}
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/upgrade/ResourceUpgradeContext.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/upgrade/ResourceUpgradeContext.java
index 471978c..90e9f5d 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/upgrade/ResourceUpgradeContext.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/upgrade/ResourceUpgradeContext.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pluginapi.upgrade;
@@ -52,7 +48,7 @@ public class ResourceUpgradeContext<T extends
ResourceComponent<?>> extends Reso
private final String description;
/**
- * @see ResourceContext#ResourceContext(org.rhq.core.domain.resource.Resource,
org.rhq.core.pluginapi.inventory.ResourceComponent,
org.rhq.core.pluginapi.inventory.ResourceContext,
org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent,
org.rhq.core.system.SystemInfo, java.io.File, java.io.File, String,
org.rhq.core.pluginapi.event.EventContext,
org.rhq.core.pluginapi.operation.OperationContext,
org.rhq.core.pluginapi.content.ContentContext, java.util.concurrent.Executor,
org.rhq.core.pluginapi.inventory.PluginContainerDeployment)
+ * @see ResourceContext#ResourceContext(org.rhq.core.domain.resource.Resource,
org.rhq.core.pluginapi.inventory.ResourceComponent,
org.rhq.core.pluginapi.inventory.ResourceContext,
org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent,
org.rhq.core.system.SystemInfo, java.io.File, java.io.File, String,
org.rhq.core.pluginapi.event.EventContext,
org.rhq.core.pluginapi.operation.OperationContext,
org.rhq.core.pluginapi.content.ContentContext,
org.rhq.core.pluginapi.availability.AvailabilityContext,
org.rhq.core.pluginapi.inventory.InventoryContext,
org.rhq.core.pluginapi.inventory.PluginContainerDeployment)
*
* @since 4.0
*/
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
index ab79689..4cd148f 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java
@@ -1,24 +1,20 @@
/*
- * RHQ Management
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.bundle;
@@ -581,7 +577,8 @@ public class BundleManager extends AgentService implements
BundleAgentService, B
* @throws PluginContainerException on error
*/
protected BundleFacet getBundleFacet(int resourceId, long timeout) throws
PluginContainerException {
- return ComponentUtil.getComponent(resourceId, BundleFacet.class,
FacetLockType.READ, timeout, false, true);
+ return ComponentUtil.getComponent(resourceId, BundleFacet.class,
FacetLockType.READ, timeout, false, true,
+ false);
}
/**
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/component/ComponentInvocationContextImpl.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/component/ComponentInvocationContextImpl.java
new file mode 100644
index 0000000..491bb38
--- /dev/null
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/component/ComponentInvocationContextImpl.java
@@ -0,0 +1,84 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package org.rhq.core.pc.component;
+
+import org.rhq.core.pluginapi.component.ComponentInvocationContext;
+
+/**
+ * Plugin container implementation of {@link ComponentInvocationContext}. An instance of
this class will be created
+ * by the plugin container and put in the {@link
org.rhq.core.pluginapi.inventory.ResourceContext}.
+ *
+ * Component invocation threads MUST call
+ * {@link
#setLocalContext(org.rhq.core.pc.component.ComponentInvocationContextImpl.LocalContext)}
before executing
+ * component code.
+ *
+ * @author Thomas Segismont
+ */
+public final class ComponentInvocationContextImpl implements ComponentInvocationContext
{
+ private static final ThreadLocal<LocalContext> localContext = new
ThreadLocal<LocalContext>() {
+ @Override
+ protected LocalContext initialValue() {
+ return new LocalContext();
+ }
+ };
+
+ @Override
+ public boolean isInterrupted() {
+ return localContext.get().isInterrupted();
+ }
+
+ @Override
+ public void markInterrupted() {
+ localContext.get().markInterrupted();
+ }
+
+ /**
+ * Binds the specified {@link LocalContext} instance to the current thread.
+ *
+ * @param localContext
+ *
+ * @throws IllegalArgumentException if <code>localContext</code> is null
+ */
+ public void setLocalContext(LocalContext localContext) {
+ if (localContext == null) {
+ throw new IllegalArgumentException("localContext is null");
+ }
+ ComponentInvocationContextImpl.localContext.set(localContext);
+ }
+
+ /**
+ * Interrupted status holder. A single instance of this class should be bound to the
invocation thread by calling
+ * {@link
#setLocalContext(org.rhq.core.pc.component.ComponentInvocationContextImpl.LocalContext)}.
+ */
+ public static final class LocalContext implements ComponentInvocationContext {
+
+ private volatile boolean interrupted = false;
+
+ @Override
+ public boolean isInterrupted() {
+ return interrupted;
+ }
+
+ @Override
+ public void markInterrupted() {
+ interrupted = true;
+ }
+ }
+}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
index 1af10d6..627070a 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationCheckExecutor.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.configuration;
@@ -80,7 +80,7 @@ public class ConfigurationCheckExecutor implements Runnable, Callable {
try {
resourceComponent =
resourceContainer.createResourceComponentProxy(ConfigurationFacet.class,
- FacetLockType.NONE, CONFIGURATION_CHECK_TIMEOUT, true, false);
+ FacetLockType.NONE, CONFIGURATION_CHECK_TIMEOUT, true, false, true);
} catch (PluginContainerException e) {
// Expecting when the resource does not support configuration management
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
index fa2bf09..8ec5d59 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigurationManager.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.configuration;
@@ -301,7 +297,7 @@ public class ConfigurationManager extends AgentService implements
ContainerServi
throws PluginContainerException {
boolean daemonThread = (lockType != FacetLockType.WRITE);
return ComponentUtil.getComponent(resourceId, ConfigurationFacet.class, lockType,
FACET_METHOD_TIMEOUT,
- daemonThread, true);
+ daemonThread, true, daemonThread);
}
/**
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
index 50bb67a..0b9ef6d 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/content/ContentManager.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.content;
@@ -418,7 +414,7 @@ public class ContentManager extends AgentService implements
ContainerService, Co
// Perform the discovery
// Use only a read-locked component proxy
ContentFacet contentFacet = ComponentUtil.getComponent(resourceId,
ContentFacet.class, FacetLockType.READ,
- FACET_METHOD_TIMEOUT, false, true);
+ FACET_METHOD_TIMEOUT, false, true, false);
Set<ResourcePackageDetails> details =
contentFacet.discoverDeployedPackages(type);
@@ -655,7 +651,7 @@ public class ContentManager extends AgentService implements
ContainerService, Co
private ContentFacet findContentFacet(int resourceId) throws Exception {
// in case some calls to here need only the read lock - for now, always lock down
with the write lock
return ComponentUtil.getComponent(resourceId, ContentFacet.class,
FacetLockType.WRITE, FACET_METHOD_TIMEOUT,
- false, true);
+ false, true, false);
}
/**
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AvailabilityExecutor.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AvailabilityExecutor.java
index b4d7106..f9740df 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AvailabilityExecutor.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/AvailabilityExecutor.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.inventory;
@@ -206,7 +202,7 @@ public class AvailabilityExecutor implements Runnable,
Callable<AvailabilityRepo
AvailabilityFacet resourceComponent;
try {
resourceComponent =
resourceContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.NONE, GET_AVAILABILITY_TIMEOUT, true, false);
+ FacetLockType.NONE, GET_AVAILABILITY_TIMEOUT, true, false, true);
} catch (PluginContainerException e) {
// TODO (ips): Why aren't we logging this as an error?
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 704a230..7319c97 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
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
+
package org.rhq.core.pc.inventory;
import java.io.File;
@@ -91,6 +88,7 @@ import org.rhq.core.pc.agent.AgentRegistrar;
import org.rhq.core.pc.agent.AgentService;
import org.rhq.core.pc.availability.AvailabilityCollectorThreadPool;
import org.rhq.core.pc.availability.AvailabilityContextImpl;
+import org.rhq.core.pc.component.ComponentInvocationContextImpl;
import org.rhq.core.pc.content.ContentContextImpl;
import org.rhq.core.pc.drift.sync.DriftSyncManager;
import org.rhq.core.pc.event.EventContextImpl;
@@ -107,6 +105,7 @@ import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pc.util.LoggingThreadFactory;
import org.rhq.core.pluginapi.availability.AvailabilityContext;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
+import org.rhq.core.pluginapi.component.ComponentInvocationContext;
import org.rhq.core.pluginapi.content.ContentContext;
import org.rhq.core.pluginapi.event.EventContext;
import org.rhq.core.pluginapi.inventory.ClassLoaderFacet;
@@ -680,7 +679,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
long componentTimeout = (resourceCategory ==
ResourceCategory.SERVER) ? 10000 : 5000;
// We already possess the lock, so tell the proxy not to do any
locking of its own.
resourceComponent =
resourceContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.NONE, componentTimeout, true, true);
+ FacetLockType.NONE, componentTimeout, true, true, true);
availType = resourceComponent.getAvailability();
} catch (PluginContainerException e) {
log.error("Failed to retrieve ResourceComponent for " +
resource + ".", e);
@@ -1839,7 +1838,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
// Wrap the component in a proxy that will provide locking and a timeout
for the call to start().
component =
container.createResourceComponentProxy(ResourceComponent.class, FacetLockType.READ,
- COMPONENT_START_TIMEOUT, true, false);
+ COMPONENT_START_TIMEOUT, true, false, true);
} catch (Throwable t) {
container.setResourceComponentState(ResourceComponentState.STOPPED);
throw new PluginContainerException("Failed getting proxy for
resource " + resource + ".", t);
@@ -1896,7 +1895,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
getOperationContext(resource), // for operation manager access
getContentContext(resource), // for content manager access
getAvailabilityContext(resource, this.availabilityCollectors), // for
components that want to perform async avail checking
- getInventoryContext(resource),
this.configuration.getPluginContainerDeployment()); // helps components make
determinations of what to do
+ getInventoryContext(resource),
this.configuration.getPluginContainerDeployment(), // helps components make determinations
of what to do
+ new ComponentInvocationContextImpl());
}
public <T extends ResourceComponent<?>> ResourceUpgradeContext<T>
createResourceUpgradeContext(Resource resource,
@@ -2121,7 +2121,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
try {
ResourceComponent<?> component =
container.createResourceComponentProxy(ResourceComponent.class,
- FacetLockType.WRITE, COMPONENT_STOP_TIMEOUT, true, true);
+ FacetLockType.WRITE, COMPONENT_STOP_TIMEOUT, true, true, true);
component.stop();
if (log.isDebugEnabled()) {
log.debug("Successfully deactivated resource with id ["
+ resource.getId() + "].");
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
index 338676d..4cb2cff 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
@@ -1,27 +1,26 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
+
package org.rhq.core.pc.inventory;
+import static org.rhq.core.pc.component.ComponentInvocationContextImpl.LocalContext;
+
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
@@ -56,6 +55,7 @@ import org.rhq.core.domain.measurement.MeasurementDefinition;
import org.rhq.core.domain.measurement.MeasurementSchedule;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.pc.component.ComponentInvocationContextImpl;
import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pc.util.LoggingThreadFactory;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
@@ -407,13 +407,15 @@ public class ResourceContainer implements Serializable {
* it; value must be positive
* @param daemonThread whether or not the thread used for the invocation should be
a daemon thread
* @param onlyIfStarted if <code>true</code>, and the component is not
started, an exception is thrown
+ * @param transferInterrupt whether or not interruption of the calling thread should
be transfered to the executor
+ * thread
*
* @return a proxy that wraps the given component and exposes the given facet
interface; will never be null
*
* @throws PluginContainerException if the component does not exist or does not
implement the interface
*/
public <T> T createResourceComponentProxy(Class<T> facetInterface,
FacetLockType lockType, long timeout,
- boolean daemonThread, boolean onlyIfStarted) throws PluginContainerException {
+ boolean daemonThread, boolean onlyIfStarted, boolean transferInterrupt) throws
PluginContainerException {
if (onlyIfStarted) {
if (!ResourceComponentState.STARTED.equals(getResourceComponentState())) {
throw new PluginContainerException("Resource component could not be
retrieved for resource ["
@@ -444,6 +446,7 @@ public class ResourceContainer implements Serializable {
key = 31 * key + lockType.hashCode();
key = 31 * key + (int) (timeout ^ (timeout >>> 32));
key = 31 * key + (daemonThread ? 1 : 0);
+ key = 31 * key + (transferInterrupt ? 1 : 0);
synchronized (this) {
if (this.proxyCache == null) {
@@ -456,7 +459,7 @@ public class ResourceContainer implements Serializable {
// this is the handler that will actually acquire the lock and invoke the
facet method call
ResourceComponentInvocationHandler handler = new
ResourceComponentInvocationHandler(this, lockType,
- timeout, daemonThread, facetInterface);
+ timeout, daemonThread, facetInterface, transferInterrupt);
// this is the proxy that will look like the facet interface that the
caller will use
proxy = (T) Proxy.newProxyInstance(classLoader, new Class<?>[] {
facetInterface }, handler);
@@ -501,6 +504,7 @@ public class ResourceContainer implements Serializable {
private final long timeout;
private final boolean daemonThread;
private final Class facetInterface;
+ private final boolean transferInterrupt;
/**
*
@@ -511,9 +515,11 @@ public class ResourceContainer implements Serializable {
* value must be positive
* @param daemonThread whether or not the thread used for the invocation should
be a daemon thread
* @param facetInterface the interface that the component implements that is
being exposed by this proxy
+ * @param transferInterrupt whether or not interruption of the calling thread
should be transfered to the
+ * executor thread
*/
public ResourceComponentInvocationHandler(ResourceContainer container,
FacetLockType lockType, long timeout,
- boolean daemonThread, Class facetInterface) {
+ boolean daemonThread, Class facetInterface, boolean transferInterrupt) {
this.container = container;
switch (lockType) {
case WRITE: {
@@ -535,6 +541,7 @@ public class ResourceContainer implements Serializable {
this.timeout = timeout;
this.daemonThread = daemonThread;
this.facetInterface = facetInterface;
+ this.transferInterrupt = transferInterrupt;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
@@ -548,14 +555,15 @@ public class ResourceContainer implements Serializable {
private Object invokeInNewThreadWithLock(Method method, Object[] args) throws
Throwable {
ExecutorService threadPool = this.daemonThread ? DAEMON_THREAD_POOL :
NON_DAEMON_THREAD_POOL;
- Callable invocationThread = new ComponentInvocationThread(this.container,
method, args, this.lock);
- Future<?> future = threadPool.submit(invocationThread);
+ ComponentInvocation componentInvocation = new
ComponentInvocation(this.container, method, args, this.lock);
+ Future<?> future = threadPool.submit(componentInvocation);
try {
return future.get(this.timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
LOG.error("Thread [" + Thread.currentThread().getName() +
"] was interrupted.");
- if (this.daemonThread) {
+ if (this.transferInterrupt) {
future.cancel(true);
+ componentInvocation.markContextInterrupted();
}
throw new RuntimeException(invokedMethodString(method, args, "was
rudely interrupted."), e);
} catch (ExecutionException e) {
@@ -568,6 +576,7 @@ public class ResourceContainer implements Serializable {
+ " milliseconds - invocation thread will be
interrupted.");
LOG.debug(msg);
future.cancel(true);
+ componentInvocation.markContextInterrupted();
if (LOG.isDebugEnabled()) {
LOG.debug(this.container.getFacetLockStatus());
}
@@ -599,17 +608,22 @@ public class ResourceContainer implements Serializable {
}
}
- private static class ComponentInvocationThread implements Callable {
+ private static class ComponentInvocation implements Callable {
private final ResourceContainer resourceContainer;
private final Method method;
private final Object[] args;
private final Lock lock;
+ private final ComponentInvocationContextImpl componentInvocationContext;
+ private final LocalContext localContext;
- ComponentInvocationThread(ResourceContainer resourceContainer, Method method,
Object[] args, Lock lock) {
+ ComponentInvocation(ResourceContainer resourceContainer, Method method, Object[]
args, Lock lock) {
this.resourceContainer = resourceContainer;
this.method = method;
this.args = args;
this.lock = lock;
+ this.componentInvocationContext = (ComponentInvocationContextImpl)
resourceContainer.getResourceContext()
+ .getComponentInvocationContext();
+ localContext = new LocalContext();
}
public Object call() throws Exception {
@@ -623,7 +637,11 @@ public class ResourceContainer implements Serializable {
// If we made it here, we have acquired the lock.
}
+ componentInvocationContext.setLocalContext(localContext);
+
ClassLoader originalContextClassLoader =
Thread.currentThread().getContextClassLoader();
+
+ // The thread needs to run with a fresh invocation context
try {
ClassLoader pluginClassLoader =
this.resourceContainer.getResourceClassLoader();
if (pluginClassLoader == null) {
@@ -648,5 +666,9 @@ public class ResourceContainer implements Serializable {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
}
+
+ public void markContextInterrupted() {
+ localContext.markInterrupted();
+ }
}
-}
\ No newline at end of file
+}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
index a506493..3dee763 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceFactoryManager.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.inventory;
@@ -271,7 +267,7 @@ public class ResourceFactoryManager extends AgentService implements
ContainerSer
*/
private DeleteResourceFacet getDeleteResourceFacet(int resourceId) throws
PluginContainerException {
DeleteResourceFacet facet = ComponentUtil.getComponent(resourceId,
DeleteResourceFacet.class,
- FacetLockType.WRITE, FACET_DELETE_TIMEOUT, false, true);
+ FacetLockType.WRITE, FACET_DELETE_TIMEOUT, false, true, false);
return facet;
}
@@ -291,7 +287,7 @@ public class ResourceFactoryManager extends AgentService implements
ContainerSer
int createTimeout = (null == timeout || timeout < 1) ? FACET_CREATE_TIMEOUT :
timeout;
CreateChildResourceFacet facet = ComponentUtil.getComponent(parentResourceId,
CreateChildResourceFacet.class,
- FacetLockType.WRITE, createTimeout, false, true);
+ FacetLockType.WRITE, createTimeout, false, true, false);
return facet;
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
index 8c663b4..d6a9614 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/RuntimeDiscoveryExecutor.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.inventory;
@@ -228,7 +224,7 @@ public class RuntimeDiscoveryExecutor implements Runnable,
Callable<InventoryRep
AvailabilityFacet parentComponent = null;
try {
parentComponent =
parentContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.NONE, AvailabilityExecutor.GET_AVAILABILITY_TIMEOUT,
true, false);
+ FacetLockType.NONE, AvailabilityExecutor.GET_AVAILABILITY_TIMEOUT,
true, false, true);
} catch (PluginContainerException e) {
if (log.isDebugEnabled()) {
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/TimeoutException.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/TimeoutException.java
index 64695d3..fc4ae17 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/TimeoutException.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/TimeoutException.java
@@ -1,36 +1,31 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.inventory;
import org.rhq.core.pc.util.ComponentUtil;
-import org.rhq.core.pc.util.FacetLockType;
/**
* This exception is thrown when a method invoked on a proxied plugin component times
out. If possible, its cause
* will be set to an Exception containing the stack trace of the plugin component thread
that timed out.
*
- * @see ResourceContainer#createResourceComponentProxy(Class, FacetLockType, long,
boolean, boolean)
- * @see ComponentUtil#getComponent(int, Class, FacetLockType, long, boolean, boolean)
+ * @see ResourceContainer#createResourceComponentProxy(Class,
org.rhq.core.pc.util.FacetLockType, long, boolean, boolean, boolean)
+ * @see ComponentUtil#getComponent(int, Class, org.rhq.core.pc.util.FacetLockType, long,
boolean, boolean, boolean)
*
* @author Ian Springer
*/
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
index 32df8be..7aaf12a 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementCollectorRunner.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.measurement;
@@ -106,7 +102,7 @@ public class MeasurementCollectorRunner implements
Callable<MeasurementReport>,
} else {
MeasurementFacet measurementComponent = ComponentUtil
.getComponent(resourceId, MeasurementFacet.class,
FacetLockType.READ,
- MeasurementManager.FACET_METHOD_TIMEOUT, true, true);
+ MeasurementManager.FACET_METHOD_TIMEOUT, true, true, true);
if (log.isDebugEnabled()) {
scheduleHistory.addRequests(requests);
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
index 8e8c399..6ad3551 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/measurement/MeasurementManager.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.measurement;
@@ -477,7 +473,7 @@ public class MeasurementManager extends AgentService implements
MeasurementAgent
try {
measurementFacet = ComponentUtil.getComponent(resourceId,
MeasurementFacet.class, FacetLockType.READ,
- FACET_METHOD_TIMEOUT, true, true);
+ FACET_METHOD_TIMEOUT, true, true, true);
} catch (Exception e) {
LOG.warn("Cannot get measurement facet for Resource [" + resourceId
+ "]. Cause: " + e);
return Collections.emptySet();
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
index a3f5f1d..b8a8376 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/operation/OperationManager.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.operation;
@@ -197,7 +193,7 @@ public class OperationManager extends AgentService implements
OperationAgentServ
*/
protected OperationFacet getOperationFacet(int resourceId, long facetMethodTimeout)
throws PluginContainerException {
return ComponentUtil.getComponent(resourceId, OperationFacet.class,
FacetLockType.WRITE, facetMethodTimeout,
- false, false);
+ false, false, true);
}
/**
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
index 6c0f81b..1c67c31 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/support/SupportManager.java
@@ -1,24 +1,20 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.support;
@@ -83,6 +79,6 @@ public class SupportManager extends AgentService implements
SupportAgentService,
protected SupportFacet getSupportFacet(int resourceId, long facetMethodTimeout)
throws PluginContainerException {
return ComponentUtil.getComponent(resourceId, SupportFacet.class,
FacetLockType.READ, facetMethodTimeout,
- false, true);
+ false, true, false);
}
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
index e1453a6..bd98afd 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentServiceImpl.java
@@ -1,34 +1,28 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.pc.util;
import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.plugin.PluginManager;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
public class ComponentServiceImpl implements ComponentService {
@@ -39,7 +33,8 @@ public class ComponentServiceImpl implements ComponentService {
public <T> T getComponent(int resourceId, Class<T> facetInterface,
FacetLockType lockType, long timeout,
boolean daemonThread, boolean onlyIfStarted) throws PluginContainerException
{
- return ComponentUtil.getComponent(resourceId, facetInterface, lockType, timeout,
daemonThread, onlyIfStarted);
+ return ComponentUtil.getComponent(resourceId, facetInterface, lockType, timeout,
daemonThread, onlyIfStarted,
+ daemonThread);
}
public String getAmpsVersion(int resourceId) throws PluginContainerException {
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentUtil.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentUtil.java
index 9eb6e71..1abe002 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentUtil.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/util/ComponentUtil.java
@@ -1,25 +1,21 @@
/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
package org.rhq.core.pc.util;
import org.rhq.core.clientapi.agent.PluginContainerException;
@@ -84,6 +80,8 @@ public class ComponentUtil {
* it; value must be positive
* @param daemonThread whether or not the thread used for the invocation should be
a daemon thread
* @param onlyIfStarted if <code>true</code>, and the component is not
started, an exception is thrown
+ * @param transferInterrupt whether or not interruption of the calling thread should
be transfered to the executor
+ * thread
*
* @return the resource's <code>T</code> component interface
*
@@ -91,18 +89,19 @@ public class ComponentUtil {
* interface or it is not started and
<code>onlyIfStarted</code> is <code>
* true</code>
*
- * @see ResourceContainer#createResourceComponentProxy(Class, FacetLockType, long,
boolean, boolean)
+ * @see ResourceContainer#createResourceComponentProxy(Class, FacetLockType, long,
boolean, boolean, boolean)
*/
@SuppressWarnings("unchecked")
- public static <T> T getComponent(int resourceId, Class<T> facetInterface,
FacetLockType lockType,
- long timeout, boolean daemonThread, boolean
onlyIfStarted) throws PluginContainerException {
+ public static <T> T getComponent(int resourceId, Class<T> facetInterface,
FacetLockType lockType, long timeout,
+ boolean daemonThread, boolean onlyIfStarted, boolean transferInterrupt) throws
PluginContainerException {
InventoryManager inventoryManager =
PluginContainer.getInstance().getInventoryManager();
ResourceContainer resourceContainer =
inventoryManager.getResourceContainer(resourceId);
if (resourceContainer == null) {
throw new PluginContainerException("Resource component container could
not be retrieved for resource: "
+ resourceId);
}
- return resourceContainer.createResourceComponentProxy(facetInterface, lockType,
timeout, daemonThread, onlyIfStarted);
+ return resourceContainer.createResourceComponentProxy(facetInterface, lockType,
timeout, daemonThread,
+ onlyIfStarted, transferInterrupt);
}
@SuppressWarnings("unchecked")
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/component/ComponentInvocationContextImplTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/component/ComponentInvocationContextImplTest.java
new file mode 100644
index 0000000..00601fa
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/component/ComponentInvocationContextImplTest.java
@@ -0,0 +1,92 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package org.rhq.core.pc.component;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.rhq.core.pc.component.ComponentInvocationContextImpl.LocalContext;
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Thomas Segismont
+ */
+@Test
+public class ComponentInvocationContextImplTest {
+
+ private ComponentInvocationContextImpl componentInvocationContext = new
ComponentInvocationContextImpl();
+
+ @Test(timeOut = 1000 * 30)
+ public void newThreadsShouldSeeComponentInvocationContextInitialValue() throws
Exception {
+ InterruptedStatusRecorder recorder = new InterruptedStatusRecorder() {
+ @Override
+ public void run() {
+ value = componentInvocationContext.isInterrupted();
+ }
+ };
+ Thread thread = startRecorderThread(recorder);
+ thread.join();
+ assertEquals(recorder.getRecordedValue(), false);
+ }
+
+ @Test(timeOut = 1000 * 30)
+ public void threadShouldSeeLocalContextValue() throws Exception {
+ final LocalContext localContext = new LocalContext();
+ InterruptedStatusRecorder recorder = new InterruptedStatusRecorder() {
+ @Override
+ public void run() {
+ componentInvocationContext.setLocalContext(localContext);
+ while (!componentInvocationContext.isInterrupted()) {
+ try {
+ Thread.sleep(SECONDS.toMillis(1));
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ value = componentInvocationContext.isInterrupted();
+ }
+ };
+ Thread thread = startRecorderThread(recorder);
+ localContext.markInterrupted();
+ thread.join();
+ assertEquals(recorder.getRecordedValue(), true);
+ }
+
+ @Test(expectedExceptions = { IllegalArgumentException.class })
+ public void localContextCannotBeNull() {
+ componentInvocationContext.setLocalContext(null);
+ }
+
+ private Thread startRecorderThread(InterruptedStatusRecorder recorder) {
+ Thread thread = new Thread(recorder);
+ thread.setDaemon(true);
+ thread.start();
+ return thread;
+ }
+
+ private abstract class InterruptedStatusRecorder implements Runnable {
+
+ boolean value;
+
+ boolean getRecordedValue() {
+ return value;
+ }
+ }
+}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/ResourceContainerTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/ResourceContainerTest.java
index 5432eff..75e2d51 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/ResourceContainerTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/inventory/ResourceContainerTest.java
@@ -1,42 +1,50 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
+
package org.rhq.core.pc.inventory;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
import java.io.File;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
+import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.util.FacetLockType;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
+import org.rhq.core.pluginapi.component.ComponentInvocationContext;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.core.pluginapi.operation.OperationResult;
/**
* Unit test for {@link ResourceContainer}.
@@ -45,6 +53,7 @@ import org.rhq.core.pluginapi.inventory.ResourceContext;
*/
@Test
public class ResourceContainerTest {
+ private static final Log LOG = LogFactory.getLog(ResourceContainerTest.class);
@BeforeClass
public void beforeClass() {
@@ -65,59 +74,115 @@ public class ResourceContainerTest {
}
public void testCreateResourceComponentProxy() throws Exception {
- Resource resource = new Resource("TestPlatformKey",
"MyTestPlatform", PluginMetadataManager.TEST_PLATFORM_TYPE);
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- ResourceContainer resourceContainer = new ResourceContainer(resource,
contextClassLoader);
- ResourceComponent resourceComponent = new MockResourceComponent(false);
- resourceContainer.setResourceComponent(resourceComponent);
- System.out.println("Testing proxy call that should timeout...");
+ ResourceContainer resourceContainer = getResourceContainer();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Testing proxy call that should timeout...");
+ }
AvailabilityFacet resourceComponentProxy =
resourceContainer.createResourceComponentProxy(
- AvailabilityFacet.class, FacetLockType.NONE, 50, true, false);
+ AvailabilityFacet.class, FacetLockType.NONE, 50, true, false, true);
try {
resourceComponentProxy.getAvailability();
assert (false);
} catch (RuntimeException e) {
assert (e instanceof TimeoutException) : "[" + e + "] is not a
org.rhq.core.pc.inventory.TimeoutException.";
}
- System.out.println("SUCCESS!");
- System.out.println("Testing proxy call that should complete
successfully...");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("SUCCESS!");
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Testing proxy call that should complete
successfully...");
+ }
resourceComponentProxy =
resourceContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.NONE, 150, true, false);
+ FacetLockType.NONE, 150, true, false, true);
AvailabilityType avail = resourceComponentProxy.getAvailability();
assert (avail == AvailabilityType.UP);
- System.out.println("SUCCESS!");
- System.out.println("Testing proxy call that should fail...");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("SUCCESS!");
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Testing proxy call that should fail...");
+ }
ResourceComponent naughtyResourceComponent = new MockResourceComponent(true);
resourceContainer.setResourceComponent(naughtyResourceComponent);
resourceComponentProxy =
resourceContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.NONE, Long.MAX_VALUE, true, false);
+ FacetLockType.NONE, Long.MAX_VALUE, true, false, true);
try {
resourceComponentProxy.getAvailability();
assert (false);
} catch (RuntimeException e) {
assert (e instanceof MockRuntimeException);
}
- System.out.println("SUCCESS!");
- System.out.println("Testing proxy call should not timeout; its not to a
declared method in proxied interface");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("SUCCESS!");
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Testing proxy call should not timeout; its not to a declared
method in proxied interface");
+ }
resourceComponentProxy =
resourceContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.NONE, 50, true, false);
+ FacetLockType.NONE, 50, true, false, true);
String string = resourceComponentProxy.toString();
assert (string.equals(MockResourceComponent.class.toString()));
- System.out.println("SUCCESS!");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("SUCCESS!");
+ }
// TODO: Test proxy locking.
}
- class MockResourceComponent implements ResourceComponent {
+ public void testInterruptedComponentInvocationContext() throws Exception {
+ ResourceContainer resourceContainer = getResourceContainer();
+ OperationFacet proxy =
resourceContainer.createResourceComponentProxy(OperationFacet.class,
+ FacetLockType.WRITE, 50, true, false, true);
+ try {
+ proxy.invokeOperation("op", new Configuration());
+ fail("Expected invokeOperation to throw a TimeoutException");
+ } catch (TimeoutException e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Caught expected TimeoutException: " +
e.getMessage());
+ }
+ assertTrue(((MockResourceComponent)
resourceContainer.getResourceComponent())
+ .caughtInterruptedComponentInvocation());
+ }
+ }
+
+ public void testUninterruptedComponentInvocationContext() throws Exception {
+ ResourceContainer resourceContainer = getResourceContainer();
+ OperationFacet proxy =
resourceContainer.createResourceComponentProxy(OperationFacet.class,
+ FacetLockType.WRITE, 150, true, false, true);
+ try {
+ proxy.invokeOperation("op", new Configuration());
+ fail("Expected invokeOperation to throw a TimeoutException");
+ } catch (Exception e) {
+ assertFalse(e instanceof TimeoutException, "Caught unexpected instance
of TimeoutException: "
+ + e.getClass().getName());
+ assertFalse(((MockResourceComponent)
resourceContainer.getResourceComponent())
+ .caughtInterruptedComponentInvocation());
+ }
+ }
+
+ private ResourceContainer getResourceContainer() {
+ Resource resource = new Resource("TestPlatformKey",
"MyTestPlatform", PluginMetadataManager.TEST_PLATFORM_TYPE);
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ ResourceContainer resourceContainer = new ResourceContainer(resource,
contextClassLoader);
+ ResourceComponent resourceComponent = new MockResourceComponent(false);
+ resourceContainer.setResourceComponent(resourceComponent);
+ return resourceContainer;
+ }
+
+ class MockResourceComponent implements ResourceComponent, OperationFacet {
private boolean naughty;
+ private boolean caughtInterruptedComponentInvocation;
+ private ResourceContext resourceContext;
MockResourceComponent(boolean naughty) {
this.naughty = naughty;
}
public void start(ResourceContext resourceContext) throws Exception {
+ this.resourceContext = resourceContext;
}
public void stop() {
+ this.resourceContext = null;
}
public AvailabilityType getAvailability() {
@@ -141,6 +206,24 @@ public class ResourceContainerTest {
}
return this.getClass().toString();
}
+
+ @Override
+ public OperationResult invokeOperation(String name, Configuration parameters)
throws Exception {
+ long start = System.nanoTime();
+ while (!resourceContext.getComponentInvocationContext().isInterrupted()) {
+ if ((System.nanoTime() - start) > MILLISECONDS.toNanos(100)) {
+ // Make the operation fail after 100ms
+ caughtInterruptedComponentInvocation = false;
+ throw new Exception();
+ }
+ }
+ caughtInterruptedComponentInvocation = true;
+ throw new InterruptedException();
+ }
+
+ public boolean caughtInterruptedComponentInvocation() {
+ return caughtInterruptedComponentInvocation;
+ }
}
class MockRuntimeException extends RuntimeException {
diff --git
a/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
b/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
index 544c1ce..aef1fa8 100644
---
a/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
+++
b/modules/core/plugin-test-util/src/main/java/org/rhq/core/plugin/testutil/AbstractAgentPluginTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.core.plugin.testutil;
@@ -204,7 +204,7 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
ResourceContainer resourceContainer =
this.pluginContainer.getInventoryManager().getResourceContainer(resource);
long timeoutMillis = 5000;
AvailabilityFacet availFacet =
resourceContainer.createResourceComponentProxy(AvailabilityFacet.class,
- FacetLockType.READ, timeoutMillis, false, false);
+ FacetLockType.READ, timeoutMillis, false, false, false);
AvailabilityType avail;
try {
avail = availFacet.getAvailability();
@@ -239,7 +239,7 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
ResourceContainer resourceContainer =
this.pluginContainer.getInventoryManager().getResourceContainer(resource);
long timeoutMillis = timeout * 1000;
OperationFacet operationFacet =
resourceContainer.createResourceComponentProxy(OperationFacet.class,
- FacetLockType.WRITE, timeoutMillis, false, false);
+ FacetLockType.WRITE, timeoutMillis, false, false, false);
OperationResult operationResult;
try {
operationResult = operationFacet.invokeOperation(operationName, params);
@@ -263,7 +263,7 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
ResourceContainer resourceContainer =
this.pluginContainer.getInventoryManager().getResourceContainer(resource);
long timeoutMillis = 5000;
ConfigurationFacet configurationFacet =
resourceContainer.createResourceComponentProxy(
- ConfigurationFacet.class, FacetLockType.READ, timeoutMillis, false, false);
+ ConfigurationFacet.class, FacetLockType.READ, timeoutMillis, false, false,
false);
return configurationFacet.loadResourceConfiguration();
}
@@ -277,7 +277,7 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
ResourceContainer resourceContainer =
this.pluginContainer.getInventoryManager().getResourceContainer(resource);
long timeoutMillis = 5000;
ConfigurationFacet configurationFacet =
resourceContainer.createResourceComponentProxy(
- ConfigurationFacet.class, FacetLockType.WRITE, timeoutMillis, false, false);
+ ConfigurationFacet.class, FacetLockType.WRITE, timeoutMillis, false, false,
false);
ConfigurationUpdateReport report = new
ConfigurationUpdateReport(resourceConfig);
configurationFacet.updateResourceConfiguration(report);
return report;
@@ -547,7 +547,7 @@ public abstract class AbstractAgentPluginTest extends Arquillian {
throw new IllegalStateException("Resource component for " +
resource + " has not yet been started.");
}
MeasurementFacet measurementFacet =
resourceContainer.createResourceComponentProxy(MeasurementFacet.class,
- FacetLockType.READ, timeoutMillis, false, false);
+ FacetLockType.READ, timeoutMillis, false, false, false);
MeasurementReport report = new MeasurementReport();
MeasurementScheduleRequest request = new MeasurementScheduleRequest(-1,
metricName, -1, true,
measurementDefinition.getDataType(),
measurementDefinition.getRawNumericType());
diff --git
a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractDestinationTest.java
b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractDestinationTest.java
index 2c23c8b..5dbdef3 100644
---
a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractDestinationTest.java
+++
b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractDestinationTest.java
@@ -1,24 +1,20 @@
/*
- * Jopr Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.plugins.jbossas5.test;
@@ -159,7 +155,7 @@ public abstract class AbstractDestinationTest extends
AbstractResourceTest {
if (resource.getName().equals(getDestinationName())) {
foundDestination = true;
OperationFacet operationFacet =
ComponentUtil.getComponent(resource.getId(), OperationFacet.class,
- FacetLockType.WRITE, 3000, true, true);
+ FacetLockType.WRITE, 3000, true, true, true);
String name = "removeAllMessages";
operationFacet.invokeOperation(name, getTestOperationParameters(name));
}
diff --git
a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractResourceTest.java
b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractResourceTest.java
index b78b522..162254f 100644
---
a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractResourceTest.java
+++
b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/AbstractResourceTest.java
@@ -1,24 +1,20 @@
/*
- * Jopr Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.plugins.jbossas5.test;
@@ -95,7 +91,7 @@ public abstract class AbstractResourceTest extends AbstractPluginTest {
for (Resource resource : resources) {
System.out.println("Validating metrics for " + resource +
"...");
MeasurementFacet measurementFacet =
ComponentUtil.getComponent(resource.getId(),
- MeasurementFacet.class, FacetLockType.READ,
MEASUREMENT_FACET_METHOD_TIMEOUT, true, true);
+ MeasurementFacet.class, FacetLockType.READ,
MEASUREMENT_FACET_METHOD_TIMEOUT, true, true, true);
for (MeasurementDefinition metricDefinition : metricDefinitions) {
String name = metricDefinition.getName();
try {
@@ -160,7 +156,7 @@ public abstract class AbstractResourceTest extends AbstractPluginTest
{
//the 3 seconds to finish. Otherwise all the operations would have to
finish in 3 secs
//which can be a bit harsh limit.
OperationFacet operationFacet =
ComponentUtil.getComponent(resource.getId(), OperationFacet.class,
- FacetLockType.WRITE, OPERATION_FACET_METHOD_TIMEOUT, true,
true);
+ FacetLockType.WRITE, OPERATION_FACET_METHOD_TIMEOUT, true, true,
true);
//String name = operationDefinition.getName();
OperationResult result = operationFacet.invokeOperation(name,
getTestOperationParameters(name));
System.out.println("Validating operation '" + name +
"' result (" + result + ")...");
diff --git
a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/util/AppServerUtils.java
b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/util/AppServerUtils.java
index 6b1af87..17e0b1d 100644
---
a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/util/AppServerUtils.java
+++
b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/test/util/AppServerUtils.java
@@ -1,24 +1,20 @@
/*
- * Jopr Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.plugins.jbossas5.test.util;
@@ -38,7 +34,6 @@ import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.measurement.AvailabilityType;
-import org.rhq.core.domain.measurement.ResourceAvailability;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.PluginContainer;
@@ -46,7 +41,6 @@ import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.util.ComponentUtil;
import org.rhq.core.pc.util.FacetLockType;
-import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.plugins.jbossas5.ProfileServiceComponent;
@@ -182,7 +176,7 @@ public class AppServerUtils {
Thread.currentThread().setContextClassLoader(cl);
return ComponentUtil.getComponent(resource.getId(),
resourceSpecificFacetInterface, FacetLockType.WRITE,
- timeout, true, true);
+ timeout, true, true, true);
} finally {
Thread.currentThread().setContextClassLoader(currenContextClassLoader);
}
diff --git
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
index 13e1b75..0b5dbf5 100644
---
a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
+++
b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseServerComponent.java
@@ -19,6 +19,8 @@
package org.rhq.modules.plugins.jbossas7;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
@@ -43,6 +45,7 @@ import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.pluginapi.availability.AvailabilityCollectorRunnable;
import org.rhq.core.pluginapi.availability.AvailabilityFacet;
+import org.rhq.core.pluginapi.component.ComponentInvocationContext;
import org.rhq.core.pluginapi.event.log.LogFileEventResourceComponentHelper;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
@@ -279,8 +282,6 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
protected boolean waitUntilDown() throws InterruptedException {
boolean notAnswering = false;
- int count = 0;
-
while (!notAnswering) {
Operation op = new ReadAttribute(new Address(),
"release-version");
@@ -288,21 +289,18 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
Result res = getASConnection().execute(op);
if (!res.isSuccess()) { // If op succeeds, server is not down
notAnswering = true;
- } else if (count > 20) {
- break;
}
} catch (Exception e) {
notAnswering = true;
}
if (!notAnswering) {
- try {
- Thread.sleep(1000); // Wait 1s
- } catch (InterruptedException e) {
- // ignore
+ if (context.getComponentInvocationContext().isInterrupted()) {
+ // Operation canceled or timed out
+ throw new InterruptedException();
}
+ Thread.sleep(SECONDS.toMillis(1));
}
- count++;
}
// BZ 893802: wait until server (the process) is really down
@@ -314,8 +312,7 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
if (hostPort.isLocal) {
// lets be paranoid here
- for (; count <= 20; count++) {
- ProcessInfo processInfo = context.getNativeProcess();
+ for (ProcessInfo processInfo = context.getNativeProcess(); ; processInfo =
context.getNativeProcess()) {
if (processInfo == null) {
// Process not found, so it died, that's fine
break;
@@ -324,16 +321,14 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
// Process info says process is no longer running, that's fine
break;
}
- // Process is still running, wait a second and check again
- try {
- Thread.sleep(1000); // Wait 1s
- } catch (InterruptedException e) {
- // ignore
+ if (context.getComponentInvocationContext().isInterrupted()) {
+ // Operation canceled or timed out
+ throw new InterruptedException();
}
+ // Process is still running, wait a second and check again
+ Thread.sleep(SECONDS.toMillis(1));
}
}
-
- log.debug("waitUntilDown: Used " + count + " delay round(s) to
shut down. Server down=" + notAnswering);
return notAnswering;
}
@@ -342,7 +337,7 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
*
* @return the result of the operation
*/
- protected OperationResult startServer() {
+ protected OperationResult startServer() throws InterruptedException {
OperationResult operationResult = new OperationResult();
if (isManuallyAddedServer(operationResult, "Starting")) {
return operationResult;
@@ -383,8 +378,7 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
// standalone.bat.conf and domain.bat.conf respectively.
processExecution.setWorkingDirectory(startScriptFile.getParent());
processExecution.setCaptureOutput(true);
- processExecution.setWaitForCompletion(15000L); // 15 seconds // TODO: Should we
wait longer than 15 seconds?
- processExecution.setKillOnTimeout(false);
+ processExecution.setWaitForCompletion(0);
if (log.isDebugEnabled()) {
log.debug("About to execute the following process: [" +
processExecution + "]");
@@ -484,17 +478,14 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
return startScriptFile;
}
- private boolean waitForServerToStart() {
+ private boolean waitForServerToStart() throws InterruptedException {
boolean up = false;
- int count = 0;
while (!up) {
Operation op = new ReadAttribute(new Address(),
"release-version");
try {
Result res = getASConnection().execute(op);
if (res.isSuccess()) { // If op succeeds, server is not down
up = true;
- } else if (count > 20) {
- break;
}
} catch (Exception e) {
//do absolutely nothing
@@ -503,13 +494,12 @@ public abstract class BaseServerComponent<T extends
ResourceComponent<?>> extend
}
if (!up) {
- try {
- Thread.sleep(1000); // Wait 1s
- } catch (InterruptedException e) {
- // ignore
+ if (context.getComponentInvocationContext().isInterrupted()) {
+ // Operation canceled or timed out
+ throw new InterruptedException();
}
+ Thread.sleep(SECONDS.toMillis(1));
}
- count++;
}
return up;
}
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
index 5b552bc..b872ad6 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/DeploymentTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.modules.plugins.jbossas7.itest.standalone;
@@ -272,7 +272,7 @@ public class DeploymentTest extends AbstractJBossAS7PluginTest {
ResourceContainer webRuntimeResourceContainer =
pluginContainer.getInventoryManager().getResourceContainer(
webRuntimeResource);
MeasurementFacet measurementFacet =
webRuntimeResourceContainer.createResourceComponentProxy(
- MeasurementFacet.class, FacetLockType.READ, SECONDS.toMillis(5), false,
false);
+ MeasurementFacet.class, FacetLockType.READ, SECONDS.toMillis(5), false,
false, false);
MeasurementReport report = new MeasurementReport();
Set<MeasurementScheduleRequest> measurementScheduleRequests =
getMeasurementScheduleRequests(webRuntimeResource);
measurementFacet.getValues(report, measurementScheduleRequests);
diff --git
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/WebConnectorComponentTest.java
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/WebConnectorComponentTest.java
index ca86d5e..31343f3 100644
---
a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/WebConnectorComponentTest.java
+++
b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/itest/standalone/WebConnectorComponentTest.java
@@ -88,7 +88,7 @@ public class WebConnectorComponentTest extends
AbstractJBossAS7PluginTest {
requests.add(newMeasurementRequest(MAX_CONNECTIONS_METRIC_NAME));
MeasurementReport report = new MeasurementReport();
ComponentUtil.getComponent(webConnectorResource.getId(),
MeasurementFacet.class, FacetLockType.READ,
- SECONDS.toMillis(30), true, false).getValues(report, requests);
+ SECONDS.toMillis(30), true, false, true).getValues(report, requests);
Set<MeasurementDataNumeric> numericMetrics = report.getNumericData();
assertEquals(numericMetrics, 1);
MeasurementData measurementData = numericMetrics.iterator().next();
diff --git
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/AppServerUtils.java
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/AppServerUtils.java
index 653e86d..b07e10a 100644
---
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/AppServerUtils.java
+++
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/AppServerUtils.java
@@ -1,24 +1,20 @@
/*
- * Jopr Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.plugins.jbosscache3.test;
@@ -187,7 +183,7 @@ public class AppServerUtils {
return ComponentUtil.getComponent(asResource.getId(),
resourceSpecificFacetInterface, FacetLockType.WRITE,
- DEPLOY_CONTENT_TIMEOUT, true, true);
+ DEPLOY_CONTENT_TIMEOUT, true, true, true);
} finally {
Thread.currentThread().setContextClassLoader(
currenContextClassLoader);
diff --git
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/CacheComponentTest.java
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/CacheComponentTest.java
index 2189e6b..6d9a025 100644
---
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/CacheComponentTest.java
+++
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/CacheComponentTest.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2013 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,8 +13,8 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package org.rhq.plugins.jbosscache3.test;
@@ -183,7 +183,7 @@ public class CacheComponentTest {
MeasurementFacet measurementFacet = ComponentUtil.getComponent(
resource.getId(), MeasurementFacet.class,
FacetLockType.READ, MEASUREMENT_FACET_METHOD_TIMEOUT, true,
- true);
+ true, true);
EmsBean relatedBean = connection.getBean(resource.getResourceKey());
for (MeasurementDefinition metricDefinition : metricDefinitions) {
diff --git
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/OperationTest.java
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/OperationTest.java
index 1c69a88..cab153b 100644
---
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/OperationTest.java
+++
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/OperationTest.java
@@ -1,3 +1,22 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
package org.rhq.plugins.jbosscache3.test;
import java.util.Set;
@@ -51,7 +70,7 @@ public class OperationTest {
resource.getId(), OperationFacet.class,
FacetLockType.WRITE,
CacheComponentTest.OPERATION_FACET_METHOD_TIMEOUT,
- true, true);
+ true, true, true);
for (OperationDefinition operationDefinition : operationDefinitions) {
String name = operationDefinition.getName();
diff --git
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
index 16c453e..5284f1d 100644
---
a/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
+++
b/modules/plugins/jboss-cache-v3/src/test/java/org/rhq/plugins/jbosscache3/test/TestHelper.java
@@ -1,3 +1,22 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
package org.rhq.plugins.jbosscache3.test;
import java.io.File;
@@ -104,7 +123,7 @@ public class TestHelper {
.getComponent(resource.getId(), MeasurementFacet.class,
FacetLockType.READ,
CacheComponentTest.MEASUREMENT_FACET_METHOD_TIMEOUT,
- true, true);
+ true, true, true);
ResourceType resourceType = resource.getResourceType();
Set<MeasurementDefinition> metricDefinitions = resourceType
.getMetricDefinitions();