List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor()
From source file:com.changhong.bigdata.flume.source.dirregex.DirRegexSource.java
/** * @Title: configure//from w w w. j a v a2 s. c o m * @Description: ?flume? * @author YuYue * @param context * @throws */ public void configure(Context context) { logger.info("----------------------DirRegexSource configure..."); try { // monitorDir?monitorFileRegex String strMonitorDir = context.getString("monitorDir"); Preconditions.checkArgument(StringUtils.isNotBlank(strMonitorDir), "Missing Param:'monitorDir'"); String monitorFileRegex = context.getString("monitorFileRegex", DEFAULT_MONITORFILEREGEX); Preconditions.checkArgument(StringUtils.isNotBlank(monitorFileRegex), "Missing Param:'monitorFileRegex'"); monitorFilePattern = Pattern.compile(monitorFileRegex); // checkFile String strCheckFile = context.getString("checkFile"); Preconditions.checkArgument(StringUtils.isNotBlank(strCheckFile), "Missing Param:'checkFile'"); // contentRegex String contentRegex = context.getString("contentRegex"); Preconditions.checkArgument(StringUtils.isNotBlank(contentRegex), "Missing Param:'contentRegex'"); contentPattern = Pattern.compile(contentRegex); // ip ipstr = context.getString("ip"); Preconditions.checkArgument(StringUtils.isNotBlank(ipstr), "Missing Param:'contentRegex'"); // delayTime?charsetName?batchSize delayTime = context.getLong("delayTime", DEFAULT_DELAYTIME); Preconditions.checkArgument(delayTime > 0, "'delayTime' must be greater than 0"); charsetName = context.getString("charsetName", DEFAULT_CHARSETNAME); Preconditions.checkArgument(StringUtils.isNotBlank(charsetName), "Missing Param:'charsetName'"); batchSize = context.getInteger("batchSize", DEFAULT_BATCHSIZE); Preconditions.checkArgument(batchSize > 0, "'batchSize' must be greater than 0"); monitorDir = new File(strMonitorDir); checkFile = new File(strCheckFile); properties = new Properties(); if (!checkFile.exists()) { checkFile.createNewFile(); } else { FileInputStream checkfile001 = new FileInputStream(checkFile); properties.load(checkfile001); checkfile001.close(); } executorService = Executors.newCachedThreadPool(); scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); sourceCounter = new SourceCounter("DirRegexSource"); } catch (Exception e) { // TODO Auto-generated catch block throw new IllegalArgumentException(e); } logger.info("----------------------DirRegexSource configured!"); }
From source file:org.sakaiproject.config.impl.StoredConfigService.java
public void init() { log.info("init()"); node = serverConfigurationService.getServerId(); if (StringUtils.isBlank(node)) { log.error("init(); node cannot be blank, StoredConfigService is disabled"); return;/*from w w w . j a va 2s.co m*/ } // get configured config to skip String[] doNotPersistConfig = serverConfigurationService.getStrings(SAKAI_CONFIG_NEVER_PERSIST); List<String> tmpdoNotPersist; if (doNotPersistConfig == null) { // SCS can return a null here if config is not found tmpdoNotPersist = new ArrayList<String>(); } else { tmpdoNotPersist = Arrays.asList(doNotPersistConfig); } // always add password@org.jasypt.encryption.pbe.PBEStringEncryptor tmpdoNotPersist.add("password@org.jasypt.encryption.pbe.PBEStringEncryptor"); // TODO add more stuff here like serverId, DB password // Setup list of items we should never persist neverPersistItems = Collections.unmodifiableSet(new HashSet<String>(tmpdoNotPersist)); // delete items that should never persisted for (String item : neverPersistItems) { deleteHibernateConfigItem(item); } // enables storing of all config that SCS knows about if (serverConfigurationService.getBoolean(SAKAI_CONFIG_STORE_ENABLE, false)) { learnConfig(serverConfigurationService.getConfigData().getItems()); serverConfigurationService.registerListener(this); } if (serverConfigurationService.getBoolean(SAKAI_CONFIG_POLL_ENABLE, false)) { final int pollDelaySeconds = serverConfigurationService.getInt(SAKAI_CONFIG_POLL_SECONDS, 60); // setup an ExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); // schedule task for every pollDelaySeconds scheduler.scheduleWithFixedDelay(new Runnable() { Date pollDate; @Override public void run() { pollDate = storedConfigPoller(pollDelaySeconds, pollDate); } }, pollDelaySeconds < 120 ? 120 : pollDelaySeconds, // minimally wait 120 seconds for sakai to start pollDelaySeconds, TimeUnit.SECONDS); log.info("init() " + SAKAI_CONFIG_POLL_ENABLE + " is enabled and polling every " + pollDelaySeconds + " seconds"); } }
From source file:org.apereo.openlrs.storage.elasticsearch.XApiOnlyElasticsearchTierTwoStorage.java
@Override public OpenLRSEntity save(OpenLRSEntity entity) { if (entity != null && Statement.OBJECT_KEY.equals(entity.getObjectKey())) { try {/*w w w.ja v a2 s . c o m*/ if (log.isDebugEnabled()) { log.debug("statement to index: {}", entity); } statementQueue.add((Statement) entity); if (executorService == null) { log.debug("Init executorService with rate " + bulkIndexScheduleRateSecond); executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleAtFixedRate(task, 0, bulkIndexScheduleRateSecond, TimeUnit.SECONDS); } } catch (Exception e) { log.error(e.getMessage(), e); //TODO - what else? } } else if (entity != null) { log.warn("XApiOnlyElasticsearchTierTwoStorage does not support " + entity.getObjectKey()); } return entity; }
From source file:org.archive.crawler.framework.ActionDirectory.java
public void start() { if (isRunning()) { return;// www. ja v a 2s . c om } try { // create directories org.archive.util.FileUtils.ensureWriteableDirectory(getActionDir().getFile()); org.archive.util.FileUtils.ensureWriteableDirectory(getDoneDir().getFile()); } catch (IOException e) { throw new IllegalStateException(e); } // start background executor executor = Executors.newSingleThreadScheduledExecutor(); executor.scheduleWithFixedDelay(this, getInitialDelaySeconds(), getDelaySeconds(), TimeUnit.SECONDS); }
From source file:de.msal.shoutemo.connector.GetPostsService.java
/** * *//*from w w w .j a va2 s.c om*/ private void startGetPostsTask() { mAccountManager.getAuthToken(mAccount, LoginActivity.PARAM_AUTHTOKEN_TYPE, null, false, new AccountManagerCallback<Bundle>() { @Override public void run(AccountManagerFuture<Bundle> result) { Bundle bundle; try { bundle = result.getResult(); } catch (OperationCanceledException e) { e.printStackTrace(); return; } catch (AuthenticatorException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } mAuthToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); Log.v(TAG, "Received authentication token=" + mAuthToken); // now get messages! if (worker == null || worker.isShutdown()) { worker = Executors.newSingleThreadScheduledExecutor(); } // fix (possible) wrong time-setting on autemo.com worker.execute(new SetTimezoneTask()); // only now recieve messages (with right time) worker.scheduleAtFixedRate(new GetPostsTask(), 0, INTERVAL, TimeUnit.MILLISECONDS); } }, null); }
From source file:au.com.jwatmuff.eventmanager.gui.main.LoadCompetitionWindow.java
@Override public void setVisible(boolean visible) { if (visible) { success = false;/* ww w. j a va2 s . co m*/ isNew = false; updateLicenseInfo(); checkDatabasesExecutor = Executors.newSingleThreadScheduledExecutor(); checkDatabasesExecutor.scheduleAtFixedRate(checkDatabasesTask, 0, CHECK_DATABASES_PERIOD, TimeUnit.MILLISECONDS); dbManager.setListener(new DatabaseManager.Listener() { @Override public void handleDatabaseManagerEvent() { updateDatabaseList(); } }); } super.setVisible(visible); }
From source file:com.persinity.ndt.datamutator.DataMutator.java
/** * @param configProps//from w w w .j a va 2 s.c o m * @param configSource * @param dbConfigProps * @param dbConfigSource * @param quite */ public DataMutator(final Properties configProps, final String configSource, final Properties dbConfigProps, final String dbConfigSource, final boolean quite) { config = new DataMutatorConfig(configProps, configSource); log.info(config.toString()); try { entityFactory = (EntityFactory) config.getEntityFactoryClass().newInstance(); } catch (Exception e) { throw new RuntimeException(e); } entityPoolUtil = new EntityPoolUtil(new EntityPool(this.config.getRatio()), new RelDbTypeFactory()); entityFactory.init(dbConfigProps, dbConfigSource, entityPoolUtil); loadExecutors = new ArrayList<>(); threads = new ArrayList<>(); Reader consoleReader = null; if (!quite && this.config.getLoadType() == LoadType.TIME && this.config.getLoadQuantity() == -1) { consoleReader = ConsoleView.openConsoleReader(); } transactionDelayInMs = this.config.getTransactionDelayInMs(); dmlsPerTransaction = this.config.getDmlsPerTransaction(); scheduler = Executors.newSingleThreadScheduledExecutor(); runningTime = Stopwatch.createUnstarted(); logStatusTime = Stopwatch.createStarted(); this.quite = quite; view = new ConsoleView(this, consoleReader, quite); view.logMsg(NAME_VERSION); view.logMsg(entityFactory.getConnectionInfo()); log.info("{}", BuildInfo.getInstance()); }
From source file:muvis.Environment.java
private Environment() { //Loading the main configuration ConfigurationFactory factory = new ConfigurationFactory("config.xml"); try {/*from w w w . j a v a 2s .c om*/ configuration = factory.getConfiguration(); } catch (ConfigurationException ex) { System.out.println("Couldn't not load the configuration file! Possible reason: " + ex.toString()); } initializeDataFolders(); //initialize all the elements in the workspace audioPlayer = new MuVisAudioPlayer(); snippetManager = new AudioSnippetPlayerManager(audioPlayer); userPlaylist = new BasePlaylist(); configFile = new Properties(); viewManager = new ViewManager(); desk = new DockingDesktop(); ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new MemoryCollector(), 300, 300, TimeUnit.SECONDS); nbtreesManager = new NBTreeManager(); try { String dataFolder = configuration.getString("muvis.data_folder"); String nbtreeMainFolder = configuration.getString("muvis.nbtree_folder"); String nbtreeFullfolder = dataFolder + Util.getOSEscapeSequence() + nbtreeMainFolder + Util.getOSEscapeSequence(); nbtreesManager.addNBTree(Elements.TRACKS_NBTREE, new NBTree(Elements.TRACKS_NBTREE, nbtreeFullfolder)); nbtreesManager.addNBTree(Elements.ALBUMS_NBTREE, new NBTree(Elements.ALBUMS_NBTREE, nbtreeFullfolder)); nbtreesManager.addNBTree(Elements.ARTISTS_NBTREE, new NBTree(Elements.ARTISTS_NBTREE, nbtreeFullfolder)); } catch (NBTreeException ex) { ex.printStackTrace(); System.out.println("An error occured when trying to initialize the nbtreemanager!"); } initConfigFile(); }
From source file:org.impalaframework.module.monitor.ScheduledModuleChangeMonitor.java
void setDefaultsIfNecessary() { if (fileMonitor == null) { FileMonitorImpl fileMonitor = new FileMonitorImpl(); final List<String> includes = autoReloadFileIncludes != null ? Arrays.asList(autoReloadFileIncludes) : new ArrayList<String>(); final List<String> excludes = autoReloadFileExcludes != null ? Arrays.asList(autoReloadFileExcludes) : new ArrayList<String>(); fileMonitor.setFileFilter(new MonitorFileFilter(includes, excludes)); this.fileMonitor = fileMonitor; }//ww w .j ava 2s .c o m if (executor == null) executor = Executors.newSingleThreadScheduledExecutor(); }
From source file:com.alibaba.jstorm.daemon.nimbus.TopologyMetricsRunnable.java
public TopologyMetricsRunnable(final NimbusData nimbusData) { setName(getClass().getSimpleName()); this.nimbusData = nimbusData; this.localMode = nimbusData.isLocalMode(); if (localMode) { this.metricStat = new AtomicIntegerArray(1); return;//from w w w .jav a 2 s . c o m } LOG.info("create topology metrics runnable."); this.metricCache = nimbusData.getMetricCache(); this.stormClusterState = nimbusData.getStormClusterState(); this.isShutdown = nimbusData.getIsShutdown(); clusterName = ConfigExtension.getClusterName(nimbusData.getConf()); if (clusterName == null) { throw new RuntimeException("cluster.name property must be set in storm.yaml!"); } this.maxPendingUploadMetrics = ConfigExtension.getMaxPendingMetricNum(nimbusData.getConf()); this.metricStat = new AtomicIntegerArray(this.maxPendingUploadMetrics); int cnt = 0; for (int i = 0; i < maxPendingUploadMetrics; i++) { TopologyMetricDataInfo obj = getMetricDataInfoFromCache(i); if (obj != null) { this.metricStat.set(i, SET); cnt++; } } LOG.info("pending upload metrics: {}", cnt); // init alive topologies from zk this.refreshTopologies(); this.refreshTopologiesThread = new AsyncLoopThread(new RefreshTopologiesThread()); this.clusterMetricsUpdateExecutor = Executors.newSingleThreadScheduledExecutor(); this.clusterMetricsUpdateExecutor.scheduleAtFixedRate(new Runnable() { @Override public void run() { int secOffset = TimeUtils.secOffset(); int offset = 55; if (secOffset < offset) { JStormUtils.sleepMs((offset - secOffset) * 1000); } else if (secOffset == offset) { // do nothing } else { JStormUtils.sleepMs((60 - secOffset + offset) * 1000); } LOG.info("cluster metrics force upload."); mergeAndUploadClusterMetrics(); } }, 5, 60, TimeUnit.SECONDS); // track nimbus JVM heap JStormMetrics.registerWorkerGauge(JStormMetrics.NIMBUS_METRIC_KEY, MetricDef.MEMORY_USED, new AsmGauge(new Gauge<Double>() { @Override public Double getValue() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memoryUsage = memoryMXBean.getHeapMemoryUsage(); return (double) memoryUsage.getUsed(); } })); }