/*-
 * ~~~~~~licensing~~~~~~
 * init-manager
 * ==========
 * Copyright (C) 2020 - 2021 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.esb.platform.runtime.core.initializer.api;

import org.osgi.framework.BundleContext;

public interface Initializer {

	public static interface Callback {
		public void inited(Initializer owner);
	}
	
	public static final String INITIALIZER_CLASS_HEADER = "Entaxy-Initializer-Class";
	
	
	/*
	 * Query string params for bundle manifest header Entaxy-Initializer-Class
	 * - id - initializer ID (className by default)
	 * - depends-on - list of comma-separated ids on initializers that must be executed first
	 * - repeat - repeat initialization on every start (e.g. liquibase updater) (false by default)
	 * 
	 * The header will look like
	 * Entaxy-Initializer-Class: ru.entaxy.initializer.Init1?id=init_1&depends-on=connection&repeat=true
	 */
	public static final String INITIALIZER_QUERY_STRING_PARAM_ID = "id";
	public static final String INITIALIZER_QUERY_STRING_PARAM_DEPENDS_ON = "depends-on";
	public static final String INITIALIZER_QUERY_STRING_PARAM_REPEAT = "repeat";
	public static final String INITIALIZER_QUERY_STRING_PARAM_RETRIES = "retries";
	public static final String INITIALIZER_QUERY_STRING_PARAM_INTERVAL = "interval";
	
	public void init() throws InitializerException;
	
	/*
	 * Initializer must do cleanup and init again
	 * 
	 * for future use
	 */
	public void reinit() throws InitializerException;
	
	public void setBundleContext(BundleContext context);
	public long getBundleId();
	public String getBundleName();
	
	public void setInitializerId(String id);
	public String getInitializerId();
	
	public void setCalllback(Initializer.Callback callback);
}
