/** * 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.scripting.executor.internal.messaging; 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.MessageBus; import com.liferay.portal.kernel.scripting.Scripting; import com.liferay.portal.kernel.util.HashMapDictionary; import com.liferay.portal.scripting.executor.internal.ScriptingExecutorMessagingConstants; import java.util.Dictionary; 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 Michael C. Han */ @Component(immediate = true) public class ScriptingExecutorMessagingConfigurator { @Activate protected void activate(BundleContext bundleContext) { _bundleContext = bundleContext; DestinationConfiguration destinationConfiguration = new DestinationConfiguration( DestinationConfiguration.DESTINATION_TYPE_PARALLEL, ScriptingExecutorMessagingConstants.DESTINATION_NAME); Destination destination = _destinationFactory.createDestination( destinationConfiguration); Dictionary<String, Object> properties = new HashMapDictionary<>(); properties.put("destination.name", destination.getName()); _destinationServiceRegistration = bundleContext.registerService( Destination.class, destination, properties); ScriptingExecutorMessageListener scriptingExecutorMessageListener = new ScriptingExecutorMessageListener(_scripting); destination.register(scriptingExecutorMessageListener); } @Deactivate protected void deactivate() { if (_destinationServiceRegistration != null) { Destination destination = _bundleContext.getService( _destinationServiceRegistration.getReference()); _destinationServiceRegistration.unregister(); destination.destroy(); } _bundleContext = null; } @Reference(unbind = "-") protected void setMessageBus(MessageBus messageBus) { } private volatile BundleContext _bundleContext; @Reference private DestinationFactory _destinationFactory; private volatile ServiceRegistration<Destination> _destinationServiceRegistration; @Reference private Scripting _scripting; }