com.liferay.portal.upgrade.internal.release.ReleasePublisher Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.upgrade.internal.release;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.model.Release;
import com.liferay.portal.kernel.module.framework.ModuleServiceLifecycle;
import com.liferay.portal.kernel.service.ReleaseLocalService;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
/**
* @author Miguel Pastor
* @author Carlos Sierra Andrés
*/
@Component(immediate = true, service = ReleasePublisher.class)
public final class ReleasePublisher {
public void publish(Release release) {
ServiceRegistration oldServiceRegistration =
_serviceConfiguratorRegistrations.get(
release.getServletContextName());
if (oldServiceRegistration != null) {
oldServiceRegistration.unregister();
}
Dictionary properties = new Hashtable<>();
properties.put(
"release.bundle.symbolic.name", release.getBundleSymbolicName());
properties.put("release.schema.version", release.getSchemaVersion());
ServiceRegistration newServiceRegistration =
_bundleContext.registerService(Release.class, release, properties);
_serviceConfiguratorRegistrations.put(
release.getServletContextName(), newServiceRegistration);
}
@Activate
protected void activate(BundleContext bundleContext) {
_bundleContext = bundleContext;
List releases = _releaseLocalService.getReleases(
QueryUtil.ALL_POS, QueryUtil.ALL_POS);
for (Release release : releases) {
publish(release);
}
}
@Deactivate
protected void deactivate() {
for (ServiceRegistration serviceRegistration :
_serviceConfiguratorRegistrations.values()) {
serviceRegistration.unregister();
}
}
@Reference(target = ModuleServiceLifecycle.PORTAL_INITIALIZED, unbind = "-")
protected void setModuleServiceLifecycle(
ModuleServiceLifecycle moduleServiceLifecycle) {
}
@Reference(unbind = "-")
protected void setReleaseLocalService(
ReleaseLocalService releaseLocalService) {
_releaseLocalService = releaseLocalService;
}
private BundleContext _bundleContext;
private ReleaseLocalService _releaseLocalService;
private final Map>
_serviceConfiguratorRegistrations = new HashMap<>();
}