All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deeplearning4j.spark.time.TimeSourceProvider Maven / Gradle / Ivy

There is a newer version: 1.0.0-beta_spark_2
Show newest version
package org.deeplearning4j.spark.time;

import java.lang.reflect.Method;

/**
 * TimeSourceProvider: used to get a TimeSource via a static method.
* Defaults to the Network Time Protocol implementation {@link NTPTimeSource}, but can be switched to other implementations * via the {@link TimeSourceProvider#TIMESOURCE_CLASSNAME_PROPERTY} system property. * * @author Alex Black */ public class TimeSourceProvider { /** * Default class to use when getting a TimeSource instance */ public static final String DEFAULT_TIMESOURCE_CLASS_NAME = NTPTimeSource.class.getName(); /** * Name of the system property to set if the TimeSource type/class is to be customized */ public static final String TIMESOURCE_CLASSNAME_PROPERTY = "org.deeplearning4j.spark.time.TimeSource"; private TimeSourceProvider() { } /** * Get a TimeSource * the default TimeSource instance (default: {@link NTPTimeSource} * * @return TimeSource */ public static TimeSource getInstance() { String className = System.getProperty(TIMESOURCE_CLASSNAME_PROPERTY, DEFAULT_TIMESOURCE_CLASS_NAME); return getInstance(className); } /** * Get a specific TimeSource by class name * * @param className Class name of the TimeSource to return the instance for * @return TimeSource instance */ public static TimeSource getInstance(String className) { try { Class c = Class.forName(className); Method m = c.getMethod("getInstance"); return (TimeSource) m.invoke(null); } catch (Exception e) { throw new RuntimeException("Error getting TimeSource instance for class \"" + className + "\"", e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy