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

com.github.petruki.switcher.client.factory.SwitcherOffline Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package com.github.petruki.switcher.client.factory;

import java.util.Map;

import org.apache.log4j.Logger;

import com.github.petruki.switcher.client.domain.CriteriaResponse;
import com.github.petruki.switcher.client.domain.Switcher;
import com.github.petruki.switcher.client.domain.criteria.Domain;
import com.github.petruki.switcher.client.exception.SwitcherException;
import com.github.petruki.switcher.client.facade.ClientOfflineServiceFacade;
import com.github.petruki.switcher.client.utils.SnapshotLoader;
import com.github.petruki.switcher.client.utils.SwitcherContextParam;

/**
 * @author rogerio
 * @since 2019-12-24
 */
public class SwitcherOffline implements SwitcherExecutor {
	
	private static final Logger logger = Logger.getLogger(SwitcherOffline.class);
	
	private String snapshotLocation;
	
	public SwitcherOffline(final String snapshotLocation) {
		
		this.init(snapshotLocation);
	}
	
	public void init(final String snapshotLocation) {
		
		this.snapshotLocation = snapshotLocation;
	}
	
	@Override
	public boolean executeCriteria(final Switcher switcher) throws SwitcherException {
		
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("switcher: %s", switcher));
		}
		
		final Domain domain = SnapshotLoader.loadSnapshot(this.snapshotLocation);
		final CriteriaResponse response = ClientOfflineServiceFacade.getInstance().executeCriteria(switcher, domain);
		
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("[Offline] response: %s", response));
		}
		
		return response.isItOn();
	}
	
	@Override
	public void updateContext(final Map properties) {
		this.snapshotLocation = (String) properties.get(SwitcherContextParam.SNAPSHOT_LOCATION);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy