/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */

package com.liferay.portal.kernel.deploy.hot;

import com.liferay.portal.kernel.util.AutoResetThreadLocal;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;

/**
 * @author Miguel Pastor
 * @author Raymond Augé
 */
public class DependencyManagementThreadLocal {

	public static Boolean isEnabled() {
		return _enabled.get();
	}

	public static void setEnabled(boolean enabled) {
		_enabled.set(enabled);
	}

	private static ThreadLocal<Boolean> _enabled;

	static {
		if (GetterUtil.getBoolean(
				PropsUtil.get(
					PropsKeys.HOT_DEPLOY_DEPENDENCY_MANAGEMENT_ENABLED),
				true)) {

			_enabled = new AutoResetThreadLocal<Boolean>(
				DependencyManagementThreadLocal.class + ".enabled", true);
		}
		else {
			_enabled = new ThreadLocal<Boolean>() {

				@Override
				public Boolean get() {
					return Boolean.FALSE;
				}

			};
		}
	}

}