public static boolean isCollector() { IoCs.findOrCreateInstance(Repository.class); // ensure we have a repo which init store classes by default return IoCs.getInstance(CollectorCounterStore.class) != null; } }
@Override public void contextDestroyed(final ServletContextEvent sce) { IoCs.shutdown(); } }
public static <T> T autoSet(final T instance) throws Exception { return autoSet(null, instance); }
public CassandraPathTrackingDataStore() { this.cassandra = IoCs.findOrCreateInstance( CassandraSirona.class ); this.keyspace = cassandra.getKeyspace(); this.family = cassandra.getPathTrackingColumFamily(); this.markerFamilly = cassandra.getMarkerPathTrackingColumFamily(); }
public CassandraCollectorDataStoreFactory() { super( IoCs.processInstance(new CassandraCollectorCounterDataStore()), IoCs.processInstance(new CassandraCollectorGaugeDataStore()), IoCs.processInstance(new CassandraCollectorNodeStatusDataStore()), IoCs.processInstance(new CassandraPathTrackingDataStore())); } }
public static synchronized <T> T findOrCreateInstance(final Class<T> clazz) { final T t = clazz.cast(SINGLETONS.get(clazz)); if (t != null) { return t; } return newInstance(clazz); }
public static <T> T processInstance(final T instance) { try { return internalProcessInstance(instance); } catch (final Exception e) { throw new SironaException(e); } }
public CassandraCollectorCounterDataStore() { this.cassandra = IoCs.findOrCreateInstance(CassandraSirona.class); this.keyspace = cassandra.getKeyspace(); this.markerFamily = cassandra.getMarkerCountersColumnFamily(); this.family = cassandra.getCounterColumnFamily(); }
public CassandraAgentDataStoreFactory() { super( IoCs.processInstance(new CassandraCounterDataStore()), IoCs.processInstance(new CassandraGaugeDataStore()), IoCs.processInstance(new CassandraStatusDataStore()), IoCs.processInstance(new CassandraPathTrackingDataStore())); } }
public static synchronized <T> T newInstance(final Class<T> clazz) { String config = Configuration.getProperty(clazz.getName(), null); try { if (config == null) { if (clazz.isInterface()) { config = clazz.getPackage().getName() + ".Default" + clazz.getSimpleName(); } else { config = clazz.getName(); } } final T t = newInstance(clazz, config); SINGLETONS.put(clazz, t); return t; } catch (final Exception e) { throw new SironaException("Cannot find instance for class " + clazz.getName() + " with config : " // + config + " : " + e.getMessage(),e); } }
private static <T> T newInstance(final Class<T> clazz, final String config) throws Exception { Class<?> loadedClass; try { loadedClass = ClassLoaders.current().loadClass(config); } catch (final Throwable throwable) { // NoClassDefFoundError or Exception loadedClass = clazz; } return clazz.cast(internalProcessInstance(loadedClass.newInstance())); }
public CassandraCollectorNodeStatusDataStore() { this.cassandra = IoCs.findOrCreateInstance(CassandraSirona.class); this.keyspace = cassandra.getKeyspace(); this.family = cassandra.getStatusColumnFamily(); this.markerFamily = cassandra.getMarkerStatusesColumnFamily(); }
public WebSocketDataStoreFactory() { super( IoCs.processInstance(new WebSocketCounterDataStore()), IoCs.processInstance(new WebSocketGaugeDataStore()), IoCs.processInstance(new WebSocketNodeStatusDataStore()), new InMemoryPathTrackingDataStore() // TODO ); } }
@Override public void run() { shutdown(); } };
public static <T> T[] newInstances(final Class<T> api) { final String names = Configuration.getProperty(api.getName(), null); if (names == null) { return (T[]) Array.newInstance(api, 0); } final String[] split = names.split(","); final T[] array = (T[]) Array.newInstance(api, split.length); for (int i = 0; i < array.length; i++) { try { array[i] = newInstance(api, split[i]); } catch (final Exception e) { throw new SironaException(e); } } return array; }
public static <T> T autoSet(final String key, final T instance) throws Exception { return autoSet(key, instance, instance.getClass()); }
public CassandraCollectorGaugeDataStore() { this.cassandra = IoCs.findOrCreateInstance(CassandraSirona.class); this.keyspace = cassandra.getKeyspace(); this.valueFamily = cassandra.getGaugeValuesColumnFamily(); this.markerFamily = cassandra.getMarkerGaugesColumFamily(); }
private static <T> T internalProcessInstance(final T instance) throws Exception { final Class<?> loadedClass = instance.getClass(); // autoset before invoking @Created if (loadedClass.getAnnotation(AutoSet.class) != null) { autoSet(null, instance, loadedClass); } Class<?> clazz = loadedClass; while (clazz != null && !Object.class.equals(clazz)) { for (final Method m : clazz.getDeclaredMethods()) { if (m.getAnnotation(Created.class) != null) { m.setAccessible(true); m.invoke(instance); } else if (m.getAnnotation(Destroying.class) != null) { m.setAccessible(true); if (shutdownHook == null == Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "shutdown.hook", true)) { shutdownHook = new Thread() { @Override public void run() { shutdown(); } }; Runtime.getRuntime().addShutdownHook(shutdownHook); } INSTANCES.add(new ToDestroy(m, instance)); } } clazz = clazz.getSuperclass(); } return instance; }
final CollectorGaugeDataStore gaugeStore = IoCs.findOrCreateInstance(CollectorGaugeDataStore.class); final Iterator<String> markers = gaugeStore.markers().iterator(); final StringBuilder builder = new StringBuilder("[");