List of usage examples for java.util Timer cancel
public void cancel()
From source file:org.asimba.util.saml2.metadata.provider.MetadataProviderUtil.java
/** * Create a new HTTP Metadata Provider from the provided URL and HTTP settings<br/> * An exception is thrown when the provider could not be initiated. * /* w w w . j a v a 2 s . c om*/ * @param sMetadataURL * @param sMetadataTimeout * @param oParserPool * @param oMPM * @return * @throws OAException */ public static MetadataProvider newHTTPMetadataProvider(String sId, String sMetadataURL, int iTimeout, ParserPool oParserPool, IMetadataProviderManager oMPM) throws OAException { MetadataProvider oProvider = null; // Check URL format URL oURLTarget = null; try { oURLTarget = new URL(sMetadataURL); } catch (MalformedURLException e) { _oLogger.error("Invalid url for metadata: " + sMetadataURL, e); throw new OAException(SystemErrors.ERROR_INTERNAL); } // Check valid and existing destination (with configured timeout settings) try { URLConnection oURLConnection = oURLTarget.openConnection(); if (iTimeout <= 0) { oURLConnection.setConnectTimeout(3000); oURLConnection.setReadTimeout(3000); } else { oURLConnection.setConnectTimeout(iTimeout); oURLConnection.setReadTimeout(iTimeout); } oURLConnection.connect(); } catch (IOException e) { _oLogger.warn("Could not connect to metadata url: " + sMetadataURL + "(using timout " + (iTimeout == 0 ? "3000" : iTimeout) + "ms)", e); } // Establish dedicated refresh timer: String sTimername = "Metadata_HTTP-" + (oMPM == null ? "" : oMPM.getId() + "-") + sId + "-Timer"; Timer oRefreshTimer = new Timer(sTimername, true); // Establish HttpClient HttpClient oHttpClient = new HttpClient(); if (iTimeout > 0) { // Set configured Timeout settings oHttpClient.getParams().setSoTimeout(iTimeout); } oProvider = MetadataProviderUtil.createProviderForURL(sMetadataURL, oParserPool, oRefreshTimer, oHttpClient); if (oProvider != null) { // Start managing it: if (oMPM != null) { oMPM.setProviderFor(sId, oProvider, oRefreshTimer); } } else { // Unsuccessful creation; clean up created Timer oRefreshTimer.cancel(); } return oProvider; }
From source file:xbird.engine.sched.Scheduler.java
private final void execute(final RequestContext rc, final ScheduledEventListener listener, final long timeout) { if (timeout <= 0) { throw new IllegalArgumentException("Illegal timeout value: " + timeout); }/* w ww . ja va2 s .c om*/ final Request request = rc.getRequest(); final TimerTask cancel = new TimerTask() { public void run() { try { listener.cancel(rc); } catch (RemoteException e) { LOG.warn("canceling task is failed: " + request.getIdentifier(), e); } } }; final Timer timer = new Timer("SchedTimeout"); timer.schedule(cancel, timeout); execute(rc, listener); timer.cancel(); }
From source file:org.apache.ftpserver.ConnectionManagerImpl.java
/** * Dispose connections//from w ww . j ava 2 s.c o m */ public void dispose() { // stop timer Timer timer = m_timer; if (timer != null) { timer.cancel(); m_timer = null; } // close all connections List cons = m_conList; if (cons != null) { closeAllConnections(); m_conList = null; } }
From source file:org.sipfoundry.sipxconfig.admin.BackupPlan.java
public void resetTimer(String binDirectory) { Timer timer = getTimer(); if (timer != null) { timer.cancel(); }/*www. j av a2 s. c o m*/ timer = new Timer(false); // daemon, dies with main thread setTimer(timer); schedule(timer, binDirectory); }
From source file:de.xirp.io.comm.lowlevel.AbstractStreamCommunicationInterface.java
/** * Stops the periodic sending for the given tasks name. * //w ww .j a v a 2 s.c o m * @param name * the name of the task to stop * @return <code>true</code> if the task was found and stopped, * <code>false</code> otherwise */ public boolean stopSendPeriodically(String name) { Timer timer = periodicSenders.get(name); if (timer != null) { timer.cancel(); periodicSenders.remove(name); return true; } return false; }
From source file:org.punksearch.crawler.NetworkCrawler.java
private void cancelTimers() { for (Timer timer : timers) { timer.cancel(); } timers.clear(); }
From source file:pl.openrnd.connection.rest.ConnectionHandler.java
private void stopRequestTimer(Timer timer) { if (timer == null) { return;/*from w ww. jav a 2s.c om*/ } timer.purge(); timer.cancel(); }
From source file:deincraftlauncher.IO.download.FTPDownloader.java
private void update() { System.out.println("downloader update #" + updateNum); updateNum++;/*from w w w . j a va 2 s . c om*/ if (finished) { System.out.println("cancelling updating"); return; } onUpdate.call(totalProgress, totalSize, this); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { //periodic update timer.cancel(); timer.purge(); update(); } }, updateDelay); }
From source file:org.sonar.server.benchmark.SourceIndexBenchmarkTest.java
private void benchmarkIndexing() { LOGGER.info("Indexing source lines"); SourceIterator files = new SourceIterator(FILES, LINES_PER_FILE); ProgressTask progressTask = new ProgressTask(LOGGER, "files of " + LINES_PER_FILE + " lines", files.count());/*from w w w .j a v a2 s.com*/ Timer timer = new Timer("SourceIndexer"); timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS); long start = System.currentTimeMillis(); tester.get(SourceLineIndexer.class).index(files); long end = System.currentTimeMillis(); timer.cancel(); long period = end - start; long nbLines = files.count.get() * LINES_PER_FILE; long throughputPerSecond = 1000L * nbLines / period; LOGGER.info( String.format("%d lines indexed in %d ms (%d docs/second)", nbLines, period, throughputPerSecond)); benchmark.expectBetween("Throughput to index source lines", throughputPerSecond, 6000L, 6400L); // be sure that physical files do not evolve during estimation of size tester.get(EsClient.class).prepareOptimize(SourceLineIndexDefinition.INDEX).get(); long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()); LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize))); benchmark.expectBetween("ES dir size (b)", dirSize, 103L * FileUtils.ONE_MB, 109L * FileUtils.ONE_MB); }
From source file:org.sonar.server.benchmark.IssueIndexBenchmarkTest.java
private void benchmarkIssueIndexing() { LOGGER.info("Indexing issues"); IssueIterator issues = new IssueIterator(PROJECTS, FILES_PER_PROJECT, ISSUES_PER_FILE); ProgressTask progressTask = new ProgressTask(LOGGER, "issues", issues.count()); Timer timer = new Timer("IssuesIndex"); timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS); long start = System.currentTimeMillis(); tester.get(IssueIndexer.class).index(issues); timer.cancel(); long period = System.currentTimeMillis() - start; long throughputPerSecond = 1000 * issues.count.get() / period; LOGGER.info(String.format("%d issues indexed in %d ms (%d docs/second)", issues.count.get(), period, throughputPerSecond));//w ww . j a va 2 s .c o m benchmark.expectAround("Throughput to index issues", throughputPerSecond, 6500, Benchmark.DEFAULT_ERROR_MARGIN_PERCENTS); // be sure that physical files do not evolve during estimation of size tester.get(EsClient.class).prepareOptimize("issues").get(); long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()); LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize))); benchmark.expectBetween("ES dir size (b)", dirSize, 200L * FileUtils.ONE_MB, 420L * FileUtils.ONE_MB); }