List of usage examples for java.lang InterruptedException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:voldemort.store.readonly.fetcher.HdfsFetcher.java
public static void main(String[] args) throws Exception { if (args.length < 1) Utils.croak("USAGE: java " + HdfsFetcher.class.getName() + " url [keytab location] [kerberos username] [hadoop-config-path]"); String url = args[0];/*from w w w .j a v a2 s .com*/ String keytabLocation = ""; String kerberosUser = ""; String hadoopPath = ""; if (args.length == 4) { keytabLocation = args[1]; kerberosUser = args[2]; hadoopPath = args[3]; } long maxBytesPerSec = 1024 * 1024 * 1024; Path p = new Path(url); final Configuration config = new Configuration(); final URI uri = new URI(url); config.setInt("io.file.buffer.size", VoldemortConfig.DEFAULT_BUFFER_SIZE); config.set("hadoop.rpc.socket.factory.class.ClientProtocol", ConfigurableSocketFactory.class.getName()); config.setInt("io.socket.receive.buffer", 1 * 1024 * 1024 - 10000); FileSystem fs = null; p = new Path(url); HdfsFetcher.keytabPath = keytabLocation; HdfsFetcher.kerberosPrincipal = kerberosUser; boolean isHftpBasedFetch = url.length() > 4 && url.substring(0, 4).equals("hftp"); logger.info("URL : " + url + " and hftp protocol enabled = " + isHftpBasedFetch); if (hadoopPath.length() > 0 && !isHftpBasedFetch) { config.set("hadoop.security.group.mapping", "org.apache.hadoop.security.ShellBasedUnixGroupsMapping"); config.addResource(new Path(hadoopPath + "/core-site.xml")); config.addResource(new Path(hadoopPath + "/hdfs-site.xml")); String security = config.get(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION); if (security == null || !security.equals("kerberos")) { logger.info("Security isn't turned on in the conf: " + CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION + " = " + config.get(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION)); logger.info("Fix that. Exiting."); return; } else { logger.info("Security is turned on in the conf. Trying to authenticate ..."); } } try { // Get the filesystem object if (keytabLocation.length() > 0 && !isHftpBasedFetch) { UserGroupInformation.setConfiguration(config); UserGroupInformation.loginUserFromKeytab(kerberosUser, keytabLocation); final Path path = p; try { logger.debug("I've logged in and am now Doasing as " + UserGroupInformation.getCurrentUser().getUserName()); fs = UserGroupInformation.getCurrentUser().doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws Exception { FileSystem fs = path.getFileSystem(config); return fs; } }); } catch (InterruptedException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error("Got an exception while getting the filesystem object: "); logger.error("Exception class : " + e.getClass()); e.printStackTrace(); for (StackTraceElement et : e.getStackTrace()) { logger.error(et.toString()); } } } else { fs = p.getFileSystem(config); } } catch (IOException e) { e.printStackTrace(); System.err.println("IOException in getting Hadoop filesystem object !!! Exiting !!!"); System.exit(-1); } catch (Throwable te) { te.printStackTrace(); logger.error("Error thrown while trying to get Hadoop filesystem"); System.exit(-1); } FileStatus status = fs.listStatus(p)[0]; long size = status.getLen(); HdfsFetcher fetcher = new HdfsFetcher(null, maxBytesPerSec, VoldemortConfig.REPORTING_INTERVAL_BYTES, VoldemortConfig.DEFAULT_BUFFER_SIZE, 0, keytabLocation, kerberosUser, 5, 5000); long start = System.currentTimeMillis(); File location = fetcher.fetch(url, System.getProperty("java.io.tmpdir") + File.separator + start, hadoopPath); double rate = size * Time.MS_PER_SECOND / (double) (System.currentTimeMillis() - start); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); System.out.println( "Fetch to " + location + " completed: " + nf.format(rate / (1024.0 * 1024.0)) + " MB/sec."); fs.close(); }
From source file:com.sap.prd.mobile.ios.mios.Forker.java
static int forkProcess(final PrintStream out, final File executionDirectory, final String... args) throws IOException { if (out == null) throw new IllegalArgumentException("Print stream for log handling was not provided."); if (args == null || args.length == 0) throw new IllegalArgumentException("No arguments has been provided."); for (final String arg : args) if (arg == null || arg.isEmpty()) throw new IllegalArgumentException( "Invalid argument '" + arg + "' provided with arguments '" + Arrays.asList(args) + "'."); final ProcessBuilder builder = new ProcessBuilder(args); if (executionDirectory != null) builder.directory(executionDirectory); builder.redirectErrorStream(true);// w w w. j av a 2s . c o m InputStream is = null; // // TODO: check if there is any support for forking processes in // maven/plexus // try { final Process process = builder.start(); is = process.getInputStream(); handleLog(is, out); return process.waitFor(); } catch (InterruptedException e) { throw new RuntimeException(e.getClass().getName() + " caught during while waiting for a forked process. This exception is not expected to be caught at that time.", e); } finally { // // Exception raised during close operation below are not reported. // That is actually bad. // We do not have any logging facility here and we cannot throw the // exception since this would swallow any // other exception raised in the try block. // May be we should revisit that ... // IOUtils.closeQuietly(is); } }
From source file:com.clustercontrol.monitor.util.StatusSearchRunUtil.java
@SuppressWarnings("unchecked") public Map<String, ArrayList<ArrayList<Object>>> searchInfo(List<String> managerList, String facilityId, StatusFilterInfo filter) {/*from w w w . j a va 2 s . co m*/ Map<String, ArrayList<ArrayList<Object>>> dispDataMap = new ConcurrentHashMap<>(); Map<String, String> errMsgs = new ConcurrentHashMap<>(); long start = System.currentTimeMillis(); try { String threadName = Thread.currentThread().getName() + "-StatusSearch"; List<StatusSearchTask> searchList = new ArrayList<StatusSearchTask>(); for (String managerName : managerList) { StatusSearchTask task = null; task = new StatusSearchTask(threadName, managerName, facilityId, filter, ContextProvider.getContext()); searchList.add(task); } List<Future<Map<String, List<?>>>> list = getExecutorService().invokeAll(searchList); for (Future<Map<String, List<?>>> future : list) { if (future == null || future.get() == null) { continue; } Map<String, List<?>> map = future.get(); for (Map.Entry<String, List<?>> entry : map.entrySet()) { //?1?? String managerName = entry.getKey(); List<?> ret = entry.getValue(); if (ret.get(POS_INFO) != null && ret.get(POS_INFO) instanceof ArrayList) { ArrayList<ArrayList<Object>> infoList = (ArrayList<ArrayList<Object>>) ret.get(POS_INFO); dispDataMap.put(managerName, infoList); } if (ret.get(POS_ERROR) != null && ret.get(POS_ERROR) instanceof String) { String errList = (String) ret.get(POS_ERROR); errMsgs.put(managerName, errList); } } } } catch (InterruptedException e) { m_log.error(e.getMessage() + e.getClass().getName()); } catch (ExecutionException e) { m_log.error(e.getMessage() + e.getClass().getName()); } // if (0 < errMsgs.size()) { UIManager.showMessageBox(errMsgs, true); } long end = System.currentTimeMillis(); m_log.debug("time=" + (end - start)); return dispDataMap; }
From source file:com.clustercontrol.monitor.util.EventSearchRunUtil.java
public Map<String, ViewListInfo> searchInfo(List<String> managerList, String facilityId, EventFilterInfo filter, int messages) { Map<String, ViewListInfo> dispDataMap = new ConcurrentHashMap<>(); Map<String, String> errMsgs = new ConcurrentHashMap<>(); long start = System.currentTimeMillis(); try {//w w w . j a v a 2 s. c o m String threadName = Thread.currentThread().getName() + "-EventSearch"; List<EventSearchTask> searchList = new ArrayList<EventSearchTask>(); for (String managerName : managerList) { EventSearchTask task = null; task = new EventSearchTask(threadName, managerName, facilityId, filter, messages, ContextProvider.getContext()); searchList.add(task); } List<Future<Map<String, List<?>>>> list = getExecutorService().invokeAll(searchList); for (Future<Map<String, List<?>>> future : list) { if (future == null || future.get() == null) { continue; } Map<String, List<?>> map = future.get(); for (Map.Entry<String, List<?>> entry : map.entrySet()) { //?1?? String managerName = entry.getKey(); List<?> ret = entry.getValue(); if (ret.get(POS_INFO) != null && ret.get(POS_INFO) instanceof ViewListInfo) { ViewListInfo infoList = (ViewListInfo) ret.get(POS_INFO); dispDataMap.put(managerName, infoList); } if (ret.get(POS_ERROR) != null && ret.get(POS_ERROR) instanceof String) { String err = (String) ret.get(POS_ERROR); errMsgs.put(managerName, (String) err); } } } } catch (InterruptedException e) { m_log.error(e.getMessage() + e.getClass().getName()); } catch (ExecutionException e) { m_log.error(e.getMessage() + e.getClass().getName()); } // if (0 < errMsgs.size()) { UIManager.showMessageBox(errMsgs, true); } long end = System.currentTimeMillis(); m_log.debug("time=" + (end - start)); return dispDataMap; }
From source file:pe.chalk.takoyaki.target.Target.java
@Override public void run() { this.getLogger().getParent().info("?? : " + this); while (Takoyaki.getInstance().isAlive() && !this.isInterrupted()) { try {/* ww w .ja v a 2s .c o m*/ Thread.sleep(this.getInterval()); this.collect(this.getDocument()); } catch (InterruptedException e) { return; } catch (Exception e) { this.getLogger().error(e.getClass().getName() + ": " + e.getMessage()); } } }
From source file:org.paxle.se.search.impl.SearchProviderCallable.java
public ISearchResult call() throws Exception { final long start = System.currentTimeMillis(); String providerID = null;/*from w ww. j a va 2 s .c o m*/ AToken query = null; try { // the search query to use query = this.searchRequest.getSearchQuery(); // the provider to use final ISearchProvider provider = (ISearchProvider) this.ctx.getBundleContext() .getService(this.providerRef); // the provider-ID (may be used to fetch additional metadata) providerID = (String) this.providerRef.getProperty(Constants.SERVICE_PID); this.logger.info( "Starting search for '" + query + "' (" + this.searchRequest.getSearchQuery().toString() + ")"); provider.search(this.searchRequest, this.results); } catch (InterruptedException e) { /* just fall through */ } catch (Exception e) { this.logger .error(String.format("Unexpected '%s' while performing a search for '%s' using provider '%s'.", e.getClass().getName(), query, providerID), e); } finally { // context cleanup SearchProviderContext.removeCurrentContext(); } return new SearchResult(providerID, this.results, System.currentTimeMillis() - start); }
From source file:com.amazonaws.services.simpleworkflow.flow.worker.SynchronousRetrier.java
public void retry(Runnable r) { int attempt = 0; long startTime = System.currentTimeMillis(); BackoffThrottler throttler = new BackoffThrottler(retryParameters.getInitialInterval(), retryParameters.getMaximumRetryInterval(), retryParameters.getBackoffCoefficient()); boolean success = false; do {//from www . java2s . c o m try { attempt++; throttler.throttle(); r.run(); success = true; throttler.success(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } catch (RuntimeException e) { throttler.failure(); for (Class<?> exceptionToNotRetry : exceptionsToNotRetry) { if (exceptionToNotRetry.isAssignableFrom(e.getClass())) { throw e; } } long elapsed = System.currentTimeMillis() - startTime; if (attempt > retryParameters.getMaximumRetries() || (elapsed >= retryParameters.getExpirationInterval() && attempt > retryParameters.getMinimumRetries())) { throw e; } log.warn("Retrying after failure", e); } } while (!success); }
From source file:org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerConnection.java
protected void call(HttpRequestBase method) throws ManifoldCFException { CallThread ct = new CallThread(httpClient, method); try {/*from ww w. ja v a 2 s . co m*/ ct.start(); try { ct.finishUp(); if (!checkResultCode(ct.getResultCode())) throw new ManifoldCFException(getResultDescription()); response = ct.getResponse(); } catch (InterruptedException e) { ct.interrupt(); throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED); } } catch (java.net.SocketTimeoutException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException( "SocketTimeoutException while calling " + method.getURI() + ": " + e.getMessage(), e); } catch (InterruptedIOException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED); } catch (HttpException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException("HttpException while calling " + method.getURI() + ": " + e.getMessage(), e); } catch (IOException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException("IOException while calling " + method.getURI() + ": " + e.getMessage(), e); } }
From source file:org.paxle.core.threading.AWorker.java
@Override public void run() { this.running = true; try {//from w ww.jav a2 s. c o m if (this.outQueue == null) throw new IllegalArgumentException("Output-Queue was not set properly."); // The thread keeps running. while (!this.stopped && !this.destroyed && !this.isInterrupted()) { if (this.done) { if (this.myPool != null && !this.myPool.closed()) { synchronized (this) { // return thread back into pool this.myPool.returnWorker(this); // We are waiting for a new task now. if (!this.stopped && !this.destroyed && !this.isInterrupted()) { this.wait(); } } } else { this.stopped = true; } } else { try { // if we are in trigger mode we fetch the next command on our own if (this.command == null && this.inQueue != null) { this.command = this.dequeue(); /* * If the command is null here, then it was rejected by one of the * input-queue filters during dequeueing. */ if (this.command == null) { this.logger.debug("Command was null. Maybe command was consumed by a queue filter"); continue; } } else { // set threadname this.setWorkerName(); } // executing the new Command this.execute(this.command); } finally { // write the modified command object to the out-queue if (this.command != null) this.outQueue.enqueue(this.command); // signal that we have finished execution this.done = true; // free memory this.reset(); // reset threadname this.setWorkerName(); } } } this.logger.debug("Worker thread stopped from outside."); } catch (InterruptedException ex) { this.logger.debug("Worker thread interrupted from outside."); } catch (Throwable ex) { this.logger.error(String.format("Unexpected '%s' while processing command '%s'.", ex.getClass().getName(), this.command), ex); } finally { if (this.myPool != null && !this.destroyed && !this.stopped) this.myPool.invalidateWorker(this); } }
From source file:org.paxle.core.threading.impl.Master.java
@Override public void run() { while (!this.stopped && !Thread.interrupted()) { Data command = null;// www .j a va 2 s . com try { // check if the master was paused synchronized (this) { if (this.paused) this.wait(); } if (!this.triggerMode) { // getting a new command from the queue command = this.inQueue.dequeue(); } else { // just wait for the next command this.inQueue.waitForNext(); } // getting a free worker from pool IWorker<Data> worker = this.pool.getWorker(); if (!this.triggerMode) { // assign the command to the worker worker.assign(command); command = null; } else { // force the worker to fetch the next command worker.trigger(); } this.processedCount++; //add the job to the total job-count and the PPM this.ppm.trick(); // delay if (this.delay > 0) { Thread.sleep(this.delay); } } catch (InterruptedException e) { this.logger.debug("Master thread interrupted from outside."); Thread.interrupted(); this.stopped = true; } catch (Throwable e) { this.logger.error(String.format("Unexpected '%s' while processing command '%s'.", e.getClass().getName(), command), e); } } // consuming the "is interrupted"-flag this.isInterrupted(); // closing the pool try { this.logger.debug("Terminating worker-threads ..."); this.pool.close(); this.logger.debug("Worker-threads terminated."); } catch (Throwable e) { this.logger.error( String.format("Unexpected '%s' while terminating worker-threads.", e.getClass().getName()), e); } }