List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor()
From source file:gtfsrt.provider.util.GtfsrtProviderImpl.java
/** * The start method automatically starts up a recurring task. *//*w ww . j av a 2 s .c o m*/ @PostConstruct public void start() { _executor = Executors.newSingleThreadScheduledExecutor(); _executor.scheduleAtFixedRate(new RefreshTask(), 0, _refreshInterval, TimeUnit.SECONDS); }
From source file:org.wso2.carbon.registry.ws.client.internal.WSClientServiceComponent.java
protected void activate(ComponentContext context) { RegistryProvider provider = new RegistryProvider() { private WSRegistryServiceClient client = null; private ScheduledExecutorService scheduledExecutor; public Registry getRegistry(String registryURL, String username, String password) throws RegistryException { if (client != null) { return client; }//from w ww. j a v a 2 s . com if (registryURL != null && username != null && password != null) { if (registryURL.endsWith("/")) { registryURL = registryURL.substring(0, registryURL.length() - 1); } String serverURL = registryURL.substring(0, registryURL.indexOf("/registry")) + "/services/"; RegistryUtils.setTrustStoreSystemProperties(); client = new WSRegistryServiceClient(serverURL, username, password, dataHolder.getConfigurationContext()); startExecutor(100000); return client; } throw new RegistryException("Unable to create an instance of a WS Registry"); } private void startExecutor(int timePeriod) { if (scheduledExecutor == null) { scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { client = null; } }, timePeriod, timePeriod, TimeUnit.MILLISECONDS); } } }; Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("type", "ws"); serviceRegistration = context.getBundleContext().registerService(RegistryProvider.class.getName(), provider, ht); if (log.isDebugEnabled()) { log.info("Registry WS Client bundle is activated"); } }
From source file:com.appnexus.opensdk.PBImplementation.java
private static void captureImage(final Context context, final View view, final String auctionInfo) { //Handler was blocking UI thread. ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); scheduledExecutorService.schedule(new Runnable() { @Override//from w w w. ja va 2s . c om public void run() { byte[] imageBytes = BitmapToByte(captureView(view)); Clog.d(Clog.baseLogTag, "PITBULL image size: " + imageBytes.length + " bytes"); sendBroadcast(context, auctionInfo, imageBytes); } }, PB_CAPTURE_DELAY_MS, TimeUnit.MILLISECONDS); }
From source file:org.openvpms.web.echo.servlet.SessionMonitor.java
/** * Constructs an {@link SessionMonitor}. *///from w w w .j a va 2s . c om public SessionMonitor() { executor = Executors.newSingleThreadScheduledExecutor(); log.info("Using default session auto-lock time=" + (autoLock / DateUtils.MILLIS_PER_MINUTE) + " minutes"); log.info("Using default session auto-logout time=" + (autoLogout / DateUtils.MILLIS_PER_MINUTE) + " minutes"); }
From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java
/** * Sets preferences in GAT context and initializes a broker. * * @param configuration//from w w w . j av a2 s .com * @throws URISyntaxException * @throws OctopusException * @throws OctopusIOException */ public OctopusManager(OctopusConfiguration configuration) throws URISyntaxException, OctopusException, OctopusIOException { this.configuration = configuration; Properties props = configuration.getPreferencesAsProperties(); octopus = OctopusFactory.newOctopus(props); URI schedulerURI = configuration.getScheduler(); Credential credential = configuration.getCredential(); // TODO prompt user for password/passphrases scheduler = octopus.jobs().newScheduler(schedulerURI, credential, null); jobs = new ConcurrentHashMap<String, SandboxedJob>(); executor = Executors.newSingleThreadScheduledExecutor(); PollConfiguration pollConf = configuration.getPollConfiguration(); poller = new JobsPoller(jobs, pollConf, octopus); }
From source file:org.apache.lucene.stor.azure.AzureLock.java
@Override public boolean obtain() throws IOException { try {// w w w. j av a2 s. com CloudBlockBlob blob = azureDirectory.getBlobContainer().getBlockBlobReference(lockFile); try { if (IsNullOrEmpty(leaseid)) { leaseid = blob.acquireLease(60, leaseid); // keep the lease alive by renewing every 30 seconds service = Executors.newSingleThreadScheduledExecutor(); service.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { Renew(); } catch (Exception e) { System.err.println("Renew lock failed: " + e.getMessage()); e.printStackTrace(); } } }, 30, 30, TimeUnit.SECONDS); } return !IsNullOrEmpty(leaseid); } catch (StorageException e) { if (handleException(blob, e)) return obtain(); } } catch (URISyntaxException | StorageException e) { throw new IOException("A StorageException occurred. See cause.", e); } return false; }
From source file:org.onebusaway.gtfs_realtime.alerts_producer_demo.GtfsRealtimeProviderImpl.java
/** * The start method automatically starts up a recurring task that periodically * downloads the latest alerts from the SEPTA alerts stream and processes * them./* w w w .j av a2 s . c o m*/ */ @PostConstruct public void start() { _log.info("starting GTFS-realtime service"); _executor = Executors.newSingleThreadScheduledExecutor(); _executor.scheduleAtFixedRate(new AlertRefreshTask(), 0, _refreshInterval, TimeUnit.SECONDS); }
From source file:jp.ksksue.app.terminal.AndroidUSBSerialMonitorLite.java
private void startIrBeaconPulse() { irBeaconExecutor = Executors.newSingleThreadScheduledExecutor(); irBeaconExecutor.scheduleAtFixedRate(timerRunnable, 0, mPlayIntervalSeconds, TimeUnit.SECONDS); btnStop.setEnabled(true);/*from w w w . j a v a2 s. co m*/ btnPlay.setEnabled(false); }
From source file:org.openvpms.hl7.impl.TestPharmacyService.java
/** * Constructs an {@link TestPharmacyService}. * * @param port the port to listen to messages from OpenVPMS on * @param outboundHost the host that OpenVPMS is running on * @param outboundPort the port that OpenVPMS is listening on * @param dispenses the number of dispenses for an order * @param returnAfterDispense if {@code true}, generate a return after a dispense *//*from w w w . j av a 2 s .com*/ public TestPharmacyService(int port, String outboundHost, int outboundPort, int dispenses, boolean returnAfterDispense) { this.outboundHost = outboundHost; this.outboundPort = outboundPort; this.dispenses = dispenses; this.returnAfterDispense = returnAfterDispense; executor = Executors.newSingleThreadScheduledExecutor(); server = new SimpleServer(port); sendContext = HapiContextFactory.create(); server.registerApplication(new ReceivingApplication() { @Override public Message processMessage(Message message, Map<String, Object> metaData) throws ReceivingApplicationException, HL7Exception { return process(message); } @Override public boolean canProcess(Message theMessage) { return true; } }); }
From source file:com.spotify.asyncdatastoreclient.Datastore.java
private Datastore(final DatastoreConfig config) { this.config = config; // TODO implement ning config which doesn't exist on apache http client // .setCompressionEnforced(true) RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(config.getConnectTimeout()) .setConnectionRequestTimeout(config.getRequestTimeout()).build(); client = FiberCloseableHttpAsyncClient.wrap(HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig) .setMaxConnPerRoute(config.getMaxConnections()).setMaxConnTotal(config.getMaxConnections()) .build());//from ww w .ja va 2s . co m client.start(); prefixUri = String.format("%s/datastore/%s/datasets/%s/", config.getHost(), config.getVersion(), config.getDataset()); executor = Executors.newSingleThreadScheduledExecutor(); if (config.getCredential() != null) { // block while retrieving an access token for the first time refreshAccessToken(); // wake up every 10 seconds to check if access token has expired executor.scheduleAtFixedRate(this::refreshAccessToken, 10, 10, TimeUnit.SECONDS); } }