Search in sources :

Example 6 with InstallableUnitEvent

use of org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent 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;
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Example 7 with InstallableUnitEvent

use of org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent 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);
}
Also used : State(org.apache.felix.fileinstall.plugins.installer.State) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) InstallableUnitEvent(org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)

Aggregations

InstallableUnitEvent (org.apache.felix.fileinstall.plugins.installer.InstallableUnitEvent)7 State (org.apache.felix.fileinstall.plugins.installer.State)5 LinkedList (java.util.LinkedList)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 Collection (java.util.Collection)2 List (java.util.List)2 ArtifactInstaller (org.apache.felix.fileinstall.ArtifactInstaller)2 InstallableListener (org.apache.felix.fileinstall.plugins.installer.InstallableListener)2 Test (org.junit.Test)2 Bundle (org.osgi.framework.Bundle)2 JarFile (java.util.jar.JarFile)1 Artifact (org.apache.felix.fileinstall.plugins.installer.Artifact)1 InstallableUnit (org.apache.felix.fileinstall.plugins.installer.InstallableUnit)1