package appeng.core.features.registries; import java.lang.reflect.Constructor; import java.util.HashMap; import appeng.api.networking.IGrid; import appeng.api.networking.IGridCache; import appeng.api.networking.IGridCacheRegistry; import appeng.core.AELog; public class GridCacheRegistry implements IGridCacheRegistry { final private HashMap, Class> caches = new HashMap(); @Override public void registerGridCache(Class iface, Class implementation) { if ( iface.isAssignableFrom( implementation ) ) caches.put( iface, implementation ); else throw new RuntimeException( "Invalid setup, grid cache must either be the same class, or an interface that the implementation implements" ); } @Override public HashMap, IGridCache> createCacheInstance(IGrid g) { HashMap, IGridCache> map = new HashMap(); for (Class iface : caches.keySet()) { try { Constructor c = caches.get( iface ).getConstructor( IGrid.class ); map.put( iface, c.newInstance( g ) ); } catch (Throwable e) { AELog.severe( "Grid Caches must have a constructor with IGrid as the single param." ); throw new RuntimeException( e ); } } return map; } }