All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.exactpro.sf.configuration.EnvironmentManager Maven / Gradle / Ivy

There is a newer version: 3.4.260
Show newest version
/******************************************************************************
 * Copyright 2009-2018 Exactpro (Exactpro Systems Limited)
 *
 * 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.
 ******************************************************************************/
package com.exactpro.sf.configuration;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.exactpro.sf.scriptrunner.EnvironmentSettings;
import com.exactpro.sf.scriptrunner.IConnectionManager;
import com.exactpro.sf.storage.IMessageStorage;
import com.exactpro.sf.storage.IServiceStorage;

/**
 * The class is part of ScriptContext
 *
 */
public class EnvironmentManager implements IEnvironmentManager
{
    private static final Logger logger = LoggerFactory.getLogger(EnvironmentManager.class) ;

    private final ReadWriteLock envSettingsLock = new ReentrantReadWriteLock(false);

    private final IMessageStorage messageStorage;

    private final IServiceStorage serviceStorage;

    private final IConnectionManager connectionManager;

    private final EnvironmentSettings envSettings;

    public EnvironmentManager(IMessageStorage messageStorage, IServiceStorage serviceStorage, IConnectionManager connectionManager, EnvironmentSettings envSettings) throws Exception {
		logger.info("Environment manager initializing started...");
		this.messageStorage = messageStorage;
        this.serviceStorage = serviceStorage;
		this.connectionManager = connectionManager;
		this.envSettings = envSettings;
	}

    @Override
    public void updateEnvironmentSettings(EnvironmentSettings envSettings) {
        try {
            envSettingsLock.writeLock().lock();
            this.envSettings.set(envSettings);
        } finally {
            envSettingsLock.writeLock().unlock();
        }
    }

    @Override
    public EnvironmentSettings getEnvironmentSettings() {
        try {
            envSettingsLock.readLock().lock();
            return envSettings.clone();
        } finally {
            envSettingsLock.readLock().unlock();
        }
    }

    @Override
    public IConnectionManager getConnectionManager() {
        return connectionManager;
    }

    @Override
    public IMessageStorage getMessageStorage() {
        return messageStorage;
    }

    @Override
    public IServiceStorage getServiceStorage() {
        return serviceStorage;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy