@Override public double value() { try { return Number.class.cast(SERVER.getAttribute(name, attribute)).doubleValue(); } catch (final Exception e) { throw new SironaException(e); } } }
protected GaugeDataStore newStore(final String marker) { try { try { final Constructor<? extends GaugeDataStore> cons = delegateClass.getConstructor(String.class); return cons.newInstance(marker); } catch (final Exception e) { // no-op: use default constructor } return delegateClass.newInstance(); } catch (final Exception e) { throw new SironaException(e); } }
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 ); } }
@Override public void init(final FilterConfig filterConfig) throws ServletException { final String ignoredUrls = filterConfig.getInitParameter(IGNORED_URLS); if (ignoredUrls != null) { ignored = ignoredUrls.split(","); } final String monStatus = filterConfig.getInitParameter(MONITOR_STATUS); if ((monStatus == null || "true".equalsIgnoreCase(monStatus)) && filterConfig.getServletContext().getAttribute(GaugeDiscoveryListener.STATUS_GAUGES_ATTRIBUTE) == null) { throw new SironaException("To monitor status activate " + GaugeDiscoveryListener.class.getName()); } statusGauges = (Map<Integer, StatusGauge>) filterConfig.getServletContext().getAttribute(GaugeDiscoveryListener.STATUS_GAUGES_ATTRIBUTE); }
public DelegatedCollectorGaugeDataStore() { try { delegateClass = Class.class.cast( DelegatedCollectorGaugeDataStore.class.getClassLoader().loadClass( // use this classloader and not TCCL to avoid issues Configuration.getProperty(Configuration.CONFIG_PROPERTY_PREFIX + "collector.gauge.store-class", InMemoryGaugeDataStore.class.getName()))); } catch (final ClassNotFoundException e) { throw new SironaException(e.getMessage(),e); } }
public static <T> T processInstance(final T instance) { try { return internalProcessInstance(instance); } catch (final Exception e) { throw new SironaException(e); } }
public Method method() { if (realMethod == null) { // try to find it try { Class<?> declaring = Thread.currentThread().getContextClassLoader().loadClass(clazz); while (declaring != null) { for (final Method m : declaring.getDeclaredMethods()) { if (m.getName().equals(method)) { realMethod = m; return realMethod; } } declaring = declaring.getSuperclass(); } } catch (final ClassNotFoundException e) { throw new SironaException(e.getMessage(),e); } } return realMethod; }
protected TrustManager[] createTrustManager() { if (sslTrustStore == null) { return null; } try { KeyStore ks = KeyStore.getInstance(null == sslTrustStoreType ? KeyStore.getDefaultType() : sslTrustStoreType); char[] pwd; if (sslTrustStorePassword != null) { pwd = sslTrustStorePassword.toCharArray(); } else { pwd = "changeit".toCharArray(); } FileInputStream fis = new FileInputStream(sslTrustStore); try { ks.load(fis, pwd); } finally { fis.close(); } TrustManagerFactory tmf = TrustManagerFactory.getInstance(null == sslTrustStoreProvider ? TrustManagerFactory.getDefaultAlgorithm() : sslTrustStoreProvider); tmf.init(ks); return tmf.getTrustManagers(); } catch (final Exception e) { throw new SironaException(e); } }
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; }
protected KeyManager[] createKeyManager() { if (sslKeyStore == null) { return null; } try { KeyStore ks = KeyStore.getInstance(null == sslKeyStoreType ? KeyStore.getDefaultType() : sslKeyStoreType); char[] pwd; if (sslKeyStorePassword != null) { pwd = sslKeyStorePassword.toCharArray(); } else { pwd = "changeit".toCharArray(); } FileInputStream fis = new FileInputStream(sslKeyStore); try { ks.load(fis, pwd); } finally { fis.close(); } KeyManagerFactory kmf = KeyManagerFactory.getInstance(null == sslKeyStoreProvider ? KeyManagerFactory.getDefaultAlgorithm() : sslKeyStoreProvider); kmf.init(ks, pwd); return kmf.getKeyManagers(); } catch (final Exception e) { throw new SironaException(e); } }
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); } }
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); }