List of usage examples for org.joda.time DateTimeZone setDefault
public static void setDefault(DateTimeZone zone) throws SecurityException
From source file:com.serotonin.m2m2.Lifecycle.java
public synchronized void initialize(ClassLoader classLoader) { for (Module module : ModuleRegistry.getModules()) { module.preInitialize();//from w ww. ja va 2 s. c o m } String tzId = Common.envProps.getString("timezone"); if (!StringUtils.isEmpty(tzId)) { TimeZone tz = TimeZone.getTimeZone(tzId); if ((tz == null) || (!tz.getID().equals(tzId))) throw new RuntimeException("Time zone id '" + tzId + "' in env properties is not valid"); this.LOG.info("Setting default time zone to " + tz.getID()); TimeZone.setDefault(tz); DateTimeZone.setDefault(DateTimeZone.forID(tzId)); } Common.timer.init(new ThreadPoolExecutor(0, 1000, 30L, TimeUnit.SECONDS, new SynchronousQueue())); Providers.add(TimerProvider.class, new TimerProvider() { public AbstractTimer getTimer() { return Common.timer; } }); Common.JSON_CONTEXT.addResolver(new EventTypeResolver(), new Class[] { EventType.class }); Common.JSON_CONTEXT.addResolver(new BaseChartRenderer.Resolver(), new Class[] { ChartRenderer.class }); Common.JSON_CONTEXT.addResolver(new BaseTextRenderer.Resolver(), new Class[] { TextRenderer.class }); Common.JSON_CONTEXT.addResolver(new EmailRecipientResolver(), new Class[] { EmailRecipient.class }); Providers.add(InputStreamEPollProvider.class, new InputStreamEPollProviderImpl()); Providers.add(ProcessEPollProvider.class, new ProcessEPollProviderImpl()); // lic(); freemarkerInitialize(); databaseInitialize(classLoader); for (Module module : ModuleRegistry.getModules()) { module.postDatabase(); } utilitiesInitialize(); eventManagerInitialize(); runtimeManagerInitialize(); maintenanceInitialize(); imageSetInitialize(); webServerInitialize(classLoader); for (Module module : ModuleRegistry.getModules()) { module.postInitialize(); } SystemEventType.raiseEvent(new SystemEventType("SYSTEM_STARTUP"), System.currentTimeMillis(), false, new TranslatableMessage("event.system.startup")); for (Runnable task : this.STARTUP_TASKS) Common.timer.execute(task); }
From source file:com.spotify.reaper.ReaperApplication.java
License:Apache License
@Override public void run(ReaperApplicationConfiguration config, Environment environment) throws Exception { // Using UTC times everywhere as default. Affects only Yoda time. DateTimeZone.setDefault(DateTimeZone.UTC); checkConfiguration(config);/*w ww . j ava 2 s. com*/ context.config = config; addSignalHandlers(); // SIGHUP, etc. LOG.info("initializing runner thread pool with {} threads", config.getRepairRunThreadCount()); context.repairManager = new RepairManager(); context.repairManager.initializeThreadPool(config.getRepairRunThreadCount(), config.getHangingRepairTimeoutMins(), TimeUnit.MINUTES, 30, TimeUnit.SECONDS); if (context.storage == null) { LOG.info("initializing storage of type: {}", config.getStorageType()); context.storage = initializeStorage(config, environment); } else { LOG.info("storage already given in context, not initializing a new one"); } if (context.jmxConnectionFactory == null) { LOG.info("no JMX connection factory given in context, creating default"); context.jmxConnectionFactory = new JmxConnectionFactory(); } // read jmx host/port mapping from config and provide to jmx con.factory Map<String, Integer> jmxPorts = config.getJmxPorts(); if (jmxPorts != null) { LOG.debug("using JMX ports mapping: " + jmxPorts); context.jmxConnectionFactory.setJmxPorts(jmxPorts); } // Enable cross-origin requests for using external GUI applications. if (config.isEnableCrossOrigin() || System.getProperty("enableCrossOrigin") != null) { final FilterRegistration.Dynamic cors = environment.servlets().addFilter("crossOriginRequests", CrossOriginFilter.class); cors.setInitParameter("allowedOrigins", "*"); cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin"); cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD"); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); } JmxCredentials jmxAuth = config.getJmxAuth(); if (jmxAuth != null) { LOG.debug("using specified JMX credentials for authentication"); context.jmxConnectionFactory.setJmxAuth(jmxAuth); } LOG.info("creating and registering health checks"); // Notice that health checks are registered under the admin application on /healthcheck final ReaperHealthCheck healthCheck = new ReaperHealthCheck(context); environment.healthChecks().register("reaper", healthCheck); environment.jersey().register(healthCheck); LOG.info("creating resources and registering endpoints"); final PingResource pingResource = new PingResource(); environment.jersey().register(pingResource); final ClusterResource addClusterResource = new ClusterResource(context); environment.jersey().register(addClusterResource); final RepairRunResource addRepairRunResource = new RepairRunResource(context); environment.jersey().register(addRepairRunResource); final RepairScheduleResource addRepairScheduleResource = new RepairScheduleResource(context); environment.jersey().register(addRepairScheduleResource); Thread.sleep(1000); SchedulingManager.start(context); LOG.info("resuming pending repair runs"); context.repairManager.resumeRunningRepairRuns(context); }
From source file:com.yahoo.bard.webservice.application.JerseyTestBinder.java
License:Apache License
/** * Constructor with more control over auto-start and the application state it uses. * * @param doStart Will auto-start test harness after constructing if true, must be manually started if false. * @param state Application state to load for testing * @param resourceClasses Resource classes for Jersey to load */// www. j a v a 2 s . com public JerseyTestBinder(boolean doStart, ApplicationState state, Class<?>... resourceClasses) { this.state = state; //Initializing the Sketch field converter FieldConverterSupplier.sketchConverter = initializeSketchConverter(); //Initialize the metrics filter helper FieldConverterSupplier.metricsFilterSetBuilder = initializeMetricsFilterSetBuilder(); // Set up the web services buildWebServices(); // Pin the default timezone to UTC so that we use the same timezone no matter where tests run previousDateTimeZone = DateTimeZone.getDefault(); DateTimeZone.setDefault(DateTimeZone.UTC); // Fill in the binder factory testBinderFactory = buildBinderFactory(getDimensionConfiguration(), getMetricLoader(), getTableLoader(), state); this.binder = (AbstractBinder) (testBinderFactory.buildBinder()); // Configure and register the resources this.config = new ResourceConfig(); // Order matters. First check if BardLoggingFilter is requested boolean skipWrapper = false; for (Class<?> cls : resourceClasses) { if (cls.getSimpleName().equals(BardLoggingFilter.class.getSimpleName())) { skipWrapper = true; } } // If BardLoggingFilter is not requested, use a wrapper instead to enable logging of the information that is // potentially recorded in the resources that are registered if (skipWrapper) { this.config.registerClasses(resourceClasses); } else { this.config.register(getLoggingFilter(), 1); // Now register the requested classes for (Class<?> cls : resourceClasses) { this.config.register(cls, 5); } } this.config .register(new InstrumentedResourceMethodApplicationListener(MetricRegistryFactory.getRegistry())); this.config.register(this.binder); registerMetricsAppender(); // Create and set up the test harness this.harness = new JerseyTest() { @Override protected Application configure() { // Find first available port. forceSet(TestProperties.CONTAINER_PORT, RANDOM_PORT); return config; } }; if (doStart) { start(); } }
From source file:com.yahoo.bard.webservice.application.JerseyTestBinder.java
License:Apache License
/** * Tear down the test harness and unload the binder. * * @throws Exception if there's a problem tearing things down *//*w w w. ja v a2 s. c o m*/ public void tearDown() throws Exception { // Reset the default timezone to what it was before the JTB was created DateTimeZone.setDefault(previousDateTimeZone); getHarness().tearDown(); DimensionDictionary dictionary = configurationLoader.getDimensionDictionary(); Set<Dimension> dimensions = dictionary.findAll(); List<Throwable> caughtExceptions = Collections.emptyList(); for (Dimension dimension : dimensions) { if (dimension instanceof KeyValueStoreDimension) { KeyValueStoreDimension kvDimension = (KeyValueStoreDimension) dimension; try { kvDimension.deleteAllDimensionRows(); } catch (Exception e) { caughtExceptions.add(e); String msg = String.format("Unable to delete all DimensionRows for %s", dimension.getApiName()); LOG.error(msg, e); } } } state.cache.clear(); testBinderFactory.shutdownLoaderScheduler(); if (!caughtExceptions.isEmpty()) { // Throw what we caught last so that we don't lose it. throw new MultiException(caughtExceptions); } getDimensionConfiguration().stream().map(DimensionConfig::getSearchProvider) .forEach(SearchProvider::clearDimension); }
From source file:com.yahoo.bard.webservice.data.config.ConfigurationLoader.java
License:Apache License
/** * Constructor.//from w w w.ja va2s . co m * * @param dimensionLoader DimensionLoader to load dimensions from * @param metricLoader MetricLoader to load metrics from * @param tableLoader TableLoader to load tables from */ @Inject public ConfigurationLoader(DimensionLoader dimensionLoader, MetricLoader metricLoader, TableLoader tableLoader) { DateTimeZone.setDefault(DateTimeZone.forID(TIMEZONE)); // Set the max lucene query clauses as high as it can go BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); this.dimensionLoader = dimensionLoader; this.metricLoader = metricLoader; this.tableLoader = tableLoader; }
From source file:de.escidoc.bwelabs.depositor.service.SessionManager.java
License:Open Source License
/** * Method checks if the monitoring time of a provided configuration is over. * //from w w w.j a va 2 s . com * @param configuration * @return */ private static boolean isMonitoringTimeOver(Properties configuration) { String monitoringStartTime = configuration.getProperty(Constants.PROPERTY_MONITORING_START_TIME); if (monitoringStartTime == null) { return false; } DateTimeZone.setDefault(DateTimeZone.UTC); DateTime startTime = new DateTime(monitoringStartTime); String monitoringDuration = configuration.getProperty(Constants.PROPERTY_TIME_MONITORING_DURATION); int monitoringDurationMinutes = Integer.parseInt(monitoringDuration); DateTime endTime = startTime.plusMinutes(monitoringDurationMinutes); return endTime.isBeforeNow(); }
From source file:de.escidoc.bwelabs.depositor.service.SessionManager.java
License:Open Source License
/** * Method creates a new configuration directory for a provided configuration with a currently time stamp as a name * and save a configuration file within it. * /*from ww w. j a va 2 s .co m*/ * @param configuration * @param configurationId * @return File with a created configuration directory. * @throws DepositorException */ public File saveInLocalFileSystem(Properties configuration) throws DepositorException { LOG.debug("saving configuration in local file system"); DateTimeZone.setDefault(DateTimeZone.UTC); DateTime currentTime = new DateTime(); DateTimeFormatter fmt = DateTimeFormat.forPattern(PATH_FORMAT); String configurationDirectoryName = currentTime.toString(fmt); File configurationDirectory = new File(baseDir, configurationDirectoryName); configurationDirectory.mkdirs(); File configurationFile = new File(configurationDirectory, Constants.CONFIGURATION_FILE_NAME); FileOutputStream os = null; try { os = new FileOutputStream(configurationFile); } catch (FileNotFoundException e) { LOG.error(e.getMessage()); throw new DepositorException(e.getMessage()); } try { configuration.storeToXML(os, null); os.flush(); os.close(); synchronized (configurationDirPathes) { configurationDirPathes.put(configuration.getProperty(Configuration.PROPERTY_CONFIGURATION_ID), configurationDirectoryName); } } catch (IOException e) { LOG.error(e.getMessage()); throw new DepositorException(e.getMessage()); } return configurationFile; }
From source file:de.escidoc.bwelabs.depositor.service.SessionManager.java
License:Open Source License
/** * Method checks if a configuration with a provided id contains a property Monitoring Start Time. It put a time * stamp with a current time into a configuration contained in a map with configurations and in a configuration * file./*from w w w .java2 s . com*/ * * @deprecated Monitoring start time should not be needed in configuration. * @param configId */ @Deprecated private void putMonitoringStartTimeIntoConfigurationIfMissing(String configId) { File configurationDirectory = new File(baseDir, configurationDirPathes.get(configId)); Properties configuration = null; // if a configuration does not contain a calculated monitoring start // time, // put a calculated monitoring start time in to the configuration and // store the // configuration into a configuration file synchronized (configurations) { configuration = configurations.get(configId); String monitoringStartTime = configuration.getProperty(Constants.PROPERTY_MONITORING_START_TIME); if (monitoringStartTime == null) { DateTimeZone.setDefault(DateTimeZone.UTC); DateTime currentTime = new DateTime(); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_TIME_FORMAT); String timeStamp = currentTime.toString(fmt); configuration.put(Constants.PROPERTY_MONITORING_START_TIME, timeStamp); File configurationFile = new File(configurationDirectory, Constants.CONFIGURATION_FILE_NAME); configurationFile.delete(); FileOutputStream os = null; try { os = new FileOutputStream(configurationFile); } catch (FileNotFoundException e) { LOG.error(e.getMessage()); } try { configuration.storeToXML(os, null); if (os != null) { os.flush(); os.close(); } } catch (IOException e) { LOG.error(e.getMessage()); } } } }
From source file:de.fatalix.book.importer.Main.java
License:Open Source License
public static void main(String[] args) throws IOException, SolrServerException { //parseDateTime(); // try { // // // //BookExporterOld.exportBooks("http://jboss.fatalix.de/solr-4.10.4", "bookery", 20, "E:\\dumps\\bookery-web"); // //BookMigrator.exportBooks("http://jboss.fatalix.de/solr-4.10.4", "bookery", 20, "E:\\dumps\\bookery-web"); DateTimeZone.setDefault(DateTimeZone.UTC); //BookMigrator.clearDB("http://localhost:8080/solr-4.10.4", "bookery"); //List<File> bookFolder = BookMigrator.findAllBooks("E:\\import\\prepared-books"); //BookMigrator.filterBooks(bookFolder, new File("E:\\import\\fabian-incomplete")); //BookMigrator.importBooks("http://localhost:8080/solr-4.10.4", "bookery", 20, bookFolder,true); //ThumbnailConvert.createThumbnailForBook("http://localhost:8080/solr-4.10.3", "bookery", "1377ce69-ab5c-40d1-a47c-c71aae8eeace"); // ThumbnailConvert.createThumbnails("http://localhost:8080/solr-4.10.3", "bookery", 20); // //BookMigrator.exportBooks("http://jboss.fatalix.de/solr-4.10.4", "bookery", 40, "C:\\server\\bookery-backup"); // BookMigrator.importBooks("http://localhost:8080/solr-4.10.4", "bookery", 10, "E:\\dumps\\bookery-web"); // // } catch(SolrServerException | IOException ex) { // Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); // }/*from w w w .ja v a 2 s . c om*/ }
From source file:de.fatalix.bookery.bl.background.importer.CalibriImporter.java
License:Open Source License
@Override public void executeJob(Timer timer) { logger.debug("Starting batch job..."); DateTimeZone.setDefault(DateTimeZone.UTC); BatchJobConfiguration jobConfig = (BatchJobConfiguration) timer.getInfo(); Gson gson = new Gson(); CalibriImporterConfiguration config = gson.fromJson(jobConfig.getConfigurationXML(), CalibriImporterConfiguration.class); File importFolder = new File(config.getImportFolder()); if (importFolder.isDirectory()) { File[] zipFiles = importFolder.listFiles(new FilenameFilter() { @Override//w w w . j a v a2 s . c o m public boolean accept(File dir, String name) { return name.endsWith(".zip"); } }); for (File zipFile : zipFiles) { try { processArchive(zipFile.toPath(), config.getBatchSize()); logger.info("Processed file " + zipFile.getName()); } catch (IOException ex) { logger.error("Cannot process " + zipFile.getName(), ex); } } } else { logger.error("Import folder: " + importFolder.getAbsolutePath() + " cannot be read!"); } }