List of usage examples for java.util LinkedList clear
public void clear()
From source file:com.commander4j.thread.InboundMessageThread.java
public void run() { logger.debug("InboundMessageThread running"); Boolean dbconnected = false;/* www. j a v a 2s .co m*/ if (Common.hostList.getHost(hostID).isConnected(sessionID) == false) { dbconnected = Common.hostList.getHost(hostID).connect(sessionID, hostID); } else { dbconnected = true; } if (dbconnected) { JDBInterfaceLog il = new JDBInterfaceLog(getHostID(), getSessionID()); JeMail mail = new JeMail(getHostID(), getSessionID()); JDBInterface inter = new JDBInterface(getHostID(), getSessionID()); IncommingMaterialDefinition imd = new IncommingMaterialDefinition(getHostID(), getSessionID()); IncommingProcessOrderStatusChange iposc = new IncommingProcessOrderStatusChange(getHostID(), getSessionID()); IncommingProductionDeclarationConfirmation ipd = new IncommingProductionDeclarationConfirmation( getHostID(), getSessionID()); IncommingProcessOrder ipo = new IncommingProcessOrder(getHostID(), getSessionID()); IncommingLocation ilocn = new IncommingLocation(getHostID(), getSessionID()); IncommingPalletStatusChange ipsc = new IncommingPalletStatusChange(getHostID(), getSessionID()); IncommingPalletMove ipmv = new IncommingPalletMove(getHostID(), getSessionID()); IncommingBatchStatusChange bsc = new IncommingBatchStatusChange(getHostID(), getSessionID()); IncommingJourney ij = new IncommingJourney(getHostID(), getSessionID()); IncommingInspectionResult iirslt = new IncommingInspectionResult(getHostID(), getSessionID()); IncommingDespatchConfirmation idc = new IncommingDespatchConfirmation(getHostID(), getSessionID()); IncommingQMInspectionRequest iireq = new IncommingQMInspectionRequest(getHostID(), getSessionID()); IncommingMaterialAutoMove imam = new IncommingMaterialAutoMove(getHostID(), getSessionID()); GenericMessageHeader gmh = new GenericMessageHeader(); LinkedList<String> filenames = new LinkedList<String>(); BasicFileAttributes attrs; while (true) { com.commander4j.util.JWait.milliSec(100); if (allDone) { if (dbconnected) { Common.hostList.getHost(hostID).disconnect(getSessionID()); } return; } if (InboundMessageCollectionThread.recoveringFiles == false) { dir = new File(inputPath); chld = dir.listFiles((FileFilter) FileFileFilter.FILE); if (chld == null) { allDone = true; } else { Arrays.sort(chld, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); filenames.clear(); for (int i = 0; (i < chld.length) & (i < maxfiles); i++) { fileName = chld[i].getName(); try { attrs = Files.readAttributes(chld[i].getAbsoluteFile().toPath(), BasicFileAttributes.class); if (attrs.size() > 0) { if (fileName.endsWith(".xml")) { filenames.addFirst(fileName); com.commander4j.util.JWait.milliSec(50); } } else { try { chld[i].delete(); } catch (Exception ex) { } } } catch (IOException e) { } } if (filenames.size() > 0) { logger.debug("Begin processing " + String.valueOf(filenames.size()) + " files."); for (int i = filenames.size() - 1; i >= 0; i--) { if (allDone) { if (dbconnected) { Common.hostList.getHost(hostID).disconnect(getSessionID()); } return; } fromFile = filenames.get(i); try { logger.debug("<--- START OF PROCESSING " + fromFile + " ---->"); logger.debug("Reading message header : " + inputPath + fromFile); if (gmh.readAddressInfo(inputPath + fromFile, getSessionID()) == true) { messageProcessedOK = true; errorMessage = ""; if (gmh.getInterfaceType().length() == 0) { messageProcessedOK = false; errorMessage = "Unrecognised Commander4j XML message format in file " + fromFile; logger.debug(errorMessage); String datetime = ""; datetime = JUtility .getISOTimeStampStringFormat(JUtility.getSQLDateTime()); gmh.setMessageDate(datetime); gmh.setInterfaceDirection("Unknown"); gmh.setMessageInformation(fromFile); gmh.setInterfaceType("Unknown"); gmh.setMessageRef("Unknown"); } else { if (gmh.getInterfaceDirection().equals("Input") == false) { messageProcessedOK = false; errorMessage = "Inbound message ignored - Interface Direction = " + gmh.getInterfaceDirection(); } else { String interfaceType = gmh.getInterfaceType(); logger.debug("Processing " + interfaceType + " started."); if (interfaceType.equals("Despatch Confirmation") == true) { messageProcessedOK = idc.processMessage(gmh); errorMessage = idc.getErrorMessage(); } if (interfaceType.equals("Material Definition") == true) { messageProcessedOK = imd.processMessage(gmh); errorMessage = imd.getErrorMessage(); } if (interfaceType.equals("Process Order") == true) { messageProcessedOK = ipo.processMessage(gmh); errorMessage = ipo.getErrorMessage(); } if (interfaceType.equals("Location") == true) { messageProcessedOK = ilocn.processMessage(gmh); errorMessage = ilocn.getErrorMessage(); } if (interfaceType.equals("Pallet Status Change") == true) { messageProcessedOK = ipsc.processMessage(gmh); errorMessage = ipsc.getErrorMessage(); } if (interfaceType.equals("Pallet Move") == true) { messageProcessedOK = ipmv.processMessage(gmh); errorMessage = ipmv.getErrorMessage(); } if (interfaceType.equals("Batch Status Change") == true) { messageProcessedOK = bsc.processMessage(gmh); errorMessage = bsc.getErrorMessage(); } if (interfaceType.equals("Journey Definition") == true) { messageProcessedOK = ij.processMessage(gmh); errorMessage = ij.getErrorMessage(); } if (interfaceType.equals("Process Order Status Change") == true) { messageProcessedOK = iposc.processMessage(gmh); errorMessage = iposc.getErrorMessage(); } if (interfaceType.equals("Production Declaration") == true) { messageProcessedOK = ipd.processMessage(gmh); errorMessage = ipd.getErrorMessage(); } if (interfaceType.equals("QM Inspection Request") == true) { messageProcessedOK = iireq.processMessage(gmh); errorMessage = iireq.getErrorMessage(); } if (interfaceType.equals("QM Inspection Result") == true) { messageProcessedOK = iirslt.processMessage(gmh); errorMessage = iirslt.getErrorMessage(); } if (interfaceType.equals("Material Auto Move") == true) { messageProcessedOK = imam.processMessage(gmh); errorMessage = imam.getErrorMessage(); } GenericMessageHeader.updateStats("Input", interfaceType, messageProcessedOK.toString()); logger.debug("Processing " + interfaceType + " finished."); } } logger.debug( " === RESULT " + messageProcessedOK.toString() + " ==="); if (messageProcessedOK) { il.write(gmh, GenericMessageHeader.msgStatusSuccess, "Processed OK", "DB Update", fromFile); reader.deleteFile(backupPath + gmh.getInterfaceType() + File.separator + fromFile); reader.move_FileToDirectory(inputPath + fromFile, backupPath + gmh.getInterfaceType(), true); } else { il.write(gmh, GenericMessageHeader.msgStatusError, errorMessage, "DB Update", fromFile); if (inter.getInterfaceProperties(gmh.getInterfaceType(), "Input") == true) { if (inter.getEmailError() == true) { String emailaddresses = inter.getEmailAddresses(); StringConverter stringConverter = new StringConverter(); ArrayConverter arrayConverter = new ArrayConverter( String[].class, stringConverter); arrayConverter.setDelimiter(';'); arrayConverter.setAllowedChars(new char[] { '@', '_' }); String[] emailList = (String[]) arrayConverter .convert(String[].class, emailaddresses); if (emailList.length > 0) { String siteName = Common.hostList.getHost(getHostID()) .getSiteDescription(); String attachedFilename = Common.base_dir + java.io.File.separator + inputPath + fromFile; logger.debug("Attaching file " + Common.base_dir + java.io.File.separator + inputPath + fromFile); mail.postMail(emailList, "Error Processing Incoming " + gmh.getInterfaceType() + " for [" + siteName + "] on " + JUtility.getClientName(), errorMessage, fromFile, attachedFilename); com.commander4j.util.JWait.milliSec(2000); } } } reader.deleteFile( errorPath + gmh.getInterfaceType() + File.separator + fromFile); reader.move_FileToDirectory(inputPath + fromFile, errorPath + gmh.getInterfaceType(), true); } } logger.debug("<--- END OF PROCESSING " + fromFile + " ---->"); } catch (Exception e) { e.printStackTrace(); } } } } } } } }
From source file:net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper.java
/** * find driver jar path from 'temp\dbWizard',if nof found,find it from 'lib\java' and "librariesIndex.xml". * //from w w w .j av a2s. c om * @return * @throws MalformedURLException */ public LinkedList<String> getDriverJarRealPaths(List<String> driverJarNameList) throws MalformedURLException { LinkedList<String> linkedList = new LinkedList<String>(); initLibManagerServic(); boolean jarNotFound = false; for (String jarName : driverJarNameList) { String tempLibPath = ExtractMetaDataUtils.getInstance().getJavaLibPath(); File tempFolder = new File(tempLibPath); if (tempFolder.exists()) { List<File> jarFiles = FilesUtils.getJarFilesFromFolder(tempFolder, jarName); if (!jarFiles.isEmpty()) { linkedList.add(jarFiles.get(0).getPath()); continue; } } if (libManagerServic != null) { String libPath = libManagerServic.getJarPath(jarName); if (libPath == null) { jarNotFound = true; break; } linkedList.add(libPath); } else { jarNotFound = true; } } // if has one jar file not be found,return a empty list if (jarNotFound) { linkedList.clear(); } return linkedList; }
From source file:com.commander4j.db.JDBDespatch.java
public LinkedList<JDBDespatch> browseDespatchData(String status, int limit) { String temp = ""; Boolean top = false;// w w w . j a va2 s . c o m PreparedStatement stmt = null; LinkedList<JDBDespatch> result = new LinkedList<JDBDespatch>(); ResultSet rs; result.clear(); try { temp = Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBDespatch.browse"); if (temp.indexOf("[top]") >= 0) { top = true; temp = temp.replace("[top]", "top " + String.valueOf(limit)); } stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(temp); stmt.setFetchSize(100); stmt.setString(1, status); if (top == false) { stmt.setInt(2, limit); } rs = stmt.executeQuery(); while (rs.next()) { result.addLast(new JDBDespatch(getHostID(), getSessionID(), rs.getString("despatch_no"), rs.getTimestamp("despatch_date"), rs.getString("location_id_from"), rs.getString("location_id_to"), rs.getString("status"), rs.getInt("total_pallets"), rs.getString("trailer"), rs.getString("haulier"), rs.getString("load_no"), rs.getString("user_id"), rs.getString("journey_ref"))); } rs.close(); stmt.close(); } catch (SQLException e) { setErrorMessage(e.getMessage()); } return result; }
From source file:userinterface.graph.Graph.java
/** * Remove all points from a graph series and its cache. * /* ww w. j a v a2 s .co m*/ * @param seriesKey * Key of series to update. */ public void removeAllPoints(SeriesKey seriesKey) { synchronized (seriesCollection) { if (graphCache.containsKey(seriesKey)) { LinkedList<XYDataItem> seriesCache = graphCache.get(seriesKey); seriesCache.clear(); } if (keyToSeries.containsKey(seriesKey)) { XYSeries series = keyToSeries.get(seriesKey); series.clear(); } } }
From source file:com.att.nsa.cambria.service.impl.MMServiceImpl.java
private void pushEvents(DMaaPContext ctx, String topic, InputStream msg, String defaultPartition, boolean chunked, String mediaType) throws ConfigDbException, AccessDeniedException, TopicExistsException, CambriaApiException, IOException { final MetricsSet metricsSet = ctx.getConfigReader().getfMetrics(); // setup the event set final CambriaEventSet events = new CambriaEventSet(mediaType, msg, chunked, defaultPartition); // start processing, building a batch to push to the backend final long startMs = System.currentTimeMillis(); long count = 0; long maxEventBatch = 1024 * 16; String batchlen = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, BATCH_LENGTH); if (null != batchlen) maxEventBatch = Long.parseLong(batchlen); // long maxEventBatch = // ctx.getConfigReader().getSettings().getLong(BATCH_LENGTH, 1024 * 16); final LinkedList<Publisher.message> batch = new LinkedList<Publisher.message>(); final ArrayList<KeyedMessage<String, String>> kms = new ArrayList<KeyedMessage<String, String>>(); try {//from ww w. j av a 2s. co m // for each message... Publisher.message m = null; while ((m = events.next()) != null) { // add the message to the batch batch.add(m); final KeyedMessage<String, String> data = new KeyedMessage<String, String>(topic, m.getKey(), m.getMessage()); kms.add(data); // check if the batch is full final int sizeNow = batch.size(); if (sizeNow > maxEventBatch) { ctx.getConfigReader().getfPublisher().sendBatchMessage(topic, kms); kms.clear(); batch.clear(); metricsSet.publishTick(sizeNow); count += sizeNow; } } // send the pending batch final int sizeNow = batch.size(); if (sizeNow > 0) { ctx.getConfigReader().getfPublisher().sendBatchMessage(topic, kms); kms.clear(); batch.clear(); metricsSet.publishTick(sizeNow); count += sizeNow; } final long endMs = System.currentTimeMillis(); final long totalMs = endMs - startMs; LOG.info("Published " + count + " msgs in " + totalMs + "ms for topic " + topic); // build a responseP final JSONObject response = new JSONObject(); response.put("count", count); response.put("serverTimeMs", totalMs); // DMaaPResponseBuilder.respondOk(ctx, response); } catch (Exception excp) { int status = HttpStatus.SC_NOT_FOUND; String errorMsg = null; if (excp instanceof CambriaApiException) { status = ((CambriaApiException) excp).getStatus(); JSONTokener jsonTokener = new JSONTokener(((CambriaApiException) excp).getBody()); JSONObject errObject = new JSONObject(jsonTokener); errorMsg = (String) errObject.get("message"); } ErrorResponse errRes = new ErrorResponse(status, DMaaPResponseCode.PARTIAL_PUBLISH_MSGS.getResponseCode(), errorMessages.getPublishMsgError() + ":" + topic + "." + errorMessages.getPublishMsgCount() + count + "." + errorMsg, null, Utils.getFormattedDate(new Date()), topic, null, ctx.getRequest().getRemoteHost(), null, null); LOG.info(errRes.toString()); throw new CambriaApiException(errRes); } }
From source file:com.commander4j.db.JDBDespatch.java
public boolean delete() { PreparedStatement stmtupdate; boolean result = false; setErrorMessage(""); logger.debug("delete [" + getDespatchNo() + "]"); LinkedList<String> assignedList = new LinkedList<String>(); JDBPallet pal = new JDBPallet(getHostID(), getSessionID()); if (isValid(false) == true) { String journeyRef = getJourneyRef(); assignedList.clear(); assignedList.addAll(getAssignedSSCCs()); if (assignedList.size() > 0) { for (int j = 0; j < assignedList.size(); j++) { if (pal.getPalletProperties(assignedList.get(j))) { pal.setDespatchNo(""); pal.update();/*from ww w.j ava 2 s . co m*/ } } } try { stmtupdate = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement( Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBDespatch.delete")); stmtupdate.setString(1, getDespatchNo()); stmtupdate.execute(); stmtupdate.clearParameters(); Common.hostList.getHost(getHostID()).getConnection(getSessionID()).commit(); stmtupdate.close(); if (journeyRef.equals("") == false) { JDBJourney jrny = new JDBJourney(getHostID(), getSessionID()); if (jrny.getJourneyRefProperties(journeyRef)) { jrny.setStatus("Unassigned"); jrny.setDespatchNo(""); jrny.update(); } } result = true; } catch (SQLException e) { setErrorMessage(e.getMessage()); } } return result; }
From source file:org.talend.cwm.db.connection.ConnectionUtils.java
/** * find driver jar path from 'temp\dbWizard',if nof found,find it from 'lib\java' and "librariesIndex.xml". * // ww w . j av a 2 s.com * @return * @throws MalformedURLException */ public static LinkedList<String> getDriverJarRealPaths(List<String> driverJarNameList) throws MalformedURLException { LinkedList<String> linkedList = new LinkedList<String>(); boolean jarNotFound = false; for (String jarName : driverJarNameList) { String tempLibPath = ExtractMetaDataUtils.getInstance().getJavaLibPath(); File tempFolder = new File(tempLibPath); if (tempFolder.exists()) { List<File> jarFiles = FilesUtils.getJarFilesFromFolder(tempFolder, jarName); if (!jarFiles.isEmpty()) { linkedList.add(jarFiles.get(0).getPath()); continue; } } if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) { ILibraryManagerService libManagerServic = (ILibraryManagerService) GlobalServiceRegister .getDefault().getService(ILibraryManagerService.class); String libPath = libManagerServic.getJarPath(jarName); if (libPath == null) { jarNotFound = true; break; } linkedList.add(libPath); } else { jarNotFound = true; } } // if has one jar file not be found,return a empty list if (jarNotFound) { linkedList.clear(); } return linkedList; }
From source file:com.att.nsa.cambria.service.impl.EventsServiceImpl.java
/** * //from w w w . j a va 2s. c o m * @param ctx * @param topic * @param msg * @param defaultPartition * @param chunked * @param mediaType * @throws ConfigDbException * @throws AccessDeniedException * @throws TopicExistsException * @throws CambriaApiException * @throws IOException */ private void pushEvents(DMaaPContext ctx, String topic, InputStream msg, String defaultPartition, boolean chunked, String mediaType) throws ConfigDbException, AccessDeniedException, TopicExistsException, CambriaApiException, IOException { final MetricsSet metricsSet = ctx.getConfigReader().getfMetrics(); // setup the event set final CambriaEventSet events = new CambriaEventSet(mediaType, msg, chunked, defaultPartition); // start processing, building a batch to push to the backend final long startMs = System.currentTimeMillis(); long count = 0; long maxEventBatch = 1024 * 16; String batchlen = AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, BATCH_LENGTH); if (null != batchlen) maxEventBatch = Long.parseLong(batchlen); // long maxEventBatch = ctx.getConfigReader().getSettings().getLong(BATCH_LENGTH, 1024 * 16); final LinkedList<Publisher.message> batch = new LinkedList<Publisher.message>(); final ArrayList<KeyedMessage<String, String>> kms = new ArrayList<KeyedMessage<String, String>>(); try { // for each message... Publisher.message m = null; while ((m = events.next()) != null) { // add the message to the batch batch.add(m); final KeyedMessage<String, String> data = new KeyedMessage<String, String>(topic, m.getKey(), m.getMessage()); kms.add(data); // check if the batch is full final int sizeNow = batch.size(); if (sizeNow > maxEventBatch) { ctx.getConfigReader().getfPublisher().sendBatchMessage(topic, kms); kms.clear(); batch.clear(); metricsSet.publishTick(sizeNow); count += sizeNow; } } // send the pending batch final int sizeNow = batch.size(); if (sizeNow > 0) { ctx.getConfigReader().getfPublisher().sendBatchMessage(topic, kms); kms.clear(); batch.clear(); metricsSet.publishTick(sizeNow); count += sizeNow; } final long endMs = System.currentTimeMillis(); final long totalMs = endMs - startMs; LOG.info("Published " + count + " msgs in " + totalMs + "ms for topic " + topic); // build a responseP final JSONObject response = new JSONObject(); response.put("count", count); response.put("serverTimeMs", totalMs); DMaaPResponseBuilder.respondOk(ctx, response); } catch (Exception excp) { int status = HttpStatus.SC_NOT_FOUND; String errorMsg = null; if (excp instanceof CambriaApiException) { status = ((CambriaApiException) excp).getStatus(); JSONTokener jsonTokener = new JSONTokener(((CambriaApiException) excp).getBody()); JSONObject errObject = new JSONObject(jsonTokener); errorMsg = (String) errObject.get("message"); } ErrorResponse errRes = new ErrorResponse(status, DMaaPResponseCode.PARTIAL_PUBLISH_MSGS.getResponseCode(), errorMessages.getPublishMsgError() + ":" + topic + "." + errorMessages.getPublishMsgCount() + count + "." + errorMsg, null, Utils.getFormattedDate(new Date()), topic, null, ctx.getRequest().getRemoteHost(), null, null); LOG.info(errRes.toString()); throw new CambriaApiException(errRes); } }
From source file:com.commander4j.db.JDBDespatch.java
public LinkedList<JDBEquipmentList> getEquipment() { LinkedList<JDBEquipmentList> result = new LinkedList<JDBEquipmentList>(); PreparedStatement stmt = null; ResultSet rs;//from w w w . j a va 2s. co m String temp = ""; try { temp = Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBDespatch.equipment"); stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(temp); stmt.setFetchSize(25); stmt.setString(1, getDespatchNo()); rs = stmt.executeQuery(); result.clear(); while (rs.next()) { result.addLast(new JDBEquipmentList(rs.getString("equipment_type"), rs.getInt("total"))); } rs.close(); stmt.close(); } catch (SQLException e) { setErrorMessage(e.getMessage()); } return result; }