com.venky.extension.Registry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Commonly used programming tasks in java
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();
}
}