List of usage examples for java.lang InterruptedException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.clustercontrol.jobmanagement.factory.JobSessionNodeImpl.java
private boolean retryJob(JobSessionNodeEntity sessionNode, JobSessionJobEntity sessionJob, RunResultInfo info, int maxRetry) { if (sessionNode.getStatus() != StatusConstant.TYPE_RUNNING) { return false; }//w ww. j a v a 2 s . com if (sessionJob.getStatus() == StatusConstant.TYPE_SUSPEND) { setMessage(sessionNode, MessageConstant.SUSPEND.getMessage()); sessionNode.setStatus(StatusConstant.TYPE_WAIT); sessionNode.setStartDate(null); return false; } else if (sessionJob.getStatus() != StatusConstant.TYPE_RUNNING) { return false; } // int errorCount = sessionNode.getErrorRetryCount(); m_log.debug("maxRetry:" + maxRetry + " errorCount:" + errorCount + " " + (maxRetry > errorCount) + ", " + sessionNode.getId()); if (maxRetry > errorCount) { //???? int jobRetryInterval = HinemosPropertyUtil .getHinemosPropertyNum("job.retry.interval", Long.valueOf(10 * 1000)).intValue(); try { Thread.sleep(jobRetryInterval); } catch (InterruptedException e) { m_log.warn("retryJob() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); return false; } //?????????? // errorCount++; m_log.debug("errRtryCnt++=" + errorCount); //DB String msg = info.getMessage() + info.getErrorMessage(); setMessage(sessionNode, msg); setMessage(sessionNode, MessageConstant.RETRYING.getMessage() + "(" + errorCount + ")"); sessionNode.setErrorRetryCount(errorCount); sessionNode.setStatus(StatusConstant.TYPE_WAIT); sessionNode.setStartDate(null); //? if (checkMultiplicity(sessionNode)) { JpaTransactionManager jtm = new JpaTransactionManager(); jtm.addCallback(new FromRunningAfterCommitCallback(sessionNode.getId())); jtm.addCallback(new ToRunningAfterCommitCallback(sessionNode.getId())); return true; } } return false; }
From source file:com.clustercontrol.ping.util.ReachAddress.java
/** * ????????????/*from ww w . j av a 2 s. c om*/ * * @param addressText * @return PING */ private boolean isReachable(String addressText) { m_message = null; m_messageOrg = null; m_lost = 0; m_average = 0; try { long max = 0; long min = 0; long sum = 0; int num = 0; long start = 0; long end = 0; // StringBuffer buffer = new StringBuffer(); InetAddress address = InetAddress.getByName(addressText); buffer.append("Pinging " + address.getHostName() + " [" + address.getHostAddress() + "].\n\n"); int i = 0; for (; i < m_sentCount; i++) { // Reachability ?? ICMP ?? boolean isReachable; // isReachable????????? synchronized (m_syncObj) { start = HinemosTime.currentTimeMillis(); isReachable = address.isReachable(m_timeout); end = HinemosTime.currentTimeMillis(); } long time = end - start; if (isReachable) { buffer.append("Reply from " + address.getHostAddress() + ": "); sum += time; if (i == 0) { max = time; min = time; } else { if (time > max) { max = time; } else if (time < min) { min = time; } } num++; if (time > 0) { buffer.append("time=" + time + "ms\n"); } else { buffer.append("time<1ms\n"); } } else { if (time >= m_timeout) { buffer.append("Request timed out.\n"); } else { buffer.append( "Reply from " + address.getHostAddress() + ": Destination net unreachable.\n"); // num++; } } if (i < m_sentCount - 1) { try { Thread.sleep(m_sentInterval); } catch (InterruptedException e) { break; } } } buffer.append("\nPing statistics for " + address.getHostAddress() + ":\n"); // if (num == 0) { m_lost = 100; } else { m_lost = (i - num) * 100 / i; } // m_message = "Packets: Sent = " + i + ", Received = " + num + ", Lost = " + (i - num) + " (" + m_lost + "% loss),"; buffer.append("\t" + m_message + "\n"); buffer.append("Approximate round trip times in milli-seconds:\n"); // ? if (num != 0) { m_average = sum / num; } else { m_average = 0; } buffer.append("\tMinimum = " + min + "ms, Maximum = " + max + "ms, Average = " + m_average + "ms\n"); m_messageOrg = buffer.toString(); return true; } catch (UnknownHostException e) { m_log.warn("isReachable() " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + e.getClass().getSimpleName() + ", " + e.getMessage(), e); m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + " (" + e.getMessage() + ")"; } catch (IOException e) { m_log.warn("isReachable() " + MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + e.getClass().getSimpleName() + ", " + e.getMessage(), e); m_message = MessageConstant.MESSAGE_FAIL_TO_EXECUTE_PING.getMessage() + " (" + e.getMessage() + ")"; } return false; }
From source file:com.jgoetsch.eventtrader.source.HttpPollingMsgSource.java
public void receiveMsgs(HttpClient client) { NewMsgHandler msgHandler = new NewMsgHandler(); HttpUriRequest req = createRequest(); for (;;) {//from ww w . j a va 2 s. c om HttpEntity entity = null; try { if (isUseIfModifiedSince() && lastModifiedDate != null) req.setHeader("If-Modified-Since", lastModifiedDate); long startTime = System.currentTimeMillis(); HttpResponse rsp = client.execute(req); if (rsp.containsHeader("Last-Modified")) { lastModifiedDate = rsp.getFirstHeader("Last-Modified").getValue(); //log.debug("Resource last modified: " + lastModifiedDate); } entity = rsp.getEntity(); if (rsp.getStatusLine().getStatusCode() >= 400) { log.warn("HTTP request to " + req.getURI().getHost() + " failed [" + rsp.getStatusLine().getStatusCode() + " " + rsp.getStatusLine().getReasonPhrase() + ", " + (System.currentTimeMillis() - startTime) + " ms]"); // 400 level error should be unrecoverable so just quit out if (rsp.getStatusLine().getStatusCode() < 500) return; else { // give server some more time to recover before retrying if it returned 500 level error // probably means site crashed and continuing to hit it will only make things worse try { Thread.sleep(pollingInterval * 6); } catch (InterruptedException e) { } } } else { boolean bContinue = true; if (entity != null && rsp.getStatusLine().getStatusCode() != 304) { // 304 = not modified bContinue = getMsgParser().parseContent(entity.getContent(), entity.getContentLength(), entity.getContentType() == null ? null : entity.getContentType().getValue(), msgHandler); msgHandler.nextPass(); } if (log.isDebugEnabled()) { log.debug( "Checked site at " + req.getURI().getHost() + " [" + rsp.getStatusLine().getStatusCode() + " " + rsp.getStatusLine().getReasonPhrase() + ", " + (entity != null ? (entity.getContentLength() != -1 ? entity.getContentLength() + " bytes, " : "unknown length, ") : "") + (System.currentTimeMillis() - startTime) + " ms]"); } if (!bContinue) return; } } catch (IOException e) { log.warn(e.getClass() + ": " + e.getMessage()); } catch (Exception e) { log.warn(e.getClass() + ": " + e.getMessage(), e); } finally { if (entity != null) { // release connection gracefully try { entity.consumeContent(); } catch (IOException e) { } } } delay(); } }
From source file:ch.ksfx.web.services.spidering.http.HttpClientHelper.java
private HttpMethod executeMethod(HttpMethod httpMethod) { for (Header header : this.headers.getHeaders()) { httpMethod.setRequestHeader(header); }/*w ww . j ava 2 s . c o m*/ httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new KsfxHttpRetryHandler(retryCount, retryDelay)); try { int tryCount = 0; int statusCode; do { if (tryCount > 1) { httpMethod = createNewHttpMethod(httpMethod); try { if (retryDelay == 0) { retryDelay = DEFAULT_RETRY_DELAY; } Thread.sleep(retryDelay); } catch (InterruptedException e) { logger.severe("InterruptedException"); } } //PROXY Configuration /* if (torify) { String proxyHost = ""; Integer proxyPort = 0; try { proxyHost = SpiderConfiguration.getConfiguration().getString("torifyHost"); proxyPort = SpiderConfiguration.getConfiguration().getInt("torifyPort"); } catch (Exception e) { logger.severe("Cannot get Proxy information"); } this.httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } */ statusCode = this.httpClient.executeMethod(httpMethod); tryCount++; } while (!(statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_FORBIDDEN || statusCode == HttpStatus.SC_NOT_FOUND) && tryCount < retryCount); if (statusCode != HttpStatus.SC_OK) { System.out.println("HTTP method failed: " + httpMethod.getStatusLine() + " - " + httpMethod.getURI().toString()); } } catch (HttpException e) { e.printStackTrace(); httpMethod.abort(); try { logger.log(Level.SEVERE, "Redirrex " + e.getClass(), e); if (e.getClass().equals(RedirectException.class)) { logger.log(Level.SEVERE, "Is real redirect exception", e); throw new RuntimeException("HttpRedirectException"); } logger.log(Level.SEVERE, "HTTP protocol error for URL: " + httpMethod.getURI().toString(), e); } catch (URIException e1) { e.printStackTrace(); logger.log(Level.SEVERE, "URI exception", e); } throw new RuntimeException("HttpException"); } catch (IOException e) { try { e.printStackTrace(); logger.log(Level.SEVERE, "HTTP transport error for URL: " + httpMethod.getURI().toString(), e); } catch (URIException e1) { e.printStackTrace(); logger.log(Level.SEVERE, "URI exception", e); } throw new RuntimeException("IOException"); } return httpMethod; }
From source file:org.apache.manifoldcf.crawler.connectors.email.EmailConnector.java
/** Process a set of documents. * This is the method that should cause each document to be fetched, processed, and the results either added * to the queue of documents for the current job, and/or entered into the incremental ingestion manager. * The document specification allows this class to filter what is done based on the job. * The connector will be connected before this method can be called. *@param documentIdentifiers is the set of document identifiers to process. *@param statuses are the currently-stored document versions for each document in the set of document identifiers * passed in above./*from www. jav a 2 s .co m*/ *@param activities is the interface this method should use to queue up new document references * and ingest documents. *@param jobMode is an integer describing how the job is being run, whether continuous or once-only. *@param usesDefaultAuthority will be true only if the authority in use for these documents is the default one. */ @Override public void processDocuments(String[] documentIdentifiers, IExistingVersions statuses, Specification spec, IProcessActivity activities, int jobMode, boolean usesDefaultAuthority) throws ManifoldCFException, ServiceInterruption { List<String> requiredMetadata = new ArrayList<String>(); for (int i = 0; i < spec.getChildCount(); i++) { SpecificationNode sn = spec.getChild(i); if (sn.getType().equals(EmailConfig.NODE_METADATA)) { String metadataAttribute = sn.getAttributeValue(EmailConfig.ATTRIBUTE_NAME); requiredMetadata.add(metadataAttribute); } } // Keep a cached set of open folders Map<String, Folder> openFolders = new HashMap<String, Folder>(); try { for (String documentIdentifier : documentIdentifiers) { String versionString = "_" + urlTemplate; // NOT empty; we need to make ManifoldCF understand that this is a document that never will change. // Check if we need to index if (!activities.checkDocumentNeedsReindexing(documentIdentifier, versionString)) continue; String compositeID = documentIdentifier; String version = versionString; String folderName = extractFolderNameFromDocumentIdentifier(compositeID); String id = extractEmailIDFromDocumentIdentifier(compositeID); String errorCode = null; String errorDesc = null; Long fileLengthLong = null; long startTime = System.currentTimeMillis(); try { try { Folder folder = openFolders.get(folderName); if (folder == null) { getSession(); OpenFolderThread oft = new OpenFolderThread(session, folderName); oft.start(); folder = oft.finishUp(); openFolders.put(folderName, folder); } if (Logging.connectors.isDebugEnabled()) Logging.connectors.debug("Email: Processing document identifier '" + compositeID + "'"); SearchTerm messageIDTerm = new MessageIDTerm(id); getSession(); SearchMessagesThread smt = new SearchMessagesThread(session, folder, messageIDTerm); smt.start(); Message[] message = smt.finishUp(); String msgURL = makeDocumentURI(urlTemplate, folderName, id); Message msg = null; for (Message msg2 : message) { msg = msg2; } if (msg == null) { // email was not found activities.deleteDocument(id); continue; } if (!activities.checkURLIndexable(msgURL)) { errorCode = activities.EXCLUDED_URL; errorDesc = "Excluded because of URL ('" + msgURL + "')"; activities.noDocument(id, version); continue; } long fileLength = msg.getSize(); if (!activities.checkLengthIndexable(fileLength)) { errorCode = activities.EXCLUDED_LENGTH; errorDesc = "Excluded because of length (" + fileLength + ")"; activities.noDocument(id, version); continue; } Date sentDate = msg.getSentDate(); if (!activities.checkDateIndexable(sentDate)) { errorCode = activities.EXCLUDED_DATE; errorDesc = "Excluded because of date (" + sentDate + ")"; activities.noDocument(id, version); continue; } String mimeType = "text/plain"; if (!activities.checkMimeTypeIndexable(mimeType)) { errorCode = activities.EXCLUDED_DATE; errorDesc = "Excluded because of mime type ('" + mimeType + "')"; activities.noDocument(id, version); continue; } RepositoryDocument rd = new RepositoryDocument(); rd.setFileName(msg.getFileName()); rd.setMimeType(mimeType); rd.setCreatedDate(sentDate); rd.setModifiedDate(sentDate); String subject = StringUtils.EMPTY; for (String metadata : requiredMetadata) { if (metadata.toLowerCase().equals(EmailConfig.EMAIL_TO)) { Address[] to = msg.getRecipients(Message.RecipientType.TO); String[] toStr = new String[to.length]; int j = 0; for (Address address : to) { toStr[j] = address.toString(); } rd.addField(EmailConfig.EMAIL_TO, toStr); } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_FROM)) { Address[] from = msg.getFrom(); String[] fromStr = new String[from.length]; int j = 0; for (Address address : from) { fromStr[j] = address.toString(); } rd.addField(EmailConfig.EMAIL_TO, fromStr); } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_SUBJECT)) { subject = msg.getSubject(); rd.addField(EmailConfig.EMAIL_SUBJECT, subject); } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_BODY)) { Multipart mp = (Multipart) msg.getContent(); for (int k = 0, n = mp.getCount(); k < n; k++) { Part part = mp.getBodyPart(k); String disposition = part.getDisposition(); if ((disposition == null)) { MimeBodyPart mbp = (MimeBodyPart) part; if (mbp.isMimeType(EmailConfig.MIMETYPE_TEXT_PLAIN)) { rd.addField(EmailConfig.EMAIL_BODY, mbp.getContent().toString()); } else if (mbp.isMimeType(EmailConfig.MIMETYPE_HTML)) { rd.addField(EmailConfig.EMAIL_BODY, mbp.getContent().toString()); //handle html accordingly. Returns content with html tags } } } } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_DATE)) { rd.addField(EmailConfig.EMAIL_DATE, sentDate.toString()); } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_ATTACHMENT_ENCODING)) { Multipart mp = (Multipart) msg.getContent(); if (mp != null) { String[] encoding = new String[mp.getCount()]; for (int k = 0, n = mp.getCount(); k < n; k++) { Part part = mp.getBodyPart(k); String disposition = part.getDisposition(); if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT) || (disposition.equals(Part.INLINE))))) { encoding[k] = part.getFileName().split("\\?")[1]; } } rd.addField(EmailConfig.ENCODING_FIELD, encoding); } } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_ATTACHMENT_MIMETYPE)) { Multipart mp = (Multipart) msg.getContent(); String[] MIMEType = new String[mp.getCount()]; for (int k = 0, n = mp.getCount(); k < n; k++) { Part part = mp.getBodyPart(k); String disposition = part.getDisposition(); if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT) || (disposition.equals(Part.INLINE))))) { MIMEType[k] = part.getContentType(); } } rd.addField(EmailConfig.MIMETYPE_FIELD, MIMEType); } } InputStream is = msg.getInputStream(); try { rd.setBinary(is, fileLength); activities.ingestDocumentWithException(id, version, msgURL, rd); errorCode = "OK"; fileLengthLong = new Long(fileLength); } finally { is.close(); } } catch (InterruptedException e) { throw new ManifoldCFException(e.getMessage(), ManifoldCFException.INTERRUPTED); } catch (MessagingException e) { errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT); errorDesc = e.getMessage(); handleMessagingException(e, "processing email"); } catch (IOException e) { errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT); errorDesc = e.getMessage(); handleIOException(e, "processing email"); throw new ManifoldCFException(e.getMessage(), e); } } catch (ManifoldCFException e) { if (e.getErrorCode() == ManifoldCFException.INTERRUPTED) errorCode = null; throw e; } finally { if (errorCode != null) activities.recordActivity(new Long(startTime), EmailConfig.ACTIVITY_FETCH, fileLengthLong, documentIdentifier, errorCode, errorDesc, null); } } } finally { for (Folder f : openFolders.values()) { try { CloseFolderThread cft = new CloseFolderThread(session, f); cft.start(); cft.finishUp(); } catch (InterruptedException e) { throw new ManifoldCFException(e.getMessage(), ManifoldCFException.INTERRUPTED); } catch (MessagingException e) { handleMessagingException(e, "closing folders"); } } } }
From source file:com.cloud.hypervisor.xenserver.resource.XenServerStorageProcessor.java
@Override public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { final DataTO srcDataTo = cmd.getSrcTO(); final DataTO destDataTo = cmd.getDestTO(); final int wait = cmd.getWait(); final DataStoreTO srcDataStoreTo = srcDataTo.getDataStore(); final Connection conn = hypervisorResource.getConnection(); SR sr = null;//www .j a v a 2 s . c om boolean removeSrAfterCopy = false; try { if (srcDataStoreTo instanceof NfsTO && srcDataTo.getObjectType() == DataObjectType.TEMPLATE) { final NfsTO srcImageStore = (NfsTO) srcDataStoreTo; final TemplateObjectTO srcTemplateObjectTo = (TemplateObjectTO) srcDataTo; final String storeUrl = srcImageStore.getUrl(); final URI uri = new URI(storeUrl); final String tmplPath = uri.getHost() + ":" + uri.getPath() + "/" + srcDataTo.getPath(); final DataStoreTO destDataStoreTo = destDataTo.getDataStore(); boolean managed = false; String storageHost = null; String managedStoragePoolName = null; String managedStoragePoolRootVolumeName = null; String managedStoragePoolRootVolumeSize = null; String chapInitiatorUsername = null; String chapInitiatorSecret = null; if (destDataStoreTo instanceof PrimaryDataStoreTO) { final PrimaryDataStoreTO destPrimaryDataStoreTo = (PrimaryDataStoreTO) destDataStoreTo; final Map<String, String> details = destPrimaryDataStoreTo.getDetails(); if (details != null) { managed = Boolean.parseBoolean(details.get(PrimaryDataStoreTO.MANAGED)); if (managed) { storageHost = details.get(PrimaryDataStoreTO.STORAGE_HOST); managedStoragePoolName = details.get(PrimaryDataStoreTO.MANAGED_STORE_TARGET); managedStoragePoolRootVolumeName = details .get(PrimaryDataStoreTO.MANAGED_STORE_TARGET_ROOT_VOLUME); managedStoragePoolRootVolumeSize = details.get(PrimaryDataStoreTO.VOLUME_SIZE); chapInitiatorUsername = details.get(PrimaryDataStoreTO.CHAP_INITIATOR_USERNAME); chapInitiatorSecret = details.get(PrimaryDataStoreTO.CHAP_INITIATOR_SECRET); removeSrAfterCopy = Boolean .parseBoolean(details.get(PrimaryDataStoreTO.REMOVE_AFTER_COPY)); } } } if (managed) { final Map<String, String> details = new HashMap<String, String>(); details.put(DiskTO.STORAGE_HOST, storageHost); details.put(DiskTO.IQN, managedStoragePoolName); details.put(DiskTO.VOLUME_SIZE, managedStoragePoolRootVolumeSize); details.put(DiskTO.CHAP_INITIATOR_USERNAME, chapInitiatorUsername); details.put(DiskTO.CHAP_INITIATOR_SECRET, chapInitiatorSecret); sr = hypervisorResource.prepareManagedSr(conn, details); } else { final String srName = destDataStoreTo.getUuid(); final Set<SR> srs = SR.getByNameLabel(conn, srName); if (srs.size() != 1) { final String msg = "There are " + srs.size() + " SRs with same name: " + srName; s_logger.warn(msg); return new CopyCmdAnswer(msg); } else { sr = srs.iterator().next(); } } final String srUuid = sr.getUuid(conn); final String tmplUuid = copy_vhd_from_secondarystorage(conn, tmplPath, srUuid, wait); final VDI tmplVdi = getVDIbyUuid(conn, tmplUuid); final String uuidToReturn; final Long physicalSize = tmplVdi.getPhysicalUtilisation(conn); if (managed) { uuidToReturn = tmplUuid; tmplVdi.setNameLabel(conn, managedStoragePoolRootVolumeName); } else { final VDI snapshotVdi = tmplVdi.snapshot(conn, new HashMap<String, String>()); uuidToReturn = snapshotVdi.getUuid(conn); snapshotVdi.setNameLabel(conn, "Template " + srcTemplateObjectTo.getName()); tmplVdi.destroy(conn); } sr.scan(conn); try { Thread.sleep(5000); } catch (final InterruptedException e) { } final TemplateObjectTO newVol = new TemplateObjectTO(); newVol.setUuid(uuidToReturn); newVol.setPath(uuidToReturn); if (physicalSize != null) { newVol.setSize(physicalSize); } newVol.setFormat(ImageFormat.VHD); return new CopyCmdAnswer(newVol); } } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " for template + " + " due to " + e.toString(); s_logger.warn(msg, e); return new CopyCmdAnswer(msg); } finally { if (removeSrAfterCopy && sr != null) { hypervisorResource.removeSR(conn, sr); } } return new CopyCmdAnswer("not implemented yet"); }
From source file:org.apache.tez.runtime.LogicalIOProcessorRuntimeTask.java
public void cleanup() throws InterruptedException { LOG.info("Final Counters for " + taskSpec.getTaskAttemptID() + ": " + getCounters().toShortString()); setTaskDone();/*from w w w.ja v a 2 s. c o m*/ if (eventRouterThread != null) { eventRouterThread.interrupt(); LOG.info("Joining on EventRouter"); try { eventRouterThread.join(); } catch (InterruptedException e) { LOG.info("Ignoring interrupt while waiting for the router thread to die"); Thread.currentThread().interrupt(); } eventRouterThread = null; } // Close the unclosed IPO /** * Cleanup IPO that are not closed. In case, regular close() has happened in IPO, they * would not be available in the IPOs to be cleaned. So this is safe. * * e.g whenever input gets closed() in normal way, it automatically removes it from * initializedInputs map. * * In case any exception happens in processor close or IO close, it wouldn't be removed from * the initialized IO data structures and here is the chance to close them and release * resources. * */ if (LOG.isDebugEnabled()) { LOG.debug("Processor closed={}", processorClosed); LOG.debug("Num of inputs to be closed={}", initializedInputs.size()); LOG.debug("Num of outputs to be closed={}", initializedOutputs.size()); } // Close the remaining inited Inputs. Iterator<Map.Entry<String, LogicalInput>> inputIterator = initializedInputs.entrySet().iterator(); while (inputIterator.hasNext()) { Map.Entry<String, LogicalInput> entry = inputIterator.next(); String srcVertexName = entry.getKey(); inputIterator.remove(); try { ((InputFrameworkInterface) entry.getValue()).close(); maybeResetInterruptStatus(); } catch (InterruptedException ie) { //reset the status LOG.info("Resetting interrupt status for input with srcVertexName={}", srcVertexName); Thread.currentThread().interrupt(); } catch (Throwable e) { LOG.warn("Ignoring exception when closing input {}(cleanup). Exception class={}, message={}", srcVertexName, e.getClass().getName(), e.getMessage()); } finally { LOG.info("Closed input for vertex={}, sourceVertex={}, interruptedStatus={}", processor.getContext().getTaskVertexName(), srcVertexName, Thread.currentThread().isInterrupted()); } } // Close the remaining inited Outputs. Iterator<Map.Entry<String, LogicalOutput>> outputIterator = initializedOutputs.entrySet().iterator(); while (outputIterator.hasNext()) { Map.Entry<String, LogicalOutput> entry = outputIterator.next(); String destVertexName = entry.getKey(); outputIterator.remove(); try { ((OutputFrameworkInterface) entry.getValue()).close(); maybeResetInterruptStatus(); } catch (InterruptedException ie) { //reset the status LOG.info("Resetting interrupt status for output with destVertexName={}", destVertexName); Thread.currentThread().interrupt(); } catch (Throwable e) { LOG.warn("Ignoring exception when closing output {}(cleanup). Exception class={}, message={}", destVertexName, e.getClass().getName(), e.getMessage()); } finally { LOG.info("Closed input for vertex={}, sourceVertex={}, interruptedStatus={}", processor.getContext().getTaskVertexName(), destVertexName, Thread.currentThread().isInterrupted()); } } if (LOG.isDebugEnabled()) { printThreads(); } // Close processor if (!processorClosed && processor != null) { try { processorClosed = true; processor.close(); LOG.info("Closed processor for vertex={}, index={}, interruptedStatus={}", processor.getContext().getTaskVertexName(), processor.getContext().getTaskVertexIndex(), Thread.currentThread().isInterrupted()); maybeResetInterruptStatus(); } catch (InterruptedException ie) { //reset the status LOG.info("Resetting interrupt for processor"); Thread.currentThread().interrupt(); } catch (Throwable e) { LOG.warn("Ignoring Exception when closing processor(cleanup). Exception class={}, message={}" + e.getClass().getName(), e.getMessage()); } } try { closeContexts(); // Cleanup references which may be held by misbehaved tasks. cleanupStructures(); } catch (IOException e) { LOG.info("Error while cleaning up contexts ", e); } }
From source file:com.clustercontrol.agent.ReceiveTopic.java
/** * ??/*www. j a v a2 s .c om*/ */ @Override public void run() { m_log.info("run start"); while (true) { /* * ?????????sleep? * */ try { int interval = m_topicInterval; countDownLatch = new CountDownLatch(1); if (!countDownLatch.await(interval, TimeUnit.MILLISECONDS)) m_log.debug("waiting is over"); } catch (InterruptedException e) { m_log.warn("Interrupt " + e.getMessage()); } catch (Exception e) { m_log.error("run() : " + e.getMessage(), e); } try { List<RunInstructionInfo> runInstructionList = new ArrayList<RunInstructionInfo>(); m_log.info("getTopic " + Agent.getAgentStr() + " start"); HinemosTopicInfo hinemosTopicInfo = null; List<TopicInfo> topicInfoList = null; SettingUpdateInfo updateInfo = null; try { // ???????????topic?????????????synchronized? synchronized (lockTopicReceiveTiming) { if (isTerminated == true) { // ????????????? return; } hinemosTopicInfo = AgentEndPointWrapper.getHinemosTopic(); } } catch (Exception e) { /* * ????????????????????? * ????? */ if (disconnectCounter < Long.MAX_VALUE) { disconnectCounter++; } // ??????????? if (disconnectCounter * m_topicInterval > m_runhistoryClearDelay) { clearJobHistory(); } /* * ????????????? * StackTrace?????????????? * StackTrace????? * ????????debug?? */ String message = "run() getTopic : " + ", " + disconnectCounter + "*" + m_topicInterval + ":" + m_runhistoryClearDelay + ", " + e.getClass().getSimpleName() + ", " + e.getMessage(); m_log.warn(message); m_log.debug(message, e); continue; // while?? } // ???????? topicInfoList = hinemosTopicInfo.getTopicInfoList(); updateInfo = hinemosTopicInfo.getSettingUpdateInfo(); Agent.setAwakePort(hinemosTopicInfo.getAwakePort()); // Hinemos HinemosTime.setTimeOffsetMillis(updateInfo.getHinemosTimeOffset()); // Hinemos HinemosTime.setTimeZoneOffset(updateInfo.getHinemosTimeZoneOffset()); /* * ???????????Windows????? * ?? */ m_log.debug("run : disconnectCounter=" + disconnectCounter); if (disconnectCounter != 0 || isReloadFlg()) { reloadLogfileMonitor(updateInfo, true); reloadCustomMonitor(updateInfo, true); reloadWinEventMonitor(updateInfo, true); reloadJobFileCheck(updateInfo, true); UpdateModuleUtil.setAgentLibMd5(); setReloadFlg(false); } disconnectCounter = 0; setHistoryClear(false); m_log.debug("run : topicInfoList.size=" + topicInfoList.size()); for (TopicInfo topicInfo : topicInfoList) { m_log.info("getTopic flag=" + topicInfo.getFlag()); RunInstructionInfo runInstructionInfo = topicInfo.getRunInstructionInfo(); if (runInstructionInfo != null) { runInstructionList.add(runInstructionInfo); } long topicFlag = topicInfo.getFlag(); if (topicInfo.getAgentCommand() != 0) { int agentCommand = topicInfo.getAgentCommand(); m_log.debug("agentCommand : " + agentCommand); if (agentCommand == AgentCommandConstant.UPDATE) { // 1????????????? if (!UpdateModuleUtil.update()) { agentCommand = 0; } } if (agentCommand != 0) { Agent.restart(agentCommand); } } if ((topicFlag & TopicFlagConstant.NEW_FACILITY) != 0) { UpdateModuleUtil.setAgentLibMd5(); } if (newTopicMode) { continue; } // ????? // topic.mode=4.0????? if ((topicFlag & TopicFlagConstant.REPOSITORY_CHANGED) != 0 || (topicFlag & TopicFlagConstant.NEW_FACILITY) != 0 || (topicFlag & TopicFlagConstant.CALENDAR_CHANGED) != 0 || (topicFlag & TopicFlagConstant.LOGFILE_CHANGED) != 0) { reloadLogfileMonitor(updateInfo, true); } if ((topicFlag & TopicFlagConstant.REPOSITORY_CHANGED) != 0 || (topicFlag & TopicFlagConstant.NEW_FACILITY) != 0 || (topicFlag & TopicFlagConstant.CALENDAR_CHANGED) != 0 || (topicFlag & TopicFlagConstant.CUSTOM_CHANGED) != 0) { reloadCustomMonitor(updateInfo, true); } if ((topicFlag & TopicFlagConstant.REPOSITORY_CHANGED) != 0 || (topicFlag & TopicFlagConstant.NEW_FACILITY) != 0 || (topicFlag & TopicFlagConstant.CALENDAR_CHANGED) != 0 || (topicFlag & TopicFlagConstant.WINEVENT_CHANGED) != 0) { reloadWinEventMonitor(updateInfo, true); } if ((topicFlag & TopicFlagConstant.REPOSITORY_CHANGED) != 0 || (topicFlag & TopicFlagConstant.NEW_FACILITY) != 0 || (topicFlag & TopicFlagConstant.CALENDAR_CHANGED) != 0 || (topicFlag & TopicFlagConstant.FILECHECK_CHANGED) != 0) { reloadJobFileCheck(updateInfo, true); } } reloadLogfileMonitor(updateInfo, false); reloadCustomMonitor(updateInfo, false); reloadWinEventMonitor(updateInfo, false); reloadJobFileCheck(updateInfo, false); settingLastUpdateInfo = updateInfo; m_log.debug("getTopic " + Agent.getAgentStr() + " end"); if (runInstructionList.size() > 0) { m_log.info("infoList.size() = " + runInstructionList.size()); } else { m_log.debug("infoList.size() = 0"); } for (RunInstructionInfo info : runInstructionList) { runJob(info); } } catch (Throwable e) { m_log.error("run() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); } } }
From source file:com.searchcode.app.jobs.IndexSvnRepoJob.java
/** * Indexes all the documents in the path provided. Will also remove anything from the index if not on disk * Generally this is a slow update used only for the inital clone of a repository * NB this can be used for updates but it will be much slower as it needs to to walk the contents of the disk *///from w w w. j av a 2 s . c o m public void indexDocsByPath(Path path, String repoName, String repoLocations, String repoRemoteLocation, boolean existingRepo) { SearchcodeLib scl = Singleton.getSearchCodeLib(); // Should have data object by this point List<String> fileLocations = new ArrayList<>(); Queue<CodeIndexDocument> codeIndexDocumentQueue = Singleton.getCodeIndexQueue(); // Convert once outside the main loop String fileRepoLocations = FilenameUtils.separatorsToUnix(repoLocations); boolean lowMemory = this.LOWMEMORY; try { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { while (CodeIndexer.shouldPauseAdding()) { Singleton.getLogger().info("Pausing parser."); try { Thread.sleep(SLEEPTIME); } catch (InterruptedException ex) { } } // Convert Path file to unix style that way everything is easier to reason about String fileParent = FilenameUtils.separatorsToUnix(file.getParent().toString()); String fileToString = FilenameUtils.separatorsToUnix(file.toString()); String fileName = file.getFileName().toString(); String md5Hash = Values.EMPTYSTRING; if (fileParent.endsWith("/.svn") || fileParent.contains("/.svn/")) { return FileVisitResult.CONTINUE; } List<String> codeLines; try { codeLines = Helpers.readFileLines(fileToString, MAXFILELINEDEPTH); } catch (IOException ex) { return FileVisitResult.CONTINUE; } try { FileInputStream fis = new FileInputStream(new File(fileToString)); md5Hash = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis); fis.close(); } catch (IOException ex) { Singleton.getLogger().warning("Unable to generate MD5 for " + fileToString); } // is the file minified? if (scl.isMinified(codeLines)) { Singleton.getLogger().info("Appears to be minified will not index " + fileToString); return FileVisitResult.CONTINUE; } String languageName = scl.languageGuesser(fileName, codeLines); String fileLocation = fileToString.replace(fileRepoLocations, Values.EMPTYSTRING) .replace(fileName, Values.EMPTYSTRING); String fileLocationFilename = fileToString.replace(fileRepoLocations, Values.EMPTYSTRING); String repoLocationRepoNameLocationFilename = fileToString; String newString = getBlameFilePath(fileLocationFilename); String codeOwner = getInfoExternal(codeLines.size(), repoName, fileRepoLocations, newString) .getName(); // If low memory don't add to the queue, just index it directly if (lowMemory) { CodeIndexer.indexDocument(new CodeIndexDocument(repoLocationRepoNameLocationFilename, repoName, fileName, fileLocation, fileLocationFilename, md5Hash, languageName, codeLines.size(), StringUtils.join(codeLines, " "), repoRemoteLocation, codeOwner)); } else { Singleton.incrementCodeIndexLinesCount(codeLines.size()); codeIndexDocumentQueue.add(new CodeIndexDocument(repoLocationRepoNameLocationFilename, repoName, fileName, fileLocation, fileLocationFilename, md5Hash, languageName, codeLines.size(), StringUtils.join(codeLines, " "), repoRemoteLocation, codeOwner)); } fileLocations.add(fileLocationFilename); return FileVisitResult.CONTINUE; } }); } catch (IOException ex) { Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + "\n with message: " + ex.getMessage()); } if (existingRepo) { CodeSearcher cs = new CodeSearcher(); List<String> indexLocations = cs.getRepoDocuments(repoName); for (String file : indexLocations) { if (!fileLocations.contains(file)) { Singleton.getLogger().info("Missing from disk, removing from index " + file); try { CodeIndexer.deleteByFileLocationFilename(file); } catch (IOException ex) { Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + "\n with message: " + ex.getMessage()); } } } } }
From source file:com.twinsoft.convertigo.eclipse.views.loggers.EngineLogView.java
private boolean getLogs() { try {/*from w ww. ja va 2 s.co m*/ JSONArray logs = logManager.getLines(); boolean interrupted = false; while (logs.length() == 0 && !interrupted && Thread.currentThread() == logViewThread) { synchronized (appender) { try { appender.wait(300); } catch (InterruptedException e) { interrupted = true; } } // Detect if the view has been closed if (Thread.currentThread() != logViewThread) { return false; } logs = logManager.getLines(); } HashMap<String, String> allExtras = new HashMap<String, String>(); for (int i = 0; i < logs.length(); i++) { JSONArray logLine = (JSONArray) logs.get(i); String dateTime = logLine.getString(1); String[] dateTimeParts = dateTime.split(" "); String date = dateTimeParts[0]; String time = dateTimeParts[1]; String deltaTime; try { long currentDate = DATE_FORMAT.parse(dateTime).getTime(); if (lastLogTime < 0) { deltaTime = "--"; } else { long delta = currentDate - lastLogTime; lastLogTime = currentDate; if (delta < 1000) { deltaTime = StringUtils.leftPad(delta + " ms", 8); } else if (delta < 10000) { deltaTime = StringUtils.leftPad(Math.floor(delta / 10.0) / 100.0 + " s ", 8); } else { deltaTime = StringUtils.leftPad((int) Math.floor(delta / 1000.0) + " s ", 8); } } lastLogTime = currentDate; } catch (ParseException e) { deltaTime = "n/a"; } int len = logLine.length(); for (int j = 5; j < len; j++) { String extra = logLine.getString(j); int k = extra.indexOf("="); allExtras.put(extra.substring(0, k), extra.substring(k + 1)); } // Build the message lines String message = logLine.getString(4); String[] messageLines = message.split("\n"); if (messageLines.length > 1) { boolean firstLine = true; for (String messageLine : messageLines) { logLines.add(new LogLine(logLine.getString(0), date, time, deltaTime, logLine.getString(2), logLine.getString(3), messageLine, !firstLine, counter, logLine.getString(4), allExtras)); counter++; firstLine = false; } } else { logLines.add(new LogLine(logLine.getString(0), date, time, deltaTime, logLine.getString(2), logLine.getString(3), logLine.getString(4), false, counter, logLine.getString(4), allExtras)); counter++; } } } catch (JSONException e) { ConvertigoPlugin.logException(e, "Unable to process received Engine logs", false); } catch (Exception e) { ConvertigoPlugin.logException(e, "Error while loading the Engine logs (" + e.getClass().getCanonicalName() + ")", false); try { Thread.sleep(5000); } catch (InterruptedException e1) { } } logManager.setContinue(true); return true; }