Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java')
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java
index 001e020dc..56518e72a 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2016 IBM Corporation and others.
+ * Copyright (c) 2012, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -200,7 +200,14 @@ public class ModuleDatabase {
writeLock();
try {
int startlevel = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : getInitialModuleStartLevel();
- long id = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : getNextIdAndIncrement();
+ long id = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : builder.getId();
+ if (id == -1) {
+ // the id is not set by the builder; get and increment the next ID
+ id = getAndIncrementNextId();
+ }
+ if (getModule(id) != null) {
+ throw new IllegalStateException("Duplicate module id: " + id + " used by module: " + getModule(id)); //$NON-NLS-1$//$NON-NLS-2$
+ }
EnumSet<Settings> settings = getActivationPolicySettings(builder);
Module module = load(location, builder, revisionInfo, id, settings, startlevel);
long currentTime = System.currentTimeMillis();
@@ -634,23 +641,13 @@ public class ModuleDatabase {
return moduleCycles;
}
- /**
- * Increments by one the next module ID
- */
- private long getNextIdAndIncrement() {
- // sanity check
- checkWrite();
- return nextId.getAndIncrement();
-
- }
-
private void checkWrite() {
if (monitor.getWriteHoldCount() == 0)
throw new IllegalMonitorStateException("Must hold the write lock."); //$NON-NLS-1$
}
/**
- * returns the next module ID
+ * returns the next module ID.
* <p>
* A read operation protected by the {@link #readLock() read} lock.
* @return the next module ID
@@ -665,6 +662,22 @@ public class ModuleDatabase {
}
/**
+ * Atomically increments by one the next module ID.
+ * <p>
+ * A write operation protected by the {@link #writeLock()} lock.
+ * @return the previous module ID
+ * @since 3.13
+ */
+ public final long getAndIncrementNextId() {
+ writeLock();
+ try {
+ return nextId.getAndIncrement();
+ } finally {
+ writeUnlock();
+ }
+ }
+
+ /**
* Returns the current timestamp for the revisions of this database.
* The timestamp is incremented any time a modification
* is made to the revisions in this database. For example:

Back to the top