protected static void PrintUserInfoList() { Collection<UserID> collection = registeredUsers.values(); Iterator<UserID> it = collection.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }
private void startNewDownloads() { boolean isLimited = true; int currentAllowedDownloadCount = 0; { final int allowedConcurrentDownloads = Core.frostSettings.getIntValue(SettingsClass.DOWNLOAD_MAX_THREADS); if (allowedConcurrentDownloads <= 0) { isLimited = false; } else { int runningDownloads = 0; for (final FrostDownloadItem dlItem : downloadModelItems.values()) { if (!dlItem.isExternal() && dlItem.getState() == FrostDownloadItem.STATE_PROGRESS) { runningDownloads++; } } currentAllowedDownloadCount = allowedConcurrentDownloads - runningDownloads; if (currentAllowedDownloadCount < 0) { currentAllowedDownloadCount = 0; } } } { while (!isLimited || currentAllowedDownloadCount > 0) { final FrostDownloadItem dlItem = FileTransferManager.inst().getDownloadManager().selectNextDownloadItem(); if (dlItem == null) { break; } // start the download if (startDownload(dlItem)) { currentAllowedDownloadCount--; } } } }
/** * Assigns the given certificate to the given alias. * * <p>If the given alias already exists in this keystore and identifies a <i>trusted certificate * entry</i>, the certificate associated with it is overridden by the given certificate. * * @param alias the alias name * @param cert the certificate * @exception KeyStoreException if the given alias already exists and does not identify a * <i>trusted certificate entry</i>, or this operation fails for some other reason. */ public void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException { permissionCheck(); synchronized (entries) { Object entry = entries.get(alias.toLowerCase()); if ((entry != null) && (entry instanceof KeyEntry)) { throw new KeyStoreException("Cannot overwrite key entry with certificate"); } // This will be slow, but necessary. Enumerate the values and then see if the cert matches // the one in the trusted cert entry. // Security framework doesn't support the same certificate twice in a keychain. Collection<Object> allValues = entries.values(); for (Object value : allValues) { if (value instanceof TrustedCertEntry) { TrustedCertEntry tce = (TrustedCertEntry) value; if (tce.cert.equals(cert)) { throw new KeyStoreException( "Keychain does not support mulitple copies of same certificate."); } } } TrustedCertEntry trustedCertEntry = new TrustedCertEntry(); trustedCertEntry.cert = cert; trustedCertEntry.date = new Date(); String lowerAlias = alias.toLowerCase(); if (entries.get(lowerAlias) != null) { deletedEntries.put(lowerAlias, entries.get(lowerAlias)); } entries.put(lowerAlias, trustedCertEntry); addedEntries.put(lowerAlias, trustedCertEntry); } }
/** Closes all open sockets and stops the internal server thread that processes messages. */ public void close() { ServerThread st = server; if (st != null) { st.close(); try { st.join(); } catch (InterruptedException ex) { logger.warn(ex); } server = null; for (Iterator it = sockets.values().iterator(); it.hasNext(); ) { SocketEntry entry = (SocketEntry) it.next(); try { synchronized (entry) { entry.getSocket().close(); } logger.debug("Socket to " + entry.getPeerAddress() + " closed"); } catch (IOException iox) { // ingore logger.debug(iox); } } if (socketCleaner != null) { socketCleaner.cancel(); } socketCleaner = null; } }
/** * Creates a shallow copy of this hashtable. All the structure of the hashtable itself is copied, * but the keys and values are not cloned. This is a relatively expensive operation. * * @return a clone of the hashtable */ public synchronized Object clone() { try { Hashtable<?, ?> t = (Hashtable<?, ?>) super.clone(); t.table = new Entry<?, ?>[table.length]; for (int i = table.length; i-- > 0; ) { t.table[i] = (table[i] != null) ? (Entry<?, ?>) table[i].clone() : null; } t.keySet = null; t.entrySet = null; t.values = null; t.modCount = 0; return t; } catch (CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw new InternalError(e); } }
/** * Check if components required by specified products are available. * * @param products list of ProdOrderProductVO objects * @params compAltComps collection of <component item code,HashSet of alternative component item * codes>; filled by this method (and given back by reference) * @return VOListResponse of ProdOrderComponentVO objects */ public final Response checkComponentsAvailability( Connection conn, Hashtable compAltComps, ArrayList products, UserSessionParameters userSessionPars, HttpServletRequest request, HttpServletResponse response, HttpSession userSession, ServletContext context) { String serverLanguageId = ((JAIOUserSessionParameters) userSessionPars).getServerLanguageId(); try { // retrieve internationalization settings (Resources object)... ServerResourcesFactory factory = (ServerResourcesFactory) context.getAttribute(Controller.RESOURCES_FACTORY); Resources resources = factory.getResources(userSessionPars.getLanguageId()); if (products.size() == 0) { return new VOListResponse(new ArrayList(), false, 0); } // fill in comps hashtable with the collection of required components... ItemPK pk = null; ProdOrderProductVO prodVO = null; ArrayList components = null; MaterialVO compVO = null; Response res = null; ProdOrderComponentVO componentVO = null; Hashtable comps = new Hashtable(); // collection of <component item code,ProdOrderComponentVO object> for (int i = 0; i < products.size(); i++) { // retrieve bill of materials for each product... prodVO = (ProdOrderProductVO) products.get(i); pk = new ItemPK(prodVO.getCompanyCodeSys01DOC23(), prodVO.getItemCodeItm01DOC23()); res = bean.getBillOfMaterials( conn, pk, userSessionPars, request, response, userSession, context); if (res.isError()) { return res; } // extract components only (leaf nodes)... components = getComponents( (DefaultMutableTreeNode) ((TreeModel) ((VOResponse) res).getVo()).getRoot()); for (int j = 0; j < components.size(); j++) { compVO = (MaterialVO) components.get(j); componentVO = (ProdOrderComponentVO) comps.get(compVO.getItemCodeItm01ITM03()); if (componentVO == null) { componentVO = new ProdOrderComponentVO(); comps.put(compVO.getItemCodeItm01ITM03(), componentVO); componentVO.setAvailableQty(new BigDecimal(0)); componentVO.setCompanyCodeSys01DOC24(compVO.getCompanyCodeSys01ITM03()); componentVO.setDescriptionSYS10(compVO.getDescriptionSYS10()); componentVO.setDocNumberDOC24(prodVO.getDocNumberDOC23()); componentVO.setDocYearDOC24(prodVO.getDocYearDOC23()); componentVO.setItemCodeItm01DOC24(compVO.getItemCodeItm01ITM03()); componentVO.setMinSellingQtyUmCodeReg02ITM01(compVO.getMinSellingQtyUmCodeReg02ITM01()); componentVO.setQtyDOC24(new BigDecimal(0)); } componentVO.setQtyDOC24( componentVO.getQtyDOC24().add(compVO.getQtyITM03().multiply(prodVO.getQtyDOC23()))); } } // check components availability in the specified warehouse... Enumeration en = comps.keys(); GridParams gridParams = new GridParams(); gridParams .getOtherGridParams() .put(ApplicationConsts.COMPANY_CODE_SYS01, prodVO.getCompanyCodeSys01DOC23()); gridParams .getOtherGridParams() .put(ApplicationConsts.WAREHOUSE_CODE, prodVO.getWarehouseCodeWar01DOC22()); gridParams.getOtherGridParams().put(ApplicationConsts.LOAD_ALL, Boolean.TRUE); ItemAvailabilityVO availVO = null; BigDecimal availability, altAvailability, delta; String itemCode = null; ArrayList list, availList; AltComponentVO altVO = null; ArrayList alternativeComps = new ArrayList(); ArrayList compsToRemove = new ArrayList(); ProdOrderComponentVO altComponentVO = null; HashSet altCodes = null; // list of alternative component item codes... BigDecimal altQty = null; while (en.hasMoreElements()) { itemCode = en.nextElement().toString(); componentVO = (ProdOrderComponentVO) comps.get(itemCode); gridParams .getOtherGridParams() .put( ApplicationConsts.ITEM_PK, new ItemPK(prodVO.getCompanyCodeSys01DOC23(), itemCode)); res = avail.executeCommand( gridParams, userSessionPars, request, response, userSession, context); if (res.isError()) return res; availList = ((VOListResponse) res).getRows(); componentVO.setAvailabilities(availList); availability = new BigDecimal(0); for (int i = 0; i < availList.size(); i++) { availVO = (ItemAvailabilityVO) availList.get(i); availability = availability.add(availVO.getAvailableQtyWAR03()); } componentVO.setAvailableQty(availability); if (componentVO.getQtyDOC24().doubleValue() > componentVO.getAvailableQty().doubleValue()) { // check if there exist some alternative component... res = altComps.executeCommand( gridParams, userSessionPars, request, response, userSession, context); if (res.isError()) return res; list = ((VOListResponse) res).getRows(); for (int i = 0; i < list.size(); i++) { altVO = (AltComponentVO) list.get(i); gridParams .getOtherGridParams() .put( ApplicationConsts.ITEM_PK, new ItemPK(prodVO.getCompanyCodeSys01DOC23(), altVO.getItemCodeItm01ITM04())); res = avail.executeCommand( gridParams, userSessionPars, request, response, userSession, context); if (res.isError()) return res; availList = ((VOListResponse) res).getRows(); altAvailability = new BigDecimal(0); for (int j = 0; j < availList.size(); j++) { availVO = (ItemAvailabilityVO) availList.get(j); altAvailability = altAvailability.add(availVO.getAvailableQtyWAR03()); } if (altAvailability.doubleValue() > 0) { altComponentVO = new ProdOrderComponentVO(); altComponentVO.setAvailabilities(availList); altComponentVO.setAvailableQty(altAvailability); altComponentVO.setCompanyCodeSys01DOC24(altVO.getCompanyCodeSys01ITM04()); altComponentVO.setDescriptionSYS10(altVO.getDescriptionSYS10()); altComponentVO.setDocNumberDOC24(prodVO.getDocNumberDOC23()); altComponentVO.setDocYearDOC24(prodVO.getDocYearDOC23()); altComponentVO.setItemCodeItm01DOC24(altVO.getItemCodeItm01ITM04()); altComponentVO.setMinSellingQtyUmCodeReg02ITM01( altVO.getMinSellingQtyUmCodeReg02ITM01()); altQty = conv.convertQty( altVO.getMinSellingQtyUmCodeReg02ITM01(), componentVO.getMinSellingQtyUmCodeReg02ITM01(), altAvailability, userSessionPars, request, response, userSession, context); if (componentVO.getQtyDOC24().subtract(availability).doubleValue() > altQty.doubleValue()) { delta = altQty; altComponentVO.setQtyDOC24(altAvailability); } else { delta = componentVO.getQtyDOC24(); altComponentVO.setQtyDOC24( conv.convertQty( componentVO.getMinSellingQtyUmCodeReg02ITM01(), altVO.getMinSellingQtyUmCodeReg02ITM01(), delta, userSessionPars, request, response, userSession, context)); } componentVO.setQtyDOC24(componentVO.getQtyDOC24().subtract(delta)); alternativeComps.add(altComponentVO); altCodes = (HashSet) compAltComps.get(itemCode); if (altCodes == null) { altCodes = new HashSet(); compAltComps.put(itemCode, altCodes); } altCodes.add(altVO.getItemCodeItm01ITM04()); if (componentVO.getQtyDOC24().doubleValue() == 0) { compsToRemove.add(componentVO); break; } if (componentVO.getQtyDOC24().subtract(availability).doubleValue() == 0) break; } } } } list = new ArrayList(comps.values()); list.addAll(alternativeComps); list.removeAll(compsToRemove); return new VOListResponse(list, false, list.size()); } catch (Throwable ex) { Logger.error( userSessionPars.getUsername(), this.getClass().getName(), "checkComponentsAvailability", "Error while retrieving components availability for the specified production order", ex); return new ErrorResponse(ex.getMessage()); } }
/** * Process an HTML get or post. * * @exception ServletException From inherited class. * @exception IOException From inherited class. */ public void scanOutXML( PrintWriter out, String strDirectory, String strFilename, String[] strPlus, String[] strMinus, boolean bExcludeParams, boolean bAnalyzeParams) throws IOException { File dir = new File(strDirectory + '/' + strFilename); if (dir.isDirectory()) return; try { FileReader is = new FileReader(strDirectory + '/' + strFilename); BufferedReader r = new BufferedReader(is); String string = null; Hashtable ht = new Hashtable(); Set setstrExtensions = new HashSet(); int iCount = 0; int iBytes = 0; while ((string = r.readLine()) != null) { StringTokenizer st = new StringTokenizer(string, " \"", false); Data data = new Data(); int iTokenCount = 0; while (st.hasMoreTokens()) { iTokenCount++; string = st.nextToken(); if (iTokenCount == IP) data.m_IP = string; if (iTokenCount == URL) { if (bExcludeParams) if (string.indexOf('?') != -1) string = string.substring(0, string.indexOf('?')); if (bAnalyzeParams) if (string.indexOf('?') != -1) string = string.substring(string.indexOf('?') + 1); data.m_URL = string; } if (iTokenCount == PROTOCOL) if (!string.startsWith("HTTP")) { data.m_URL += " " + string; iTokenCount--; } if (iTokenCount == BYTES) data.m_iBytes = Integer.parseInt(string); } if (!this.filterURL(data.m_URL, strPlus, strMinus, setstrExtensions)) continue; iCount++; iBytes += data.m_iBytes; if (ht.get(data.m_URL) == null) ht.put(data.m_URL, data); else { int iThisBytes = data.m_iBytes; data = (Data) ht.get(data.m_URL); data.m_iCount++; data.m_iBytes += iThisBytes; } } Comparator comparator = new Test(); TreeMap tm = new TreeMap(comparator); Iterator iterator = ht.values().iterator(); while (iterator.hasNext()) { Data data = (Data) iterator.next(); tm.put(new Integer(data.m_iCount), data); } out.println("<file>"); this.printXML(out, "directory", strDirectory); this.printXML(out, "name", strFilename); iterator = tm.values().iterator(); while (iterator.hasNext()) { out.println("<data>"); Data data = (Data) iterator.next(); this.printXML(out, "url", data.m_URL); this.printXML(out, "count", Integer.toString(data.m_iCount)); out.println("</data>"); } this.printXML(out, "hits", Integer.toString(iCount)); this.printXML(out, "bytes", Integer.toString(iBytes)); this.printXML(out, "unique", Integer.toString(tm.size())); iterator = setstrExtensions.iterator(); out.println("<extensions>"); while (iterator.hasNext()) { this.printXML(out, "extension", (String) iterator.next()); } out.println("</extensions>"); out.println("</file>"); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } }