All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.document.library.internal.messaging.DLDeletionMessagingConfigurator Maven / Gradle / Ivy

/**
 * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.document.library.internal.messaging;

import com.liferay.document.library.internal.configuration.StoreAreaConfiguration;
import com.liferay.portal.configuration.metatype.bnd.util.ConfigurableUtil;
import com.liferay.portal.kernel.messaging.Destination;
import com.liferay.portal.kernel.messaging.DestinationConfiguration;
import com.liferay.portal.kernel.messaging.DestinationFactory;
import com.liferay.portal.kernel.messaging.DestinationNames;
import com.liferay.portal.kernel.util.MapUtil;

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 Adolfo Pérez
 */
@Component(
	configurationPid = "com.liferay.document.library.internal.configuration.StoreAreaConfiguration",
	service = {}
)
public class DLDeletionMessagingConfigurator {

	@Activate
	protected void activate(
		BundleContext bundleContext, Map properties) {

		DestinationConfiguration destinationConfiguration =
			DestinationConfiguration.createSerialDestinationConfiguration(
				DestinationNames.DOCUMENT_LIBRARY_DELETION);

		StoreAreaConfiguration storeAreaConfiguration =
			ConfigurableUtil.createConfigurable(
				StoreAreaConfiguration.class, properties);

		int maxDeletionQueueSize =
			storeAreaConfiguration.maxDeletionQueueSize();

		if (maxDeletionQueueSize <= 0) {
			maxDeletionQueueSize = Integer.MAX_VALUE;
		}

		destinationConfiguration.setMaximumQueueSize(maxDeletionQueueSize);

		Destination destination = _destinationFactory.createDestination(
			destinationConfiguration);

		_destinationServiceRegistration = bundleContext.registerService(
			Destination.class, destination,
			MapUtil.singletonDictionary(
				"destination.name", destination.getName()));
	}

	@Deactivate
	protected void deactivate() {
		if (_destinationServiceRegistration != null) {
			_destinationServiceRegistration.unregister();
		}
	}

	@Reference
	private DestinationFactory _destinationFactory;

	private ServiceRegistration _destinationServiceRegistration;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy