List of usage examples for java.lang Thread interrupted
public static boolean interrupted()
From source file:org.apache.hama.monitor.Federator.java
@Override public void run() { try {// w ww . ja v a 2 s . c o m while (!Thread.interrupted()) { Act act = commands.take(); act.handler().handle(workers.submit(new ServiceWorker(act.collector()))); } } catch (InterruptedException ie) { LOG.error(ie); Thread.currentThread().interrupt(); } }
From source file:org.apache.tomee.embedded.TomEEEmbeddedApplicationRunner.java
public static void run(final Object app, final String... args) { final TomEEEmbeddedApplicationRunner runner = new TomEEEmbeddedApplicationRunner(); runner.start(app, args);//from w w w. j a v a 2 s. co m try { new CountDownLatch(1).await(); } catch (final InterruptedException e) { Thread.interrupted(); runner.close(); } }
From source file:com.sinosoft.one.mvc.web.instruction.ViewInstruction.java
@Override public void doRender(Invocation inv) throws Exception { String name = resolvePlaceHolder(this.name, inv); ViewDispatcher viewResolver = getViewDispatcher(inv); String viewPath = getViewPath((InvocationBean) inv, name); if (viewPath != null) { HttpServletRequest request = inv.getRequest(); HttpServletResponse response = inv.getResponse(); ///*from w w w . ja v a 2s.c o m*/ View view = viewResolver.resolveViewName(inv, viewPath, request.getLocale()); if (!Thread.interrupted()) { inv.addModel(MVC_INVOCATION, inv); if (request.getAttribute(MvcConstants.IS_WINDOW_REQUEST) != null) { request.setAttribute(MvcConstants.WINDOW_REQUEST_URI, request.getContextPath() + viewPath); } view.render(inv.getModel().getAttributes(), request, response); } else { logger.info("interrupted"); } } }
From source file:io.s4.latin.adapter.TwitterFeedListener.java
public void run() { long backoffTime = 1000; while (!Thread.interrupted()) { try {//w w w. j av a2s . c o m connectAndRead(); } catch (Exception e) { e.printStackTrace(); Logger.getLogger("s4").error("Exception reading feed", e); try { Thread.sleep(backoffTime); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } backoffTime = backoffTime * 2; if (backoffTime > maxBackoffTime) { backoffTime = maxBackoffTime; } } } }
From source file:org.callimachusproject.io.CarInputStream.java
private ZipArchiveEntry next() throws IOException { if (Thread.interrupted()) throw new InterruptedIOException(); entry = zipStream.getNextZipEntry(); if (entry == null) { entryStream = null;/*from ww w . j a v a 2s .c o m*/ entryMetaType = null; return null; } final ZipArchiveEntry openEntry = entry; entryStream = new LatencyInputStream(new FilterInputStream(zipStream) { public void close() throws IOException { if (openEntry == entry) { entry = null; entryStream = null; entryMetaType = null; } } }, RDFS_PEEK_SIZE); entryType = readEntryType(entry, entryStream); entryMetaType = MetaTypeExtraField.parseExtraField(entry); if (entryMetaType == null) { if (entry.isDirectory()) { entryMetaType = MetaTypeExtraField.FOLDER; } else if (FILE_NAME.matcher(entry.getName()).find()) { entryMetaType = MetaTypeExtraField.FILE; } else if (scanForClass(entryStream, entryType)) { entryMetaType = MetaTypeExtraField.RDFS; } else { entryMetaType = MetaTypeExtraField.RDF; } } return entry; }
From source file:com.serphacker.serposcope.scraper.google.scraper.GoogleScraper.java
public GoogleScrapResult scrap(GoogleScrapSearch search) throws InterruptedException { lastSerpHtml = null;// w ww . j a va 2 s . co m captchas = 0; List<String> urls = new ArrayList<>(); prepareHttpClient(search); long resultsNumber = 0; String referrer = "https://" + buildHost(search) + "/"; for (int page = 0; page < search.getPages(); page++) { if (Thread.interrupted()) { throw new InterruptedException(); } String url = buildRequestUrl(search, page); Status status = null; for (int retry = 0; retry < MAX_RETRY; retry++) { LOG.debug("GET {} via {} try {}", url, http.getProxy() == null ? new DirectNoProxy() : http.getProxy(), retry + 1); status = downloadSerp(url, referrer, search); if (status == Status.OK) { status = parseSerp(urls); if (status == Status.OK) { break; } } if (!isRetryableStatus(status)) { break; } } if (status != Status.OK) { return new GoogleScrapResult(status, urls, captchas); } if (page == 0) { resultsNumber = parseResultsNumberOnFirstPage(); } if (!hasNextPage()) { break; } long pause = search.getRandomPagePauseMS(); if (pause > 0) { try { LOG.trace("sleeping {} milliseconds", pause); Thread.sleep(pause); } catch (InterruptedException ex) { throw ex; } } } return new GoogleScrapResult(Status.OK, urls, captchas, resultsNumber); }
From source file:com.kurento.kmf.jsonrpcconnector.client.JsonRpcClientHttp.java
private void longPooling() { while (true) { try {/* w w w . j a va 2 s . co m*/ Thread.sleep(1000); } catch (InterruptedException e) { log.info("Long polling thread interrupted", e); } if (Thread.interrupted()) { break; } try { JsonElement requestsListJsonObject = this.sendRequest(Request.POLL_METHOD_NAME, rs.getResponseListToSend(), JsonElement.class); log.info("Response from pool: {}", requestsListJsonObject); Type collectionType = new TypeToken<List<Request<JsonElement>>>() { }.getType(); List<Request<JsonElement>> requestList = JsonUtils.fromJson(requestsListJsonObject, collectionType); processServerRequests(requestList); } catch (IOException e) { // TODO Decide what to do in this case. If the net connection is // lost, this will retry indefinitely log.error("Exception when waiting for events (long-pooling). Retry"); } } }
From source file:at.sti2.sparkwave.ServerSocketThread.java
/** * TCP/IP Sparkwave Network Server// w ww . j a va2 s.co m */ public void run() { try { //Open TCP/IP Server socket ServerSocket server = new ServerSocket(configuration.getPort()); logger.info("Server: " + server); while (!Thread.interrupted()) { logger.info("Waiting for connection..."); Socket sock = server.accept(); logger.info("Connected: " + sock); //TODO Not every connection should cause a rebuild of the plugin chain. Should work with arbitrary many connections and failure resistent. re-use plugin threads and parser threads. InputStream socketStreamIn = sock.getInputStream(); // PreProcessing Plugins to be loaded if (configuration.getPPPluginsConfig().size() == 2) { //TODO support arbitrary many plugins // Wiring: socketStreamIn --> (Plugin1) --> PipeOut1 --> PipeIn1 final PipedOutputStream pipeOut1 = new PipedOutputStream(); final PipedInputStream pipeIn1 = new PipedInputStream(pipeOut1); // Wiring: PipeIn1 --> (Plugin2) --> PipeOut2 --> PipeIn2 final PipedOutputStream pipeOut2 = new PipedOutputStream(); final PipedInputStream pipeIn2 = new PipedInputStream(pipeOut2); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); // plugin configuration PPPluginConfig pluginConfig1 = configuration.getPPPluginsConfig().get(0); PreProcess plugin1 = instantiateAndConfigurePlugin(pluginConfig1, socketStreamIn, pipeOut1); PPPluginConfig pluginConfig2 = configuration.getPPPluginsConfig().get(1); PreProcess plugin2 = instantiateAndConfigurePlugin(pluginConfig2, pipeIn1, pipeOut2); // N3 Parser StreamParserThread sparkStreamParserThread = new StreamParserThread(pipeIn2, queues); // kick-off pre-process sparkwaveParserExecutor.execute(plugin1); sparkwaveParserExecutor.execute(plugin2); // kick-off parser sparkwaveParserExecutor.execute(sparkStreamParserThread); } else { StreamParserThread sparkStreamParserThread = new StreamParserThread(socketStreamIn, queues); // kick-off parser sparkwaveParserExecutor.execute(sparkStreamParserThread); } } } catch (Exception e) { logger.error(e.getMessage()); } finally { } }
From source file:de.elomagic.carafile.client.CaraCloud.java
/** * Starts synchronization of the given base path with the registry. * <p/>// w w w . j av a2 s .c o m * This method will block till call method {@link CaraCloud#stop() } * * @throws IOException Thrown when an I/O error occurs * @throws InterruptedException Thrown when method stop was called or application will terminate * @throws GeneralSecurityException */ public void start() throws IOException, InterruptedException, GeneralSecurityException { if (client == null) { throw new IllegalStateException("Attribute \"client\" must be set."); } if (basePath == null) { throw new IllegalStateException("Attribute \"basePath\" must be set."); } if (!Files.exists(basePath)) { throw new IllegalStateException("Path \"" + basePath + "\" must exists."); } if (!Files.isDirectory(basePath)) { throw new IllegalStateException("Path \"" + basePath + "\" must be a directory/folder."); } watcher = FileSystems.getDefault().newWatchService(); registerDefaultWatch(basePath); while (!Thread.interrupted()) { WatchKey key = watcher.take(); for (WatchEvent<?> event : key.pollEvents()) { if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) { Path path = basePath.resolve(event.context().toString()); createFile(path); } else if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) { } else if (event.kind() == StandardWatchEventKinds.ENTRY_DELETE) { Path path = basePath.resolve(event.context().toString()); deleteFile(path); } else { LOG.error("Unsupported kind: " + event.kind() + ", path: " + event.context()); } } key.reset(); } }
From source file:com.googlecode.msidor.springframework.integration.system.ShutdownHandler.java
/** * Handles application shutdown/*from w w w .ja va 2 s. co m*/ */ public void shutdownGently() { long startTimestamp = System.currentTimeMillis(); log.info("Shuting down the application..."); if (componentsToShutDown != null) { Assert.notNull(operationChannel, "Operation channel must be set"); for (String component : componentsToShutDown) { log.info("Sending shutdown command to component: ".concat(component)); Message<String> operation = MessageBuilder.withPayload("@" + component + ".stop()").build(); operationChannel.send(operation); } } if (executorsToWatch != null) { log.info("Checking if all executor threads have been accomplished..."); boolean allDone = true; do { allDone = true; for (ThreadPoolTaskExecutor executor : executorsToWatch) { allDone = allDone && executor.getActiveCount() == 0; } } while (!allDone && !Thread.interrupted() && ((timeout > 0 && System.currentTimeMillis() - startTimestamp < timeout) || timeout <= 0)); if (allDone) log.info("No more active threads"); else log.warn("Some threads are still working"); } okToShutdown = true; if (shutodwnApplication) { System.exit(systemExitCode); } }