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

com.venky.extension.Registry Maven / Gradle / Ivy

package com.venky.extension;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.venky.core.log.TimerStatistics.Timer;


public class Registry {
	private Registry(){
		
	}
	private static Registry instance = new Registry();
	public static Registry instance(){
		return instance;
	}
	private HashMap> extensionsMap = new HashMap>();
	public void registerExtension(String name,Extension extension){
		List extensions = getExtensions(name);
		extensions.add(extension);
	}
	
	public List getExtensions(String extensionPoint){
		List extensions = extensionsMap.get(extensionPoint);
		if (extensions == null){
			extensions = new ArrayList();
			extensionsMap.put(extensionPoint,extensions);
		}
		return extensions;
	}
	public boolean hasExtensions(String extensionPoint){
		return !getExtensions(extensionPoint).isEmpty();
	}
	
	public void callExtensions(String pointName, Object... context){
		for (Extension extn : getExtensions(pointName)){
			Timer timer = Timer.startTimer(extn.getClass().getName());
			try {
				extn.invoke(context);
			}finally {
				timer.stop();
			}
		}
	}
	
	public void clearExtensions(){
		extensionsMap.clear();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy