@Override public <T> Iterable<T> find(final Class<T> api, final ClassLoader loader) { return SironaServiceLoader.load( api, loader ); } }
public static <S> SironaServiceLoader<S> load( Class<S> service, ClassLoader loader ) { return new SironaServiceLoader<S>( service, loader ); }
@Override public void store( final PathTrackingEntry pathTrackingEntry ) { CUBE.doPostBytes( SerializeUtils.serialize( pathTrackingEntry ), PathTrackingEntry.class.getName() ); }
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())); }
private BatchFuture startTask() { final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("nodestatusdatastore", ""); final long period = getPeriod(name); final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-status-alert-schedule-")); final ScheduledFuture<?> future = ses.scheduleAtFixedRate(new CheckStatus(), period, period, TimeUnit.MILLISECONDS); return new BatchFuture(ses, future); }
@Created protected void initMarkerIfNeeded() { if (marker == null) { marker = Localhosts.get(); } LOGGER.warning("This storage used on app side can be a bit slow, maybe consider using a remote collector"); }
/** * this method mimic the 1.6 ServiceLoader if you don't need 1.5 do not use that :-) * * @return */ public Iterator<S> iterator1_5() { String resourceName = "META-INF/services/" + this.service.getName(); try { List<String> serviceNames = new ArrayList<String>(); Enumeration<URL> urls = this.loader.getResources( resourceName ); while ( urls.hasMoreElements() ) { serviceNames.addAll( parseFile( urls.nextElement() ) ); } return initInstances( serviceNames ).iterator(); } catch ( Throwable t ) { throw new RuntimeException( t.getMessage(), t ); } }
public static String generateReport(final String label, final Role role, final long start, final long end) { if (!Environment.isCollector()) { final SortedMap<Long, Double> gaugeValues = Repository.INSTANCE.getGaugeValues(start, end, role); return "[" + Graphs.toJson(label, Graphs.DEFAULT_COLOR, aggregate(gaugeValues)) + "]";
@IgnoreJRERequirement public Iterator<S> iterator() { try { return java.util.ServiceLoader.load( this.service, this.loader ).iterator(); } catch ( Throwable t ) { // olamy revert to 1.5 way... return iterator1_5(); } }
public static <T> T getInstance(final Class<T> clazz, String className) { try { Class<?> tClass = ClassLoaders.current().loadClass( className ); return (T) tClass.newInstance(); } catch ( Exception e ) { throw new SironaException( "cannot instantiante instance of '" + className + "'",e ); } }
private void reload() { final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("nodestatusdatastore", ""); final long period = getPeriod(name); if (period < 0) { return; } final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-status-schedule-")); final ScheduledFuture<?> future = ses.scheduleAtFixedRate(new ReportStatusTask(), period, period, TimeUnit.MILLISECONDS); scheduledTask.set(new BatchFuture(ses, future)); }
@Created protected void initMarkerIfNotAlreadyDone() { if (marker == null) { marker = Localhosts.get(); } LOGGER.warning("This storage used on app side can be a bit slow, maybe consider using a remote collector"); }
public void onEvent( final PathTrackingEntry entry, final long sequence, final boolean endOfBatch ) throws Exception { if ( ( sequence % numberOfConsumers ) == ordinal ) { CUBE.doPostBytes( SerializeUtils.serialize( entry ), PathTrackingEntry.class.getName() ); } }
public static <T> T monitor(final Class<T> clazz, final Object instance) { return clazz.cast( IoCs.findOrCreateInstance(ProxyFactory.class) .createInvokerProxy(ClassLoaders.current(), new SironaPerformanceHandler(instance), new Class<?>[]{clazz})); }
@Created // call it only when main impl not in delegated mode so use IoC lifecycle management public void initAggregated() { final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("gaugedatastore", "") + ".aggregated"; final long period = getPeriod(name); final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-aggregated-gauge-schedule-")); final ScheduledFuture<?> future = ses.scheduleAtFixedRate(new PushGaugesTask(), period, period, TimeUnit.MILLISECONDS); scheduledAggregatedTask = new BatchFuture(ses, future); }
@Created protected void initMarkerIfNeeded() { if (marker == null) { marker = Localhosts.get(); } LOGGER.warning("This storage used on app side can be a bit slow, maybe consider using a remote collector"); }
protected static Collection<AlertListener> findAlerters() { final Collection<AlertListener> listeners = new ArrayList<AlertListener>(); final String alerters = Configuration.getProperty(Configuration.CONFIG_PROPERTY_PREFIX + "alerters", null); if (alerters != null && alerters.trim().length() > 0) { for (final String alert : alerters.split(" *, *")) { final String classKey = alert + ".class"; final String type = Configuration.getProperty(classKey, null); if (type == null) { throw new IllegalArgumentException("Missing configuration " + classKey); } try { final Class<?> clazz = ClassLoaders.current().loadClass(type); final AlertListener listener = IoCs.autoSet(alert, AlertListener.class.cast(clazz.newInstance())); listeners.add(listener); } catch (final Exception e) { throw new IllegalArgumentException(e); } } } return listeners; }
@Created // call it only when main impl not in delegated mode so use IoC lifecycle management public void initBatch() { final String name = getClass().getSimpleName().toLowerCase(Locale.ENGLISH).replace("gaugedatastore", ""); final long period = getPeriod(name); final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory(name + "-gauge-schedule-")); final ScheduledFuture<?> future = ses.scheduleAtFixedRate(new PushGaugesTask(), period, period, TimeUnit.MILLISECONDS); scheduledTask = new BatchFuture(ses, future); }
public synchronized Cube build() { if (cubeInstance != null) { return cubeInstance; } if (marker == null) { marker = Localhosts.get(); } if (sslKeyStore != null || sslTrustStore != null) { final KeyManager[] keyManagers = createKeyManager(); final TrustManager[] trustManagers = createTrustManager(); try { final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(keyManagers, trustManagers, new java.security.SecureRandom()); socketFactory = sslContext.getSocketFactory(); } catch (final Exception e) { throw new SironaException(e); } } else { socketFactory = null; } if (basicHeader != null) { // compute it basicHeader = "Basic " + DatatypeConverter.printBase64Binary(basicHeader.getBytes()); } return new Cube(this); }
@Created // call it only when main impl not in delegated mode so use IoC lifecycle management public void initBatch() { final String name = getClass().getSimpleName().toLowerCase( Locale.ENGLISH ).replace( "pathtrackingdatastore", "" ); final long period = getPeriod( name ); final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor( new DaemonThreadFactory( name + "-pathtracking-schedule-" ) ); final ScheduledFuture<?> future = ses.scheduleAtFixedRate( new PushPathTrackingTask(), period, period, TimeUnit.MILLISECONDS ); scheduledTask = new BatchFuture( ses, future ); }