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

com.datorama.oss.timbermill.common.persistence.PersistenceHandlerUtil Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
package com.datorama.oss.timbermill.common.persistence;

import com.datorama.oss.timbermill.common.redis.RedisService;

import java.util.Map;

public class PersistenceHandlerUtil {

	public static PersistenceHandler getPersistenceHandler(String persistenceStrategy,
														   Map params) {
		PersistenceHandler persistenceHandler = null;
		if (persistenceStrategy != null && !persistenceStrategy.toLowerCase().equals("none")){
			persistenceHandler = getPersistenceHandlerByStrategy(persistenceStrategy, params);
			if (!persistenceHandler.isCreatedSuccessfully()){
				persistenceHandler = null;
			}
		}
		return persistenceHandler;
	}

	private static PersistenceHandler getPersistenceHandlerByStrategy(String persistenceHandlerStrategy, Map params) {
		String strategy = persistenceHandlerStrategy.toLowerCase();
		switch (strategy) {
			case "sqlite":
				return new SQLJetPersistenceHandler(
						(int) params.get(PersistenceHandler.MAX_FETCHED_BULKS_IN_ONE_TIME),
						(int) params.get(PersistenceHandler.MAX_FETCHED_EVENTS_IN_ONE_TIME),
						(int) params.get(PersistenceHandler.MAX_INSERT_TRIES),
						(String) params.get(SQLJetPersistenceHandler.LOCATION_IN_DISK));
			case "redis":
				return new RedisPersistenceHandler(
						(int) params.get(PersistenceHandler.MAX_FETCHED_BULKS_IN_ONE_TIME),
						(int) params.get(PersistenceHandler.MAX_FETCHED_EVENTS_IN_ONE_TIME),
						(int) params.get(PersistenceHandler.MAX_INSERT_TRIES),
						(int) params.get(RedisPersistenceHandler.TTL),
						(RedisService) params.get(RedisPersistenceHandler.REDIS_SERVICE));
			default:
				throw new RuntimeException("Unsupported persistence handler strategy " + persistenceHandlerStrategy);
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy