Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-13 13:23:08 -0400
committerChristopher Frost2011-05-13 13:23:08 -0400
commit551889d0bd85f1479e68409cb01f33dc7c5a1361 (patch)
tree6de01d133455c5f1544dbc53b853e8bf36f8f29d /org.eclipse.virgo.kernel.model
parentcd71143b0b786e34479cc0ce64628217de98a258 (diff)
downloadorg.eclipse.virgo.kernel-551889d0bd85f1479e68409cb01f33dc7c5a1361.tar.gz
org.eclipse.virgo.kernel-551889d0bd85f1479e68409cb01f33dc7c5a1361.tar.xz
org.eclipse.virgo.kernel-551889d0bd85f1479e68409cb01f33dc7c5a1361.zip
344672 Renaming the KernelModel to ArtifactModel and adding all artifacts to it without changing the existing Model beans
Diffstat (limited to 'org.eclipse.virgo.kernel.model')
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java7
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java6
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java14
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/ManageableBundleArtifact.java7
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java21
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java30
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingInstaller.java2
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifact.java19
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableBundleArtifact.java18
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifact.java4
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListener.java77
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java24
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifactTests.java12
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifactTests.java6
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListenerTests.java4
15 files changed, 168 insertions, 83 deletions
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java
index f1adde24..6c373cd2 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/BundleArtifact.java
@@ -39,5 +39,12 @@ public interface BundleArtifact extends Artifact {
* @param targetPath The bundle relative path to delete
*/
void deleteEntry(String targetPath);
+
+ /**
+ * Gets the id of this bundle
+ *
+ * @return long id of this bundle
+ */
+ long getBundleId();
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java
index 1f25abc6..a5786f18 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifact.java
@@ -66,7 +66,6 @@ final class BundleArtifact extends AbstractArtifact {
} catch (BundleException e) {
logger.error("Unable to update bundle '{}:{}'", this.bundle.getSymbolicName(), this.bundle.getVersion());
throw new RuntimeException(String.format("Unable to update bundle '%s:%s'", this.bundle.getSymbolicName(), this.bundle.getVersion()), e);
-
}
}
@@ -79,7 +78,6 @@ final class BundleArtifact extends AbstractArtifact {
} catch (BundleException e) {
logger.error("Unable to start bundle '{}:{}'", this.bundle.getSymbolicName(), this.bundle.getVersion());
throw new RuntimeException(String.format("Unable to start bundle '%s:%s'", this.bundle.getSymbolicName(), this.bundle.getVersion()), e);
-
}
}
@@ -92,7 +90,6 @@ final class BundleArtifact extends AbstractArtifact {
} catch (BundleException e) {
logger.error("Unable to stop bundle '{}:{}'", this.bundle.getSymbolicName(), this.bundle.getVersion());
throw new RuntimeException(String.format("Unable to stop bundle '%s:%s'", this.bundle.getSymbolicName(), this.bundle.getVersion()), e);
-
}
}
@@ -104,8 +101,7 @@ final class BundleArtifact extends AbstractArtifact {
this.bundle.uninstall();
} catch (BundleException e) {
logger.error("Unable to uninstall bundle '{}:{}'", this.bundle.getSymbolicName(), this.bundle.getVersion());
- throw new RuntimeException(String.format("Unable to uninstall bundle '%s:%s'", this.bundle.getSymbolicName(), this.bundle.getVersion()),
- e);
+ throw new RuntimeException(String.format("Unable to uninstall bundle '%s:%s'", this.bundle.getSymbolicName(), this.bundle.getVersion()), e);
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
index 0380241d..c200881c 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
@@ -28,13 +28,25 @@ final class DeployerBundleArtifact extends DeployerArtifact implements BundleArt
this.installArtifact = installArtifact;
}
+ /**
+ * {@inheritDoc}
+ */
public void deleteEntry(String targetPath) {
this.installArtifact.deleteEntry(targetPath);
-
}
+ /**
+ * {@inheritDoc}
+ */
public void updateEntry(String inputPath, String targetPath) {
this.installArtifact.updateEntry(URI.create(inputPath), targetPath);
}
+ /**
+ * {@inheritDoc}
+ */
+ public long getBundleId() {
+ return this.installArtifact.getBundle().getBundleId();
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/ManageableBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/ManageableBundleArtifact.java
index 32297c0e..68abe39e 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/ManageableBundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/ManageableBundleArtifact.java
@@ -42,4 +42,11 @@ public interface ManageableBundleArtifact extends ManageableArtifact {
* @param targetPath The bundle relative path to delete
*/
void deleteEntry(String targetPath);
+
+ /**
+ * Gets the id of this bundle
+ *
+ * @return long id of this bundle
+ */
+ long getBundleId();
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java
index 5ef83b1a..ee101100 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/RuntimeArtifactModelObjectNameCreator.java
@@ -30,26 +30,35 @@ import org.osgi.framework.Version;
public interface RuntimeArtifactModelObjectNameCreator {
/**
- * Create an {@link ObjectName} based on an input {@link Artifact}. Names generated from equal (
+ * Create an Model {@link ObjectName} based on an input {@link Artifact}. Names generated from equal (
* {@link AbstractArtifact#equals(Object)}) {@link Artifact}s should be equal as well.
*
* @param artifact The artifact to generate an {@link ObjectName} for
* @return The {@link ObjectName} for the {@link Artifact}
*/
- ObjectName create(Artifact artifact);
+ ObjectName createModel(Artifact artifact);
/**
- * Creates an {@link ObjectName} based on an input type, name, and version.
+ * Create an ArtifactModel {@link ObjectName} based on an input {@link Artifact}. Names generated from equal (
+ * {@link AbstractArtifact#equals(Object)}) {@link Artifact}s should be equal as well.
+ *
+ * @param artifact The artifact to generate an {@link ObjectName} for
+ * @return The {@link ObjectName} for the {@link Artifact}
+ */
+ ObjectName createArtifactModel(Artifact artifact);
+
+ /**
+ * Creates a Model {@link ObjectName} based on an input type, name, and version.
*
* @param type The type of the object to create an @{link ObjectName} for
* @param name The name of the object to create an @{link ObjectName} for
* @param version The version of the object to create an @{link ObjectName} for
* @return An {@link ObjectName} for the runtime artifact represented by this type, name, and version
*/
- ObjectName create(String type, String name, Version version);
+ ObjectName createModel(String type, String name, Version version);
/**
- * Creates an {@link ObjectName} based on an input type, name, version, and region.
+ * Creates an ArtifactModel {@link ObjectName} based on an input type, name, version, and region.
*
* @param type The type of the object to create an @{link ObjectName} for
* @param name The name of the object to create an @{link ObjectName} for
@@ -57,7 +66,7 @@ public interface RuntimeArtifactModelObjectNameCreator {
* @param region The {@link Region} of the object to create an @{link ObjectName} for
* @return An {@link ObjectName} for the runtime artifact represented by this type, name, version, and region
*/
- ObjectName create(String type, String name, Version version, Region region);
+ ObjectName createArtifactModel(String type, String name, Version version, Region region);
/**
* Creates a query {@link ObjectName} that can be used to enumerate all of the user region artifacts in the runtime
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java
index 47e0c6ca..ffc0cfcd 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DefaultRuntimeArtifactModelObjectNameCreator.java
@@ -24,6 +24,8 @@ import org.osgi.framework.Version;
* The default implementation of {@link RuntimeArtifactModelObjectNameCreator}. This implementation creates names based
* on the following pattern:
* <p />
+ * <code>&lt;domain&gt;:type=ArtifactModel,artifact-type=&lt;type&gt;,name=&lt;name&gt;,version=&lt;version&gt;,region=&lt;region&gt;</code>
+ * and
* <code>&lt;domain&gt;:type=Model,artifact-type=&lt;type&gt;,name=&lt;name&gt;,version=&lt;version&gt;</code>
*
* <strong>Concurrent Semantics</strong><br />
@@ -33,10 +35,6 @@ import org.osgi.framework.Version;
*/
public final class DefaultRuntimeArtifactModelObjectNameCreator implements RuntimeArtifactModelObjectNameCreator {
- private static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
-
- private static final String GLOBAL_REGION_NAME = "global";
-
private static final String ARTIFACTS_FORMAT = "%s:type=Model,*";
private static final String ALL_ARTIFACTS_FORMAT = "%s:type=*Model,*";
@@ -47,7 +45,7 @@ public final class DefaultRuntimeArtifactModelObjectNameCreator implements Runti
private static final String ARTIFACT_FORMAT = "%s:type=Model,artifact-type=%s,name=%s,version=%s";
- private static final String EXTENDED_ARTIFACT_FORMAT = "%s:type=KernelModel,artifact-type=%s,name=%s,version=%s,region=%s";
+ private static final String EXTENDED_ARTIFACT_FORMAT = "%s:type=ArtifactModel,artifact-type=%s,name=%s,version=%s,region=%s";
private static final String KEY_TYPE = "artifact-type";
@@ -64,32 +62,34 @@ public final class DefaultRuntimeArtifactModelObjectNameCreator implements Runti
/**
* {@inheritDoc}
*/
- public ObjectName create(@NonNull Artifact artifact) {
- Region region = artifact.getRegion();
- // Treat user region artifacts specially to preserve JMX compatibility with Virgo 2.1.0.
- if (USER_REGION_NAME.equals(region.getName()) || GLOBAL_REGION_NAME.equals(region.getName()) ) {
- return create(artifact.getType(), artifact.getName(), artifact.getVersion());
- }
- return create(artifact.getType(), artifact.getName(), artifact.getVersion(), region);
+ public ObjectName createModel(@NonNull Artifact artifact) {
+ return createModel(artifact.getType(), artifact.getName(), artifact.getVersion());
}
/**
* {@inheritDoc}
*/
- public ObjectName create(String type, String name, Version version, Region region) {
- return createObjectName(String.format(EXTENDED_ARTIFACT_FORMAT, this.domain, type, name, version, region.getName()));
+ public ObjectName createArtifactModel(@NonNull Artifact artifact) {
+ return createArtifactModel(artifact.getType(), artifact.getName(), artifact.getVersion(), artifact.getRegion());
}
/**
* {@inheritDoc}
*/
- public ObjectName create(String type, String name, Version version) {
+ public ObjectName createModel(String type, String name, Version version) {
return createObjectName(String.format(ARTIFACT_FORMAT, this.domain, type, name, version));
}
/**
* {@inheritDoc}
*/
+ public ObjectName createArtifactModel(String type, String name, Version version, Region region) {
+ return createObjectName(String.format(EXTENDED_ARTIFACT_FORMAT, this.domain, type, name, version, region.getName()));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ObjectName createArtifactsOfTypeQuery(String type) {
return createObjectName(String.format(ARTIFACTS_OF_TYPE_FORMAT, this.domain, type));
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingInstaller.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingInstaller.java
index 9d9a7950..8d16d82d 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingInstaller.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingInstaller.java
@@ -51,7 +51,7 @@ public final class DelegatingInstaller implements Installer {
} catch (DeploymentException e) {
throw new InstallException(String.format("Exception encountered while installing '%s'", uri), e);
}
- return this.artifactObjectNameCreator.create(deploymentIdentity.getType(), deploymentIdentity.getSymbolicName(), new Version(deploymentIdentity.getVersion()));
+ return this.artifactObjectNameCreator.createModel(deploymentIdentity.getType(), deploymentIdentity.getSymbolicName(), new Version(deploymentIdentity.getVersion()));
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifact.java
index 203aaed9..b89e32ab 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifact.java
@@ -17,7 +17,6 @@ import java.util.Set;
import javax.management.ObjectName;
-import org.eclipse.equinox.region.Region;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.management.ManageableArtifact;
import org.eclipse.virgo.kernel.model.management.RuntimeArtifactModelObjectNameCreator;
@@ -41,9 +40,12 @@ class DelegatingManageableArtifact implements ManageableArtifact {
private final Artifact artifact;
- public DelegatingManageableArtifact(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator, @NonNull Artifact artifact) {
+ private final boolean newModel;
+
+ public DelegatingManageableArtifact(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator, @NonNull Artifact artifact, boolean newModel) {
this.artifactObjectNameCreator = artifactObjectNameCreator;
this.artifact = artifact;
+ this.newModel = newModel;
}
/**
@@ -85,12 +87,7 @@ class DelegatingManageableArtifact implements ManageableArtifact {
* {@inheritDoc}
*/
public String getRegion() {
- Region region = this.artifact.getRegion();
- if(region != null){
- return region.toString();
- } else {
- return "";
- }
+ return this.artifact.getRegion().getName();
}
/**
@@ -137,7 +134,11 @@ class DelegatingManageableArtifact implements ManageableArtifact {
protected final ObjectName[] convertToObjectNames(Set<Artifact> artifacts) {
Set<ObjectName> objectNames = new HashSet<ObjectName>(artifacts.size());
for (Artifact artifact : artifacts) {
- objectNames.add(artifactObjectNameCreator.create(artifact));
+ if(newModel){
+ objectNames.add(artifactObjectNameCreator.createArtifactModel(artifact));
+ } else {
+ objectNames.add(artifactObjectNameCreator.createModel(artifact));
+ }
}
return objectNames.toArray(new ObjectName[objectNames.size()]);
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableBundleArtifact.java
index 54dbd62c..fc49bf4a 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableBundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableBundleArtifact.java
@@ -32,18 +32,30 @@ final class DelegatingManageableBundleArtifact extends DelegatingManageableArtif
private final BundleArtifact bundleArtifact;
- public DelegatingManageableBundleArtifact(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator,
- @NonNull BundleArtifact bundleArtifact) {
- super(artifactObjectNameCreator, bundleArtifact);
+ public DelegatingManageableBundleArtifact(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator, @NonNull BundleArtifact bundleArtifact, boolean newModel) {
+ super(artifactObjectNameCreator, bundleArtifact, newModel);
this.bundleArtifact = bundleArtifact;
}
+ /**
+ * {@inheritDoc}
+ */
public void deleteEntry(String targetPath) {
this.bundleArtifact.deleteEntry(targetPath);
}
+ /**
+ * {@inheritDoc}
+ */
public void updateEntry(String inputPath, String targetPath) {
this.bundleArtifact.updateEntry(inputPath, targetPath);
}
+ /**
+ * {@inheritDoc}
+ */
+ public long getBundleId() {
+ return this.bundleArtifact.getBundleId();
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifact.java
index f0520145..9b6c0098 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifact.java
@@ -32,8 +32,8 @@ final class DelegatingManageableCompositeArtifact extends DelegatingManageableAr
private final CompositeArtifact planArtifact;
- public DelegatingManageableCompositeArtifact(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator, @NonNull CompositeArtifact planArtifact) {
- super(artifactObjectNameCreator, planArtifact);
+ public DelegatingManageableCompositeArtifact(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator, @NonNull CompositeArtifact planArtifact, boolean newModel) {
+ super(artifactObjectNameCreator, planArtifact, newModel);
this.planArtifact = planArtifact;
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListener.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListener.java
index 8ad46e48..86fc5518 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListener.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListener.java
@@ -43,6 +43,10 @@ import org.slf4j.LoggerFactory;
*/
public class JmxArtifactRepositoryListener implements ArtifactRepositoryListener {
+ private static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
+
+ private static final String GLOBAL_REGION_NAME = "global";
+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
@@ -57,17 +61,47 @@ public class JmxArtifactRepositoryListener implements ArtifactRepositoryListener
* {@inheritDoc}
*/
public void added(Artifact artifact) {
- ObjectName objectName = this.artifactObjectNameCreator.create(artifact);
+ String regionName = artifact.getRegion().getName();
+ if (USER_REGION_NAME.equals(regionName) || GLOBAL_REGION_NAME.equals(regionName) ) {
+ publish(artifact, false);
+ }
+ publish(artifact, true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removed(Artifact artifact) {
+ String regionName = artifact.getRegion().getName();
+ if (USER_REGION_NAME.equals(regionName) || GLOBAL_REGION_NAME.equals(regionName) ) {
+ retract(artifact, false);
+ }
+ retract(artifact, true);
+ }
+
+ public void destroy() {
+ Set<ObjectName> objectNames = this.server.queryNames(this.artifactObjectNameCreator.createAllArtifactsQuery(), null);
+ for (ObjectName objectName : objectNames) {
+ try {
+ this.server.unregisterMBean(objectName);
+ } catch (MBeanRegistrationException e) {
+ // Swallow exception to allow others to proceed
+ } catch (InstanceNotFoundException e) {
+ // Swallow exception to allow others to proceed
+ }
+ }
+ }
+
+ private void publish(Artifact artifact, boolean newModel){
+ ObjectName objectName = getModelObjectName(artifact, newModel);
try {
if (artifact instanceof CompositeArtifact) {
- this.server.registerMBean(new DelegatingManageableCompositeArtifact(this.artifactObjectNameCreator, (CompositeArtifact) artifact),
- objectName);
+ this.server.registerMBean(new DelegatingManageableCompositeArtifact(this.artifactObjectNameCreator, (CompositeArtifact) artifact, newModel), objectName);
} else if (artifact instanceof BundleArtifact) {
- this.server.registerMBean(new DelegatingManageableBundleArtifact(this.artifactObjectNameCreator, (BundleArtifact) artifact),
- objectName);
+ this.server.registerMBean(new DelegatingManageableBundleArtifact(this.artifactObjectNameCreator, (BundleArtifact) artifact, newModel), objectName);
} else {
- this.server.registerMBean(new DelegatingManageableArtifact(this.artifactObjectNameCreator, artifact), objectName);
+ this.server.registerMBean(new DelegatingManageableArtifact(this.artifactObjectNameCreator, artifact, newModel), objectName);
}
} catch (InstanceAlreadyExistsException e) {
logger.error(String.format("Unable to register '%s'", objectName.toString()), e);
@@ -77,13 +111,11 @@ public class JmxArtifactRepositoryListener implements ArtifactRepositoryListener
logger.error(String.format("Unable to register '%s'", objectName.toString()), e);
}
}
-
- /**
- * {@inheritDoc}
- */
- public void removed(Artifact artifact) {
- ObjectName objectName = this.artifactObjectNameCreator.create(artifact);
-
+
+
+ private void retract(Artifact artifact, boolean newModel){
+ ObjectName objectName = getModelObjectName(artifact, newModel);
+
try {
this.server.unregisterMBean(objectName);
} catch (MBeanRegistrationException e) {
@@ -92,17 +124,14 @@ public class JmxArtifactRepositoryListener implements ArtifactRepositoryListener
logger.error(String.format("Unable to unregister '%s'", objectName.toString()), e);
}
}
-
- public void destroy() {
- Set<ObjectName> objectNames = this.server.queryNames(this.artifactObjectNameCreator.createAllArtifactsQuery(), null);
- for (ObjectName objectName : objectNames) {
- try {
- this.server.unregisterMBean(objectName);
- } catch (MBeanRegistrationException e) {
- // Swallow exception to allow others to proceed
- } catch (InstanceNotFoundException e) {
- // Swallow exception to allow others to proceed
- }
+
+ private ObjectName getModelObjectName(Artifact artifact, boolean newModel){
+ ObjectName objectName;
+ if(newModel){
+ objectName = this.artifactObjectNameCreator.createArtifactModel(artifact);
+ } else {
+ objectName = this.artifactObjectNameCreator.createModel(artifact);
}
+ return objectName;
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java
index 479b30c7..19c974f0 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DefaultArtifactObjectNameCreatorTests.java
@@ -25,16 +25,28 @@ import org.junit.Test;
public class DefaultArtifactObjectNameCreatorTests {
private final DefaultRuntimeArtifactModelObjectNameCreator creator = new DefaultRuntimeArtifactModelObjectNameCreator("test-domain");
-
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullModelArtifact() {
+ creator.createModel(null);
+ }
+
@Test(expected = FatalAssertionException.class)
- public void nullArtifact() {
- creator.create(null);
+ public void nullArtifactModelArtifact() {
+ creator.createArtifactModel(null);
+ }
+
+ @Test
+ public void successModel() {
+ ObjectName objectName = creator.createModel(new StubCompositeArtifact());
+ assertNotNull(objectName);
+ assertEquals("test-domain:artifact-type=test-type,name=test-name,type=Model,version=0.0.0", objectName.getCanonicalName());
}
@Test
- public void success() {
- ObjectName objectName = creator.create(new StubCompositeArtifact());
+ public void successArtifactModel() {
+ ObjectName objectName = creator.createArtifactModel(new StubCompositeArtifact());
assertNotNull(objectName);
- assertEquals("test-domain:artifact-type=test-type,name=test-name,region=test-region,type=KernelModel,version=0.0.0", objectName.getCanonicalName());
+ assertEquals("test-domain:artifact-type=test-type,name=test-name,region=test-region,type=ArtifactModel,version=0.0.0", objectName.getCanonicalName());
}
}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifactTests.java
index a717ad98..4ee9a4e2 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifactTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableArtifactTests.java
@@ -40,12 +40,12 @@ public class DelegatingManageableArtifactTests {
@Test(expected = FatalAssertionException.class)
public void nullCreator() {
- new DelegatingManageableArtifact(null, new StubCompositeArtifact());
+ new DelegatingManageableArtifact(null, new StubCompositeArtifact(), true);
}
@Test(expected = FatalAssertionException.class)
public void nullArtifact() {
- new DelegatingManageableArtifact(createMock(RuntimeArtifactModelObjectNameCreator.class), null);
+ new DelegatingManageableArtifact(createMock(RuntimeArtifactModelObjectNameCreator.class), null, true);
}
@Test
@@ -53,12 +53,12 @@ public class DelegatingManageableArtifactTests {
RuntimeArtifactModelObjectNameCreator creator = createMock(RuntimeArtifactModelObjectNameCreator.class);
Artifact artifact = createMock(Artifact.class);
- DelegatingManageableArtifact manageableArtifact = new DelegatingManageableArtifact(creator, artifact);
+ DelegatingManageableArtifact manageableArtifact = new DelegatingManageableArtifact(creator, artifact, true);
expect(artifact.getDependents()).andReturn(getArtifacts());
- expect(creator.create(isA(Artifact.class))).andReturn(new ObjectName("domain:key=value1"));
- expect(creator.create(isA(Artifact.class))).andReturn(new ObjectName("domain:key=value2"));
- expect(creator.create(isA(Artifact.class))).andReturn(new ObjectName("domain:key=value3"));
+ expect(creator.createArtifactModel(isA(Artifact.class))).andReturn(new ObjectName("domain:key=value1"));
+ expect(creator.createArtifactModel(isA(Artifact.class))).andReturn(new ObjectName("domain:key=value2"));
+ expect(creator.createArtifactModel(isA(Artifact.class))).andReturn(new ObjectName("domain:key=value3"));
expect(artifact.getName()).andReturn("test-name");
expect(artifact.getState()).andReturn(ArtifactState.ACTIVE);
expect(artifact.getType()).andReturn("test-type");
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifactTests.java
index 8671ae95..b8efb544 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifactTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/DelegatingManageableCompositeArtifactTests.java
@@ -31,12 +31,12 @@ public class DelegatingManageableCompositeArtifactTests {
@Test(expected = FatalAssertionException.class)
public void nullCreator() {
- new DelegatingManageableCompositeArtifact(null, new StubCompositeArtifact());
+ new DelegatingManageableCompositeArtifact(null, new StubCompositeArtifact(), true);
}
@Test(expected = FatalAssertionException.class)
public void nullArtifact() {
- new DelegatingManageableCompositeArtifact(createMock(RuntimeArtifactModelObjectNameCreator.class), null);
+ new DelegatingManageableCompositeArtifact(createMock(RuntimeArtifactModelObjectNameCreator.class), null, true);
}
@Test
@@ -44,7 +44,7 @@ public class DelegatingManageableCompositeArtifactTests {
RuntimeArtifactModelObjectNameCreator creator = createMock(RuntimeArtifactModelObjectNameCreator.class);
CompositeArtifact artifact = createMock(CompositeArtifact.class);
- DelegatingManageableCompositeArtifact manageablePlanArtifact = new DelegatingManageableCompositeArtifact(creator, artifact);
+ DelegatingManageableCompositeArtifact manageablePlanArtifact = new DelegatingManageableCompositeArtifact(creator, artifact, true);
expect(artifact.isAtomic()).andReturn(true);
expect(artifact.isScoped()).andReturn(true);
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListenerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListenerTests.java
index 9207a4d1..7d672130 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListenerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/management/internal/JmxArtifactRepositoryListenerTests.java
@@ -47,7 +47,7 @@ public class JmxArtifactRepositoryListenerTests {
@Test
public void added() throws MalformedObjectNameException, NullPointerException {
- expect(this.creator.create(isA(Artifact.class))).andReturn(new ObjectName("test:key=1"));
+ expect(this.creator.createArtifactModel(isA(Artifact.class))).andReturn(new ObjectName("test:key=1"));
replay(creator);
int initial = this.server.getMBeanCount();
@@ -58,7 +58,7 @@ public class JmxArtifactRepositoryListenerTests {
@Test
public void removed() throws MalformedObjectNameException, NullPointerException {
- expect(this.creator.create(isA(Artifact.class))).andReturn(new ObjectName("test:key=1")).times(2);
+ expect(this.creator.createArtifactModel(isA(Artifact.class))).andReturn(new ObjectName("test:key=1")).times(2);
replay(creator);
this.listener.added(new StubCompositeArtifact());

Back to the top