Search in sources :

Example 1 with InstallationEvent

use of org.apache.sling.installer.api.event.InstallationEvent in project sling by apache.

the class UpdateHandlerTest method getInstallerListenerBarrier.

private Barrier getInstallerListenerBarrier() {
    final Barrier b = new Barrier(2);
    final InstallationListener il = new InstallationListener() {

        public void onEvent(final InstallationEvent event) {
            if (event.getType() == InstallationEvent.TYPE.PROCESSED) {
                b.block();
            }
        }
    };
    b.reg = bundleContext.registerService(InstallationListener.class.getName(), il, null);
    return b;
}
Also used : InstallationListener(org.apache.sling.installer.api.event.InstallationListener) CyclicBarrier(java.util.concurrent.CyclicBarrier) InstallationEvent(org.apache.sling.installer.api.event.InstallationEvent)

Example 2 with InstallationEvent

use of org.apache.sling.installer.api.event.InstallationEvent in project sling by apache.

the class ConfigInstallTest method setUp.

@Before
public void setUp() {
    installationEvents = 0;
    setupInstaller();
    events.clear();
    serviceRegistrations.clear();
    serviceRegistrations.add(bundleContext.registerService(ConfigurationListener.class.getName(), this, null));
    final InstallationListener il = new InstallationListener() {

        @Override
        public void onEvent(InstallationEvent event) {
            installationEvents++;
        }
    };
    serviceRegistrations.add(bundleContext.registerService(InstallationListener.class.getName(), il, null));
}
Also used : InstallationListener(org.apache.sling.installer.api.event.InstallationListener) InstallationEvent(org.apache.sling.installer.api.event.InstallationEvent) Before(org.junit.Before)

Example 3 with InstallationEvent

use of org.apache.sling.installer.api.event.InstallationEvent in project sling by apache.

the class EntityResourceList method setFinishState.

@Override
public void setFinishState(ResourceState state, String error) {
    final TaskResource toActivate = getActiveResource();
    if (toActivate != null) {
        synchronized (lock) {
            if (toActivate.getState() == ResourceState.UNINSTALL && this.resources.size() > 1) {
                final TaskResource second = this.getNextActiveResource();
                // check for template
                if (second.getDictionary() != null && second.getDictionary().get(InstallableResource.RESOURCE_IS_TEMPLATE) != null) {
                    // second resource is a template! Do not install
                    ((RegisteredResourceImpl) second).setState(ResourceState.IGNORED, null);
                } else if (state == ResourceState.UNINSTALLED) {
                    // first resource got uninstalled, go back to second
                    if (second.getState() == ResourceState.IGNORED || second.getState() == ResourceState.INSTALLED) {
                        LOGGER.debug("Reactivating for next cycle: {}", second);
                        ((RegisteredResourceImpl) second).setState(ResourceState.INSTALL, null);
                    }
                } else {
                    // don't install as the first did not get uninstalled
                    if (second.getState() == ResourceState.INSTALL) {
                        String message = MessageFormat.format("The first resource '{0}' did not get uninstalled, therefore ignore this secondary resource in the uninstall group", toActivate.getEntityId());
                        LOGGER.debug(message);
                        ((RegisteredResourceImpl) second).setState(ResourceState.IGNORED, message);
                    }
                    // and now set resource to uninstalled
                    state = ResourceState.UNINSTALLED;
                }
            } else if (state == ResourceState.INSTALLED) {
                // make sure that no other resource has state INSTALLED
                if (this.resources.size() > 1) {
                    // to get the second item in the set we have to use an iterator!
                    final Iterator<RegisteredResourceImpl> i = this.resources.iterator();
                    // skip first
                    i.next();
                    while (i.hasNext()) {
                        final TaskResource rsrc = i.next();
                        if (rsrc.getState() == ResourceState.INSTALLED) {
                            ((RegisteredResourceImpl) rsrc).setState(ResourceState.INSTALL, null);
                        }
                    }
                }
            }
            ((RegisteredResourceImpl) toActivate).setState(state, error);
            if (state != ResourceState.INSTALLED) {
                // make sure to remove all install info attributes if the resource is not
                // installed anymore
                toActivate.setAttribute(TaskResource.ATTR_INSTALL_EXCLUDED, null);
                toActivate.setAttribute(TaskResource.ATTR_INSTALL_INFO, null);
            }
            // remove install info attributes on all other resources in the group
            final Iterator<RegisteredResourceImpl> tri = this.resources.iterator();
            // skip first
            tri.next();
            while (tri.hasNext()) {
                final TaskResource rsrc = tri.next();
                rsrc.setAttribute(TaskResource.ATTR_INSTALL_EXCLUDED, null);
                rsrc.setAttribute(TaskResource.ATTR_INSTALL_INFO, null);
            }
        }
        this.listener.onEvent(new InstallationEvent() {

            @Override
            public TYPE getType() {
                return TYPE.PROCESSED;
            }

            @Override
            public Object getSource() {
                return toActivate;
            }
        });
        if (state == ResourceState.UNINSTALLED) {
            this.cleanup(toActivate);
        }
    }
}
Also used : TaskResource(org.apache.sling.installer.api.tasks.TaskResource) Iterator(java.util.Iterator) InstallationEvent(org.apache.sling.installer.api.event.InstallationEvent)

Aggregations

InstallationEvent (org.apache.sling.installer.api.event.InstallationEvent)3 InstallationListener (org.apache.sling.installer.api.event.InstallationListener)2 Iterator (java.util.Iterator)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 TaskResource (org.apache.sling.installer.api.tasks.TaskResource)1 Before (org.junit.Before)1