/**
* 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.security.ldap.internal.messaging.config;
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.util.HashMapDictionary;
import com.liferay.portal.security.ldap.internal.constants.LDAPDestinationNames;
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 MessagingConfigurator {
@Activate
protected void activate(BundleContext bundleContext) {
_bundleContext = bundleContext;
DestinationConfiguration destinationConfiguration =
new DestinationConfiguration(
DestinationConfiguration.DESTINATION_TYPE_SERIAL,
LDAPDestinationNames.SCHEDULED_USER_LDAP_IMPORT);
Destination destination = _destinationFactory.createDestination(
destinationConfiguration);
Dictionary<String, Object> dictionary = new HashMapDictionary<>();
dictionary.put("destination.name", destination.getName());
_serviceRegistration = bundleContext.registerService(
Destination.class, destination, dictionary);
}
@Deactivate
protected void deactivate() {
if (_serviceRegistration != null) {
Destination destination = _bundleContext.getService(
_serviceRegistration.getReference());
_serviceRegistration.unregister();
destination.destroy();
}
_bundleContext = null;
}
@Reference(unbind = "-")
protected void setDestinationFactory(
DestinationFactory destinationFactory) {
_destinationFactory = destinationFactory;
}
private volatile BundleContext _bundleContext;
private DestinationFactory _destinationFactory;
private ServiceRegistration<Destination> _serviceRegistration;
}