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

com.automationrockstars.gunter.events.EventStore Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2015 Automation RockStars Ltd.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     Automation RockStars - initial API and implementation
 *******************************************************************************/
package com.automationrockstars.gunter.events;

import java.util.Arrays;
import java.util.Map;

import com.automationrockstars.gunter.EventType;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;

public class EventStore {

	private static final ThreadLocal,Event>> gevents = new InheritableThreadLocal,Event>>(){
		@Override
		protected Map,Event> initialValue()  {
			return Maps.newHashMap();
		}
		@Override
		protected Map,Event> childValue(Map,Event> parentValue){
			return Maps.newHashMap(parentValue);

		}

	};

	public static final  T getEvent(Class klass){
		return (T) gevents.get().get(klass);
	}

	public static final void putEvent(Event event){

		Class key = (Class) Iterables.find(Arrays.asList(event.getClass().getInterfaces()), new Predicate>() {
			@Override
			public boolean apply(Class input) {
				return input.getName().startsWith("com.automationrockstars.gunter.events.");
			};
		});
		
		gevents.get().put(key, event);
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy