final int getInitialModuleStartLevel() { readLock(); try { return this.initialModuleStartLevel; } finally { readUnlock(); } }
private void setSystemLastModified(long currentTime) { // sanity check checkWrite(); Module systemModule = getModule(0); if (systemModule != null) { systemModule.setlastModified(currentTime); } }
@Override public Collection<BundleCapability> findProviders(Requirement requirement) { return InternalUtils.asListBundleCapability(moduleDatabase.findCapabilities(requirement)); }
/** * Returns the dependency closure of for the specified modules. * @param initial The initial modules for which to generate the dependency closure * @return A collection containing a snapshot of the dependency closure of the specified * modules, or an empty collection if there were no specified modules. */ public Collection<Module> getDependencyClosure(Collection<Module> initial) { moduleDatabase.readLock(); try { return getRefreshClosure(initial, moduleDatabase.getWiringsCopy()); } finally { moduleDatabase.readUnlock(); } }
/** * Updates the specified module with anew revision using the specified builder. * <p> * A write operation protected by the {@link #writeLock() write} lock. * @param module the module for which the revision provides an update for * @param builder the builder to use to create the new revision * @param revisionInfo the revision info for the new revision, may be {@code null}. */ final void update(Module module, ModuleRevisionBuilder builder, Object revisionInfo) { writeLock(); try { ModuleRevision oldRevision = module.getCurrentRevision(); ModuleRevision newRevision = builder.addRevision(module, revisionInfo); addCapabilities(newRevision); // if the old revision does not have a wiring it can safely be removed ModuleWiring oldWiring = wirings.get(oldRevision); if (oldWiring == null) { module.getRevisions().removeRevision(oldRevision); removeCapabilities(oldRevision); } // attempt to clean up removal pendings cleanupRemovalPending(); long currentTime = System.currentTimeMillis(); module.setlastModified(currentTime); setSystemLastModified(currentTime); incrementTimestamps(true); } finally { writeUnlock(); } }
Map<ModuleWiring, Collection<ModuleWire>> toRemoveWireLists; long timestamp; moduleDatabase.readLock(); try { checkSystemExtensionRefresh(initial); timestamp = moduleDatabase.getRevisionsTimestamp(); wiringCopy = moduleDatabase.getWiringsCopy(); refreshTriggers = new ArrayList<>(getRefreshClosure(initial, wiringCopy)); toRemoveRevisions = new ArrayList<>(); moduleDatabase.sortModules(refreshTriggers, Sort.BY_START_LEVEL, Sort.BY_DEPENDENCY); } finally { moduleDatabase.readUnlock(); Module systemModule = moduleDatabase.getModule(0); if (refreshTriggers.contains(systemModule) && Module.ACTIVE_SET.contains(systemModule.getState())) { refreshSystemModule(); moduleDatabase.writeLock(); try { if (timestamp != moduleDatabase.getRevisionsTimestamp()) return null; // need to try again moduleDatabase.removeCapabilities(removed); moduleDatabase.setWiring(wiringCopy); moduleDatabase.cleanupRemovalPending(); } finally {
/** * Installs a new revision using the specified builder, location and module. * <p> * A write operation protected by the {@link #writeLock() write} lock. * @param location the location to use for the installation * @param builder the builder to use to create the new revision * @param revisionInfo the revision info for the new revision, may be {@code null}. * @return the installed module */ final Module install(String location, ModuleRevisionBuilder builder, Object revisionInfo) { writeLock(); try { int startlevel = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : getInitialModuleStartLevel(); long id = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : getNextIdAndIncrement(); EnumSet<Settings> settings = getActivationPolicySettings(builder); Module module = load(location, builder, revisionInfo, id, settings, startlevel); long currentTime = System.currentTimeMillis(); module.setlastModified(currentTime); setSystemLastModified(currentTime); incrementTimestamps(true); return module; } finally { writeUnlock(); } }
public static void store(ModuleDatabase moduleDatabase, DataOutputStream out, boolean persistWirings) throws IOException { out.writeInt(VERSION); out.writeLong(moduleDatabase.getRevisionsTimestamp()); out.writeLong(moduleDatabase.getTimestamp()); out.writeLong(moduleDatabase.getNextId()); out.writeInt(moduleDatabase.getInitialModuleStartLevel()); List<Module> modules = moduleDatabase.getModules(); out.writeInt(modules.size()); Collection<ModuleRevision> removalPendings = moduleDatabase.getRemovalPending();
void save0() throws IOException { StorageManager childStorageManager = null; DataOutputStream out = null; moduleDatabase.readLock(); try { synchronized (this.saveMonitor) { if (lastSavedTimestamp == moduleDatabase.getTimestamp()) return; childStorageManager = getChildStorageManager(); out = new DataOutputStream(new BufferedOutputStream(childStorageManager.getOutputStream(FRAMEWORK_INFO))); saveGenerations(out); savePermissionData(out); moduleDatabase.store(out, true); lastSavedTimestamp = moduleDatabase.getTimestamp(); } } finally { if (out != null) { try { out.close(); } catch (IOException e) { // tried our best } } if (childStorageManager != null) { childStorageManager.close(); } moduleDatabase.readUnlock(); } }
writeLock(); try { int startlevel = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : getInitialModuleStartLevel(); long id = Constants.SYSTEM_BUNDLE_LOCATION.equals(location) ? 0 : builder.getId(); if (id == -1) { 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(); module.setlastModified(currentTime); setSystemLastModified(currentTime); incrementTimestamps(true); return module; } finally { writeUnlock();
Map<ModuleRevision, ModuleWiring> wiringClone; long timestamp; moduleDatabase.readLock(); try { timestamp = moduleDatabase.getRevisionsTimestamp(); wiringClone = moduleDatabase.getWiringsClone(); for (Module module : triggers) { if (!State.UNINSTALLED.equals(module.getState())) { Collection<Module> allModules = moduleDatabase.getModules(); for (Module module : allModules) { ModuleRevision revision = module.getCurrentRevision(); moduleDatabase.readUnlock();
private void resolve(boolean uninstalled) { database.readLock(); try { if (lastResolveStamp != database.getRevisionsTimestamp()) { Collection<ModuleRevision> containerRemovalPending = container.getRemovalPending(); BundleDescription[] stateRemovalPendingDescs = systemState.getRemovalPending(); Collection<BundleDescription> stateRemovalPending = new ArrayList<>(stateRemovalPendingDescs.length); for (BundleDescription description : stateRemovalPendingDescs) { if (!containerRemovalPending.contains(description.getUserObject())) { stateRemovalPending.add(description); } } if (!stateRemovalPending.isEmpty()) { systemState.resolve(stateRemovalPending.toArray(new BundleDescription[stateRemovalPending.size()]), true); } else { systemState.resolve(!uninstalled); } lastResolveStamp = database.getRevisionsTimestamp(); systemState.setTimeStamp(database.getRevisionsTimestamp()); } } finally { database.readUnlock(); } }
if (currentSL == 0) { Module systemModule = moduleDatabase.getModule(0); if (systemModule != null && !State.STARTING.equals(systemModule.getState())) { return; Debug.println("StartLevel: incremented active start level to; " + toStartLevel); //$NON-NLS-1$ if (sorted == null || currentTimestamp != moduleDatabase.getTimestamp()) { moduleDatabase.readLock(); try { sorted = moduleDatabase.getSortedModules(Sort.BY_START_LEVEL); currentTimestamp = moduleDatabase.getTimestamp(); } finally { moduleDatabase.readUnlock(); Debug.println("StartLevel: decremented active start level to " + toStartLevel); //$NON-NLS-1$ if (sorted == null || currentTimestamp != moduleDatabase.getTimestamp()) { moduleDatabase.readLock(); try { sorted = moduleDatabase.getSortedModules(Sort.BY_START_LEVEL, Sort.BY_DEPENDENCY); currentTimestamp = moduleDatabase.getTimestamp(); } finally { moduleDatabase.readUnlock();
this.securityAdmin = new SecurityAdmin(null, this.permissionData); this.adaptor = new EquinoxContainerAdaptor(equinoxContainer, this, generations); this.moduleDatabase = new ModuleDatabase(this.adaptor); this.moduleContainer = new ModuleContainer(this.adaptor, this.moduleDatabase); if (data != null) { try { moduleDatabase.load(data); lastSavedTimestamp = moduleDatabase.getTimestamp(); } catch (IllegalArgumentException e) { equinoxContainer.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.WARNING, "Incompatible version. Starting with empty framework.", e); //$NON-NLS-1$
@Override public Collection<Bundle> getRemovalPendingBundles() { moduleDatabase.readLock(); try { Collection<Bundle> removalPendingBundles = new HashSet<Bundle>(); Collection<ModuleRevision> removalPending = moduleDatabase.getRemovalPending(); for (ModuleRevision moduleRevision : removalPending) { removalPendingBundles.add(moduleRevision.getBundle()); } return removalPendingBundles; } finally { moduleDatabase.readUnlock(); } }
final Module load(String location, ModuleRevisionBuilder builder, Object revisionInfo, long id, EnumSet<Settings> settings, int startlevel) { // sanity check checkWrite(); if (modulesByLocations.containsKey(location)) throw new IllegalArgumentException("Location is already used: " + location); //$NON-NLS-1$ if (modulesById.containsKey(id)) throw new IllegalArgumentException("Id is already used: " + id); //$NON-NLS-1$ Module module; if (id == 0) { module = adaptor.createSystemModule(); } else { module = adaptor.createModule(location, id, settings, startlevel); } builder.addRevision(module, revisionInfo); modulesByLocations.put(location, module); modulesById.put(id, module); if (settings != null) moduleSettings.put(id, settings); ModuleRevision newRevision = module.getCurrentRevision(); addCapabilities(newRevision); return module; }
long getTimeStamp() { synchronized (this.monitor) { return equinoxContainer.getStorage().getModuleDatabase().getRevisionsTimestamp(); } }
/** * Increments by one the next module ID */ private long getNextIdAndIncrement() { // sanity check checkWrite(); return nextId.getAndIncrement(); }
private void readLock() { equinoxContainer.getStorage().getModuleDatabase().readLock(); }
private void readUnlock() { equinoxContainer.getStorage().getModuleDatabase().readUnlock(); }