List of usage examples for org.springframework.util StopWatch StopWatch
public StopWatch()
From source file:no.abmu.organisationregister.util.OrganisationUnitImportExcelParser.java
/** * Check for necessary input values.//from w ww . j av a 2 s .c o m * * Returns null if OK, else error message with description of missing * input values. * * @return - errorMessage equals Null if OK, else description of * missing input values. */ public String checkInputValues() { logger.info("Start testing for nessesary input values ..."); StopWatch stopWatch = new StopWatch(); stopWatch.start(); String[] notNullNames = { ORG_TYPE, NAVN_BOKMAL }; // {ORG_TYPE, NAVN_BOKMAL, ADRESSE_POST, POSTNR, POST_STED}; String errorMessage = checkInputValues(notNullNames); if (errorMessage != null) { logger.error(errorMessage); } else { logger.info("All nessesary input values were present ..."); } stopWatch.stop(); logger.info("Testing nessesary input values tok " + stopWatch.getTotalTimeMillis() + " ms."); return errorMessage; }
From source file:no.abmu.organisationregister.util.OrganisationUnitImportExcelParser.java
public int organisationUnitDuplicationCount() { logger.info("Executing organisationUnitDuplicationCount"); int duplicationCount = 0; StopWatch stopWatch = new StopWatch(); stopWatch.start();//ww w. j a v a 2 s . co m load(); for (; hasNext(); next()) { String organisationUnitName = getCellValueAsString("NAME BOKMAL"); Set<OrganisationUnit> orgUnits = DataLoaderUtils.findOrganisationUnitByName(baseService, organisationUnitName); if (orgUnits.size() > 0) { String warningMessage = "On row " + +getCurrentRowIdx() + " " + orgUnits.size() + " organisationUnits has the name: '" + organisationUnitName + "'."; logger.warn(warningMessage); duplicationCount++; } } if (duplicationCount > 0) { logger.error(duplicationCount + " dublication found to bad ... "); } else { logger.info("No duplication found, good."); } stopWatch.stop(); logger.info("Testing for dublication tok " + stopWatch.getTotalTimeMillis() + " ms."); return duplicationCount; }
From source file:no.abmu.questionnaire.service.QuestionnaireServiceHelperH3Impl.java
public ReportStatus[] getReportStatusBySchemaTypeNameAndVersion( List<OrganisationUnitForBrowsing> orgUnitsForBrowsing, SchemaTypeNameAndVersion schemaTypeNameAndVersion) { StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w . j a v a2 s . co m String codeFieldNumber = schemaTypeNameAndVersion.getCodeFinishField(); String dbSchemaName = schemaTypeNameAndVersion.getDbSchemaName(); String version = schemaTypeNameAndVersion.getVersion(); List<ReportStatus> reportStatusAsList = new ArrayList<ReportStatus>(); for (OrganisationUnitForBrowsing orgForBrowse : orgUnitsForBrowsing) { QuestionnaireData questionnaireData = getQuestionnaireData(orgForBrowse.getOrganisationUnitId(), dbSchemaName, version); reportStatusAsList.add(createReportStatus(orgForBrowse, questionnaireData, codeFieldNumber)); } stopWatch.stop(); logger.info("Finish prosessing of reportStatus for schemaTypeNameAndVersion:" + schemaTypeNameAndVersion + " with " + orgUnitsForBrowsing.size() + " elements in " + stopWatch.getTotalTimeMillis() + " ms"); return reportStatusAsList.toArray(new ReportStatus[reportStatusAsList.size()]); }
From source file:no.abmu.questionnaire.webflow.QuestionnaireFormAction.java
protected Object createFormObject(RequestContext context) { if (logger.isDebugEnabled()) { logger.debug("Executing createFormObject"); }//from w w w . jav a 2s. co m StopWatch stopWatch = new StopWatch(); stopWatch.start("createFormObject"); FlowVariables flowVariables = (FlowVariables) context.getFlowScope().get("flowVariables"); Long orgUnitId = flowVariables.getWorkingSchemaOrganisationUnitId(); String questionnaireNameAsString = flowVariables.getQuestionnaireNameAsString(); String schemaVersion = flowVariables.getQuestionnaireVersion(); // QuestionnaireCommand questionnaireCommand = flowVariables.getQuestionnaireCommand(); if (logger.isDebugEnabled()) { logger.debug("[createWebSchema] flowVariabels ==> " + flowVariables); } Assert.assertNotNull("orgUnitId", orgUnitId); Assert.assertNotNull("questionnaireNameAsString", questionnaireNameAsString); Assert.assertNotNull("schemaVersion", schemaVersion); String submitEvent = context.getRequestParameters().get("_eventId_submit.y"); if (submitEvent == null) { if (logger.isDebugEnabled()) { logger.debug("[createFormObject] submitEvent == null (formObject to user) "); } } else { if (logger.isDebugEnabled()) { logger.debug("[createFormObject] submitEvent != null (formObject from user)"); logger.debug("SubmitEvent='" + submitEvent + "'"); } } QuestionnaireCommand questionnaireCommand = getCommandFromDb(orgUnitId, questionnaireNameAsString, schemaVersion); try { stopWatch.stop(); logger.info("[createFormObject] tok [" + stopWatch.getTotalTimeMillis() + "] ms"); } catch (IllegalStateException e) { // Catch and log error. // logger.error("[formBackingObject] Error in stopWatch for user: " + loggedOn.toString()); logger.error("[formBackingObject] Error in stopWatch: " + e); } return questionnaireCommand; }
From source file:no.abmu.questionnaire.webflow.QuestionnaireFormAction.java
private QuestionnaireCommand getCommandFromDb(Long orgUnitId, String mainSchemaName, String schemaVersion) { Assert.assertNotNull("orgUnitId", orgUnitId); Assert.assertNotNull("mainSchemaName", mainSchemaName); Assert.assertNotNull("schemaVersion", schemaVersion); StopWatch stopWatch = new StopWatch(); stopWatch.start("createFormObjectFromDb"); QuestionnaireData questionnaireData = questionnaireService.getOrCreateQuestionnaireData(orgUnitId, mainSchemaName, schemaVersion); QuestionnaireCommand command = new QuestionnaireCommand(questionnaireData, orgUnitId); try {/* www .ja v a 2 s. c om*/ FieldData fieldData = command.getQuestionnaireData().getFieldData("103"); logger.info("getFieldData:" + fieldData + ", value:" + fieldData.getUntypedValue() + ", type:" + fieldData.getUntypedValue().getClass()); } catch (Exception e) { } try { stopWatch.stop(); logger.info("[getCommandFromDb] tok [" + stopWatch.getTotalTimeMillis() + "] ms"); } catch (IllegalStateException e) { // Catch and log error. // logger.error("[formBackingObject] Error in stopWatch for user: " + loggedOn.toString()); logger.error("[formBackingObject] Error in stopWatch: " + e); } return command; }
From source file:no.abmu.questionnaire.webflow.QuestionnaireWebFlowValidator.java
public void validateAndSave(Object object, Errors errors) { if (logger.isDebugEnabled()) { logger.debug("Executing validateAndSave"); logger.debug("Object is of type ==>" + object.getClass().getName()); logger.debug("Number of errors in error object=[" + errors.getErrorCount() + "]"); }//from w ww.ja v a 2 s .c o m Assert.assertTrue("We expect object to implement interface SchemaCommand", object instanceof SchemaCommand); StopWatch stopWatchValidate = new StopWatch(); stopWatchValidate.start("validate"); validate(object, errors); SchemaCommand schemaCommand = (SchemaCommand) object; // schemaCommand.setErrors(errors); stopWatchValidate.stop(); logger.info("[validate] tok [" + stopWatchValidate.getTotalTimeMillis() + "] ms"); logger.info("Number of errors after validating=[" + errors.getErrorCount() + "]."); /* logger.info("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); logger.info("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); logger.info("Error toString ==> " + errors.toString()); logger.info("Error getErrorCount ==> " + errors.getErrorCount()); logger.info("Error getGlobalErrorCount ==> " + errors.getGlobalErrorCount()); logger.info("Error getNestedPath ==> " + errors.getNestedPath()); logger.info("Error getObjectName ==> " + errors.getObjectName()); logger.info("Error getClass ==> " + errors.getClass()); logger.info("NESTED_PATH_SEPARATOR ==> " + errors.NESTED_PATH_SEPARATOR); logger.info("Error getClass ==> " + errors.getClass()); logger.info("Error getFieldError ==> " + errors.getFieldError()); logger.info("getFieldError('fields[06].value') ==> " + errors.getFieldError("fields[06].value")); logger.info("Error getFieldErrors ==> " + errors.getFieldErrors()); logger.info("Error getGlobalError ==> " + errors.getGlobalError()); logger.info("Error getGlobalErrors ==> " + errors.getGlobalErrors()); logger.info("Error hasErrors ==> " + errors.hasErrors()); logger.info("Error hasFieldErrors ==> " + errors.hasFieldErrors()); logger.info("Error hasGlobalErrors ==> " + errors.hasGlobalErrors()); logger.info("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); logger.info("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); */ if (!errors.hasErrors()) { logger.info("No errors"); StopWatch stopWatchSave = new StopWatch(); stopWatchSave.start("save"); if (schemaCommand instanceof QuestionnaireCommand) { logger.info("Command object of type QuestionnaireCommand"); QuestionnaireCommand command = (QuestionnaireCommand) object; Assert.assertNotNull("command", command); questionnaireService.storeQuestionnaireData(command.getQuestionnaireData(), command.getOrgUnitId()); } else if (schemaCommand instanceof SubSchemaCommand) { logger.info("Command object of type SubSchemaCommand"); SubSchemaCommand subSchemaCommand = (SubSchemaCommand) object; SubSchemaData subSchemaData = subSchemaCommand.getSubSchemaData(); logger.info("=============== SubSchemaData which was edited ======================"); loggingOfSubschema(subSchemaData, 0); logger.info("=============== SubSchemaData which was edited ======================"); QuestionnaireData questionnaireData = subSchemaCommand.getQuestionnaireData(); Assert.assertNotNull("questionnaireData", questionnaireData); if (subSchemaData.getId() == null) { questionnaireData.addSubSchemaData(subSchemaData); } logger.info("=============== All SubSchemaData Before store ======================"); loggingOfSubSchemas(questionnaireData); logger.info("=============== All SubSchemaData Before store ======================"); questionnaireService.storeQuestionnaireData(questionnaireData); } else { throw new IllegalArgumentException( "Unsupported command object " + schemaCommand.getClass().getName()); } stopWatchSave.stop(); logger.info("[save] tok [" + stopWatchSave.getTotalTimeMillis() + "] ms"); } }
From source file:org.eurekastreams.server.aop.PerformanceTimer.java
/** * Method for logging timing data./*ww w .ja v a 2s .co m*/ * * @param call * {@link ProceedingJoinPoint} * @return result of wrapped method. * @throws Throwable * on error. */ public Object profile(final ProceedingJoinPoint call) throws Throwable { StopWatch clock = null; // get the perf log for target object. Log log = LogFactory.getLog("perf.timer." + call.getTarget().getClass().getCanonicalName()); try { if (log.isInfoEnabled()) { clock = new StopWatch(); clock.start(call.toShortString()); } return call.proceed(); } finally { if (log.isInfoEnabled() && clock != null) { clock.stop(); Object[] args = call.getArgs(); StringBuffer params = new StringBuffer(); for (Object obj : args) { params.append("Param: " + ((obj == null) ? "null" : obj.toString()) + "\n\t"); } log.info(clock.getTotalTimeMillis() + " (ms) - " + call.getTarget().getClass().getSimpleName() + "." + call.getSignature().toShortString() + "\n\t" + params.toString()); } } }
From source file:org.flockdata.integration.FileProcessor.java
private int processJsonEntities(String fileName, ExtractProfile extractProfile) throws FlockException { int rows = 0; File file = new File(fileName); InputStream stream = null;/*from w w w . ja va 2s . c o m*/ if (!file.exists()) { stream = ClassLoader.class.getResourceAsStream(fileName); if (stream == null) { logger.error("{} does not exist", fileName); return 0; } } StopWatch watch = new StopWatch(); JsonFactory jfactory = new JsonFactory(); JsonParser jParser; List<EntityToEntityLinkInput> referenceInputBeans = new ArrayList<>(); try { //String docType = mappable.getDataType(); watch.start(); ObjectMapper om = FdJsonObjectMapper.getObjectMapper(); try { if (stream != null) jParser = jfactory.createParser(stream); else jParser = jfactory.createParser(file); JsonToken currentToken = jParser.nextToken(); long then = new DateTime().getMillis(); JsonNode node; if (currentToken == JsonToken.START_ARRAY || currentToken == JsonToken.START_OBJECT) { while (currentToken != null && currentToken != JsonToken.END_OBJECT) { while (currentToken != null && jParser.nextToken() != JsonToken.END_ARRAY) { node = om.readTree(jParser); if (node != null) { processJsonNode(node, extractProfile.getContentModel(), referenceInputBeans); if (stopProcessing(rows++, then)) { break; } } currentToken = jParser.nextToken(); } } } else if (currentToken == JsonToken.START_OBJECT) { //om.readTree(jParser); node = om.readTree(jParser); processJsonNode(node, extractProfile.getContentModel(), referenceInputBeans); } } catch (IOException e1) { logger.error("Unexpected", e1); } } finally { getPayloadWriter().flush(); } return endProcess(watch, rows, 0); }
From source file:org.flockdata.integration.FileProcessor.java
private int processXMLFile(String file, ExtractProfile extractProfile) throws IOException, FlockException, IllegalAccessException, InstantiationException, ClassNotFoundException { try {//from w ww . j a v a 2 s . c o m int rows = 0; StopWatch watch = new StopWatch(); StreamSource source = new StreamSource(file); XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(source); XmlMappable mappable = (XmlMappable) Class.forName(extractProfile.getHandler()).newInstance(); mappable.positionReader(xsr); String dataType = mappable.getDataType(); watch.start(); try { long then = new DateTime().getMillis(); while (xsr.getLocalName().equals(dataType)) { EntityInputBean entityInputBean = Transformer.toEntity(mappable, xsr, extractProfile.getContentModel()); rows++; xsr.nextTag(); getPayloadWriter().writeEntity(entityInputBean); if (stopProcessing(rows, then)) { break; } } } finally { getPayloadWriter().flush(); } return endProcess(watch, rows, 0); } catch (XMLStreamException | JAXBException e1) { throw new IOException(e1); } }
From source file:org.flockdata.integration.FileProcessor.java
private int processCSVFile(String file, ExtractProfile extractProfile) throws IOException, IllegalAccessException, InstantiationException, FlockException, ClassNotFoundException { StopWatch watch = new StopWatch(); int ignoreCount = 0; int currentRow = 0; BufferedReader br;//from ww w.j a v a 2s .c o m Reader fileObject = getReader(file); br = new BufferedReader(fileObject); try { CSVReader csvReader; if (extractProfile.getQuoteCharacter() != null) csvReader = new CSVReader(br, extractProfile.getDelimiter(), extractProfile.getQuoteCharacter().charAt(0)); else csvReader = new CSVReader(br, extractProfile.getDelimiter()); String[] headerRow = null; String[] nextLine; if (extractProfile.hasHeader()) { while ((nextLine = csvReader.readNext()) != null) { if (isHeaderRow(nextLine)) { headerRow = nextLine; break; } } } watch.start(); if (skipCount > 0) logger.info("Skipping first {} rows", skipCount); long then = System.currentTimeMillis(); while ((nextLine = csvReader.readNext()) != null) { if (!ignoreRow(nextLine)) { if (headerRow == null) { headerRow = TransformationHelper.defaultHeader(nextLine, extractProfile.getContentModel()); } currentRow++; if (currentRow >= skipCount) { if (currentRow == skipCount) logger.info("Processing now begins at row {}", skipCount); nextLine = preProcess(nextLine, extractProfile); Map<String, Object> map = Transformer.convertToMap(headerRow, nextLine, extractProfile); if (map != null) { if (extractProfile.getContentModel().isTagModel()) { Collection<TagInputBean> tagInputBean = Transformer.toTags(map, extractProfile.getContentModel()); if (tagInputBean != null) { getPayloadWriter().writeTags(tagInputBean, "TagInputBean"); } } else { EntityInputBean entityInputBean = Transformer.toEntity(map, extractProfile.getContentModel()); // Dispatch/load mechanism if (entityInputBean != null) getPayloadWriter().writeEntity(entityInputBean); } if (stopProcessing(currentRow, then)) { break; } } } } else { ignoreCount++; } } } finally { getPayloadWriter().flush(); br.close(); } return endProcess(watch, currentRow, ignoreCount); }