use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.
the class DeploymentInstaller method invalidateAllUnits.
private void invalidateAllUnits(String reason) {
List<File> affectedFiles = new LinkedList<>();
List<InstallableUnitEvent> events = new LinkedList<>();
withLock(this.unitsLock.writeLock(), () -> {
for (Entry<File, InstallableUnitImpl> entry : this.units.entrySet()) {
InstallableUnitImpl unit = entry.getValue();
State currentState = unit.getState();
if (EnumSet.of(State.RESOLVED, State.ERROR).contains(currentState)) {
unit.setState(State.REMOVED);
affectedFiles.add(entry.getKey());
events.add(new InstallableUnitEvent(currentState, State.REMOVED, unit));
debug("invalidated %s because: %s%n", entry.getKey(), reason);
}
}
});
notifyListeners(events);
// Schedule re-resolution of the affected files.
for (File file : affectedFiles) {
putResolveJob(file);
}
}
use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.
the class DeploymentInstaller method installArtifacts.
private List<Bundle> installArtifacts(InstallableUnitImpl unit) {
Supplier<List<Bundle>> func = () -> {
State oldState = unit.getState();
unit.setState(State.INSTALLING);
notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.INSTALLING, unit)));
try {
// Install Bundles
Collection<Artifact> artifacts = unit.getArtifacts();
List<String> locations = artifacts.stream().map(Artifact::getLocation).collect(Collectors.toList());
List<Bundle> installed = this.frameworkInstaller.addLocations(unit, locations);
// Start bundles
for (Bundle bundle : installed) {
if (!isFragment(bundle)) {
bundle.start();
}
}
// Mark unit installed
oldState = unit.getState();
unit.setState(State.INSTALLED);
notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.INSTALLED, unit)));
return installed;
} catch (BundleException | IOException e) {
oldState = unit.getState();
unit.setState(State.ERROR);
unit.setErrorMessage(e.getMessage());
if (log != null) {
log.log(LogService.LOG_ERROR, "Error installing artifact(s)", e);
}
notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.ERROR, unit)));
return Collections.emptyList();
}
};
return withLock(this.unitsLock.writeLock(), func);
}
use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.
the class DeploymentInstaller method uninstallArtifacts.
private List<Bundle> uninstallArtifacts(InstallableUnitImpl unit) {
List<Bundle> bundles = this.frameworkInstaller.removeSponsor(unit);
// Mark unit uninstalled
withLock(this.unitsLock.writeLock(), () -> {
State oldState = unit.getState();
if (unit.setState(State.REMOVED)) {
notifyListeners(Collections.singleton(new InstallableUnitEvent(oldState, State.REMOVED, unit)));
}
});
return bundles;
}
use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.
the class DeploymentInstaller method unsponsorUnit.
/**
* Unsponsor the installable unit. Returns a promise which is resolved when the uninstall is completed.
*/
private Promise<List<Bundle>> unsponsorUnit(File file) {
List<InstallableUnitEvent> events = new LinkedList<>();
Promise<List<Bundle>> bundles = withLock(this.unitsLock.writeLock(), () -> {
Promise<List<Bundle>> promise = Promises.resolved(Collections.emptyList());
InstallableUnitImpl existing = this.units.remove(file);
if (existing != null) {
State origState = existing.getState();
if (origState.equals(State.INSTALLED)) {
promise = putUninstallJob(existing);
}
if (existing.setState(State.REMOVED)) {
events.add(new InstallableUnitEvent(origState, State.REMOVED, existing));
}
}
return promise;
});
notifyListeners(events);
return bundles;
}
use of org.apache.felix.fileinstall.plugins.installer.State in project felix by apache.
the class DeploymentInstaller method replaceUnit.
private void replaceUnit(File file, State origState, InstallableUnitImpl newUnit) {
Collection<InstallableUnitEvent> events = new ArrayList<>(2);
events.add(new InstallableUnitEvent(origState, newUnit.getState(), newUnit));
events.addAll(withLock(this.unitsLock.writeLock(), () -> {
InstallableUnitImpl existing = this.units.put(file, newUnit);
if (existing != null) {
State oldState = existing.getState();
if (existing.setState(State.REMOVED)) {
return Collections.singleton(new InstallableUnitEvent(oldState, State.REMOVED, existing));
}
}
return Collections.emptyList();
}));
notifyListeners(events);
}
Aggregations