static

in core/src/main/java/com/spotify/metrics/core/ReservoirWithTtl.java [63:84]


    static {
        // There is a breaking API change between metrics-core 3.1 and 3.2 where
        // com.codahale.metrics.Snapshot becomes abstract and is replaced by UniformSnapshot.
        // There are more breaking changes between the two versions (bumbing breaks hermes-java for
        // instance). On the other hand, newer versions of the datastax drivers use the newer
        // version. This means that to not force anyone to make a lot of changes to be able to use
        // this library, we need to support both versions. The below code is the most sane way we
        // have found to do that: We find one class out of the two candidates that is possible to
        // construct and save a reference to its constructor.
        try {
            snapshotConstructor =
                Class.forName("com.codahale.metrics.Snapshot").getConstructor(Collection.class);
        } catch (final ClassNotFoundException | NoSuchMethodException e) {
            try {
                snapshotConstructor = Class
                    .forName("com.codahale.metrics.UniformSnapshot")
                    .getConstructor(Collection.class);
            } catch (final ClassNotFoundException | NoSuchMethodException e2) {
                throw new RuntimeException(e2);
            }
        }
    }