List of usage examples for java.util Map clear
void clear();
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void PtmOverSpeedRecordsStoreIntoDB(Map<String, PtmOverSpeed> overSpeedRecords, ApplicationContext context) {/*from ww w. j av a 2s .c o m*/ // INSERT INTO // TAB_ALARM_OVERSPEED(LICENCE,BEGIN_TIME,END_TIME,SPEED,IS_END,AREA) // SELECT LICENSE,BEGINTIME,ENDTIME,AVGSPEED,'1',FLAG FROM // ALARMOVERSPEED_REA WHERE BUSINESSTYPE = '2' String sql = ""; Connection conn = null; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClientPtm"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = overSpeedRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); PtmOverSpeed pos = overSpeedRecords.get(key); sql = "insert into TAB_ALARM_OVERSPEED " + " (LICENCE,BEGIN_TIME,END_TIME,SPEED,IS_END,AREA) " + " values ('" + pos.getLicense() + "','" + pos.getBeginTime() + "','" + pos.getEndTIme() + "'," + pos.getAvgSpeed() + "," + "1" + "," + pos.getFlag() + ")"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB OverSpeed success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { overSpeedRecords.clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.esd.ps.AdministratorController.java
/** * ?// w w w.j a v a2s . c o m * * @param workerImage * @param workerPhone * @param workerBankCard * @param workerPaypal * @param session * @return */ @RequestMapping(value = "/updateWorker", method = RequestMethod.POST) @ResponseBody public Map<String, Object> updateWorkerPOST(String workerPhone, String workerBankCard, String workerPaypal, HttpSession session) { logger.debug("workerRealName:{},workerIdCard:{},workerBankCard:{},workerPaypal:{},workerPhone:{}", workerBankCard, workerPaypal); Map<String, Object> map = new HashMap<String, Object>(); int userId = Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()); worker worker = workerService.getWorkerByUserId(userId); worker newWorker = new worker(); if (worker.getWorkerPhone().equals(workerPhone.trim())) { if (worker.getWorkerBankCard().equals(workerBankCard.trim()) && worker.getWorkerPaypal().equals(workerPaypal.trim())) { map.clear(); map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS); map.put(Constants.REPLAY, 1); return map; } } else { if (workerPhone(workerPhone) == 1) { map.clear(); map.put(Constants.MESSAGE, MSG_NOT_UPDATE); return map; } else { newWorker.setWorkerPhone(workerPhone); } } newWorker.setWorkerId(worker.getWorkerId()); newWorker.setWorkerBankCard(workerBankCard); newWorker.setWorkerPaypal(workerPaypal); StackTraceElement[] items = Thread.currentThread().getStackTrace(); newWorker.setUpdateMethod(items[1].toString()); workerService.updateByPrimaryKeySelective(newWorker); map.clear(); map.put(Constants.MESSAGE, MSG_UPDATE_SUCCESS); map.put(Constants.REPLAY, 1); return map; }
From source file:com.zimbra.qa.unittest.prov.ldap.TestProvIDN.java
@Test public void testDomainInvalidNames() throws Exception { Config config = prov.getConfig();/* w ww . j av a2 s . co m*/ // save he current value of zimbraAllowNonLDHCharsInDomain String curAllowNonLDH = config.getAttr(Provisioning.A_zimbraAllowNonLDHCharsInDomain); // test values String goodEnglish = "good" + "." + BASE_DOMAIN_NAME; String goodIDN = makeTestDomainName("good"); String LDHEnglish_comma = "ldh'ldh" + "." + BASE_DOMAIN_NAME; String LDHIDN_comma = makeTestDomainName("ldh'ldh"); // when zimbraAllowNonLDHCharsInDomain is TRUE Map<String, Object> attrs = new HashMap<String, Object>(); attrs.put(Provisioning.A_zimbraAllowNonLDHCharsInDomain, ProvisioningConstants.TRUE); prov.modifyAttrs(config, attrs); String prefix = "allowtest."; // so that we don't run into domain exist problem doTestInvalidNames(prefix + goodEnglish, true); doTestInvalidNames(prefix + goodIDN, true); doTestInvalidNames(prefix + LDHEnglish_comma, true); // test failed. javamail does not allow it anymore, fix? bug 41123 doTestInvalidNames(prefix + LDHIDN_comma, true); // test failed. javamail does not allow it anymore. fix? bug 41123 // when zimbraAllowNonLDHCharsInDomain is FALSE attrs.clear(); attrs.put(Provisioning.A_zimbraAllowNonLDHCharsInDomain, ProvisioningConstants.FALSE); prov.modifyAttrs(config, attrs); prefix = "notallowtest."; doTestInvalidNames(prefix + goodEnglish, true); doTestInvalidNames(prefix + goodIDN, true); doTestInvalidNames(prefix + LDHEnglish_comma, false); doTestInvalidNames(prefix + LDHIDN_comma, false); // restore the orig config value back attrs.clear(); attrs.put(Provisioning.A_zimbraAllowNonLDHCharsInDomain, curAllowNonLDH); prov.modifyAttrs(config, attrs); }
From source file:com.china317.gmmp.gmmp_report_analysis.App.java
private static void OverSpeedRecordsStoreIntoDB(Map<String, PtmOverSpeed> overSpeedRecords, ApplicationContext context) {/*w ww .j ava2 s .com*/ Connection conn = null; String sql = ""; try { SqlMapClient sc = (SqlMapClient) context.getBean("sqlMapClient1"); conn = sc.getDataSource().getConnection(); conn.setAutoCommit(false); Statement st = conn.createStatement(); Iterator<String> it = overSpeedRecords.keySet().iterator(); while (it.hasNext()) { String key = it.next(); PtmOverSpeed pos = overSpeedRecords.get(key); sql = "insert into ALARMOVERSPEED_REA " + " (CODE,LICENSE,LICENSECOLOR,BEGINTIME,ENDTIME,AVGSPEED,MAXSPEED,FLAG,BUSINESSTYPE) " + " values (" + "'" + pos.getCode() + "'," + "'" + pos.getLicense() + "'," + "'" + pos.getLicenseColor() + "'," + "'" + pos.getBeginTime() + "'," + "'" + pos.getEndTIme() + "'," + pos.getAvgSpeed() + "," + pos.getMaxSpeed() + "," + pos.getFlag() + "," + pos.getBusinessType() + ")"; log.info(sql); st.addBatch(sql); } st.executeBatch(); conn.commit(); log.info("[insertIntoDB OverSpeed success!!!]"); } catch (Exception e) { e.printStackTrace(); log.error(sql); } finally { overSpeedRecords.clear(); if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:io.cloudslang.worker.management.services.OutboundBufferImpl.java
private void drainInternal(List<Message> bufferToDrain) { List<Message> bulk = new ArrayList<>(); int bulkWeight = 0; Map<String, AtomicInteger> logMap = new HashMap<>(); try {// w w w . ja v a 2 s. c o m for (Message message : bufferToDrain) { if (message.getClass().equals(CompoundMessage.class)) { bulk.addAll(((CompoundMessage) message).asList()); } else { bulk.add(message); } bulkWeight += message.getWeight(); if (logger.isDebugEnabled()) { if (logMap.get(message.getClass().getSimpleName()) == null) logMap.put(message.getClass().getSimpleName(), new AtomicInteger(1)); else logMap.get(message.getClass().getSimpleName()).incrementAndGet(); } if (bulkWeight > maxBulkWeight) { if (logger.isDebugEnabled()) logger.debug("trying to drain bulk: " + logMap.toString() + ", W:" + bulkWeight); drainBulk(bulk); bulk.clear(); bulkWeight = 0; logMap.clear(); } } // drain the last bulk if (logger.isDebugEnabled()) logger.debug("trying to drain bulk: " + logMap.toString() + ", " + getStatus()); drainBulk(bulk); } catch (Exception ex) { logger.error("Failed to drain buffer, invoking worker internal recovery... ", ex); recoveryManager.doRecovery(); } }
From source file:com.espertech.esper.core.EPRuntimeImpl.java
private void processScheduleHandles(ArrayBackedCollection<ScheduleHandle> handles) { if (ThreadLogUtil.ENABLED_TRACE) { ThreadLogUtil.trace("Found schedules for", handles.size()); }//from www.j a v a2s. c o m if (handles.size() == 0) { return; } // handle 1 result separatly for performance reasons if (handles.size() == 1) { Object[] handleArray = handles.getArray(); EPStatementHandleCallback handle = (EPStatementHandleCallback) handleArray[0]; if ((MetricReportingPath.isMetricsEnabled) && (handle.getEpStatementHandle().getMetricsHandle().isEnabled())) { long cpuTimeBefore = MetricUtil.getCPUCurrentThread(); long wallTimeBefore = MetricUtil.getWall(); processStatementScheduleSingle(handle, services, engineFilterAndDispatchTimeContext); long wallTimeAfter = MetricUtil.getWall(); long cpuTimeAfter = MetricUtil.getCPUCurrentThread(); long deltaCPU = cpuTimeAfter - cpuTimeBefore; long deltaWall = wallTimeAfter - wallTimeBefore; services.getMetricsReportingService().accountTime(handle.getEpStatementHandle().getMetricsHandle(), deltaCPU, deltaWall, 1); } else { if ((ThreadingOption.isThreadingEnabled) && (services.getThreadingService().isTimerThreading())) { services.getThreadingService().submitTimerWork( new TimerUnitSingle(services, this, handle, this.engineFilterAndDispatchTimeContext)); } else { processStatementScheduleSingle(handle, services, engineFilterAndDispatchTimeContext); } } handles.clear(); return; } Object[] matchArray = handles.getArray(); int entryCount = handles.size(); // sort multiple matches for the event into statements Map<EPStatementHandle, Object> stmtCallbacks = schedulePerStmtThreadLocal.get(); stmtCallbacks.clear(); for (int i = 0; i < entryCount; i++) // need to use the size of the collection { EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) matchArray[i]; EPStatementHandle handle = handleCallback.getEpStatementHandle(); ScheduleHandleCallback callback = handleCallback.getScheduleCallback(); Object entry = stmtCallbacks.get(handle); // This statement has not been encountered before if (entry == null) { stmtCallbacks.put(handle, callback); continue; } // This statement has been encountered once before if (entry instanceof ScheduleHandleCallback) { ScheduleHandleCallback existingCallback = (ScheduleHandleCallback) entry; ArrayDeque<ScheduleHandleCallback> entries = new ArrayDeque<ScheduleHandleCallback>(); entries.add(existingCallback); entries.add(callback); stmtCallbacks.put(handle, entries); continue; } // This statement has been encountered more then once before ArrayDeque<ScheduleHandleCallback> entries = (ArrayDeque<ScheduleHandleCallback>) entry; entries.add(callback); } handles.clear(); for (Map.Entry<EPStatementHandle, Object> entry : stmtCallbacks.entrySet()) { EPStatementHandle handle = entry.getKey(); Object callbackObject = entry.getValue(); if ((MetricReportingPath.isMetricsEnabled) && (handle.getMetricsHandle().isEnabled())) { long cpuTimeBefore = MetricUtil.getCPUCurrentThread(); long wallTimeBefore = MetricUtil.getWall(); processStatementScheduleMultiple(handle, callbackObject, services, this.engineFilterAndDispatchTimeContext); long wallTimeAfter = MetricUtil.getWall(); long cpuTimeAfter = MetricUtil.getCPUCurrentThread(); long deltaCPU = cpuTimeAfter - cpuTimeBefore; long deltaWall = wallTimeAfter - wallTimeBefore; int numInput = (callbackObject instanceof Collection) ? ((Collection) callbackObject).size() : 1; services.getMetricsReportingService().accountTime(handle.getMetricsHandle(), deltaCPU, deltaWall, numInput); } else { if ((ThreadingOption.isThreadingEnabled) && (services.getThreadingService().isTimerThreading())) { services.getThreadingService().submitTimerWork(new TimerUnitMultiple(services, this, handle, callbackObject, this.engineFilterAndDispatchTimeContext)); } else { processStatementScheduleMultiple(handle, callbackObject, services, this.engineFilterAndDispatchTimeContext); } } if ((isPrioritized) && (handle.isPreemptive())) { break; } } }
From source file:com.esd.ps.EmployerController.java
@RequestMapping(value = "/updatePackTypeId", method = RequestMethod.POST) @ResponseBody/*from w ww .ja v a2s . c o m*/ public Map<String, Object> updatePackTypeIdPOST(int packId, int packTypeId) { Map<String, Object> map = new HashMap<>(); packWithBLOBs pack = new packWithBLOBs(); pack.setPackId(packId); pack.setPackType(packTypeId); packService.updateByPrimaryKeySelective(pack); map.clear(); map.put(Constants.REPLAY, 1); return map; }
From source file:com.esd.ps.EmployerController.java
/** * // ww w . ja va 2 s. c o m * @param packId * @param markTimeMethodId * @return */ @RequestMapping(value = "/updateMarkTimeMethod", method = RequestMethod.POST) @ResponseBody public Map<String, Object> updateMarkTimeMethodPOST(int packId, int markTimeMethodId) { Map<String, Object> map = new HashMap<>(); packWithBLOBs pack = new packWithBLOBs(); pack.setPackId(packId); pack.setTaskMarkTimeId(markTimeMethodId); packService.updateByPrimaryKeySelective(pack); map.clear(); map.put(Constants.REPLAY, 1); return map; }
From source file:broadwick.Broadwick.java
/** * Create and register the models internally. If there was a problem registering the models an empty cache is * returned.// w w w . j a va 2 s .com * <p> * @param project the unmarshalled configuration file. * @param lookup the Lookuup object that allows the model to access the data specified in the data files. * @return the registered models. */ private Map<String, Model> registerModels(final Project project, final Lookup lookup) { final Map<String, Model> registeredModels = new HashMap<>(); try { for (Models.Model model : project.getModels().getModel()) { // Create and register the new model object that we will be running later. final Model newInstance = Model.class.cast(Class.forName(model.getClassname()).newInstance()); newInstance .setModelConfiguration(getModelsConfiguration(model.getId(), getAllModelConfigurations())); newInstance.setModelDataLookup(lookup); newInstance.setModelParameters(model.getParameter()); if (model.getPriors() != null) { newInstance.setModelPriors(model.getPriors().getGaussianPriorAndUniformPrior()); } registeredModels.put(model.getId(), newInstance); } } catch (ParserConfigurationException | SAXException | IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) { log.error("Could not create model ; {}", ex.getLocalizedMessage()); registeredModels.clear(); } return registeredModels; }
From source file:com.amazonaws.services.kinesis.aggregators.datastore.DynamoDataStore.java
public UpdateItemResult updateConditionalValue(final AmazonDynamoDB dynamoClient, final String tableName, final UpdateKey key, final String attribute, final AggregateAttributeModification update) throws Exception { Map<String, AttributeValue> updateKey = StreamAggregatorUtils.getTableKey(key); UpdateItemResult result;/* ww w . java2s .com*/ final ReturnValue returnValue = ReturnValue.UPDATED_NEW; final String setAttribute = StreamAggregatorUtils.methodToColumn(attribute); // create the update that we want to write final Map<String, AttributeValueUpdate> thisCalcUpdate = new HashMap<String, AttributeValueUpdate>() { { put(setAttribute, new AttributeValueUpdate().withAction(AttributeAction.PUT) .withValue(new AttributeValue().withN("" + update.getFinalValue()))); } }; // create the request UpdateItemRequest req = new UpdateItemRequest().withTableName(tableName).withKey(updateKey) .withReturnValues(returnValue).withAttributeUpdates(thisCalcUpdate); Map<String, ExpectedAttributeValue> expected = new HashMap<>(); final SummaryCalculation calc = update.getCalculationApplied(); // try an update to PUT the value if NOT EXISTS, to establish if we // are the first writer for this key expected = new HashMap<String, ExpectedAttributeValue>() { { put(setAttribute, new ExpectedAttributeValue().withExists(false)); } }; req.setExpected(expected); try { result = DynamoUtils.updateWithRetries(dynamoClient, req); // yay - we were the first writer, so our value was written return result; } catch (ConditionalCheckFailedException e1) { // set the expected to the comparison contained in the update // calculation expected.clear(); expected.put(setAttribute, new ExpectedAttributeValue().withComparisonOperator(calc.getDynamoComparisonOperator()) .withValue(new AttributeValue().withN("" + update.getFinalValue()))); req.setExpected(expected); // do the conditional update on the summary // calculation. this may result in no update being // applied because the new value is greater than the // current minimum for MIN, or less than the current // maximum for MAX. try { result = DynamoUtils.updateWithRetries(dynamoClient, req); return result; } catch (ConditionalCheckFailedException e2) { // no worries - we just weren't the min or max! return null; } } }