/*-
 * ~~~~~~licensing~~~~~~
 * test-producers
 * ==========
 * Copyright (C) 2020 - 2022 EmDev LLC
 * ==========
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.platform.base.objects.factory.tracker;

import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.entaxy.platform.base.objects.factory.EntaxyFactory;

public class TrackedFactory {

	private static final Logger log = LoggerFactory.getLogger(TrackedFactory.class);
	
	public static Map<String, TrackedFactory> trackedFactoriesMap = new HashMap<>();
	
	private String id;
	private Bundle bundle; 
	private String configString;
	
	private ServiceRegistration<EntaxyFactory> serviceRegistration;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Bundle getBundle() {
		return bundle;
	}

	public void setBundle(Bundle bundle) {
		this.bundle = bundle;
	}

	public String getConfigString() {
		return configString;
	}

	public void setConfigString(String configString) {
		this.configString = configString;
	}

	public ServiceRegistration<EntaxyFactory> getServiceRegistration() {
		return serviceRegistration;
	}

	public void setServiceRegistration(ServiceRegistration<EntaxyFactory> serviceRegistration) {
		this.serviceRegistration = serviceRegistration;
	}
	
	public void unregister() {
		if (this.serviceRegistration != null)
			try {
				this.serviceRegistration.unregister();
			} catch (Exception e) {
				log.warn("TrackedFactory [" + getId() + "]", e);
			}
	}
}
