List of usage examples for java.util Vector iterator
public synchronized Iterator<E> iterator()
From source file:org.geoserver.GeoserverInitStartupListener.java
/** * This method tries hard to stop all threads and remove all references to classes in GeoServer * so that we can avoid permgen leaks on application undeploy. * What happes is that, if any JDK class references to one of the classes loaded by the * webapp classloader, then the classloader cannot be collected and neither can all the * classes loaded by it (since each class keeps a back reference to the classloader that * loaded it). The same happens for any residual thread launched by the web app. *//*from w w w .ja va2 s .c om*/ public void contextDestroyed(ServletContextEvent sce) { try { LOGGER.info("Beginning GeoServer cleanup sequence"); // the dreaded classloader ClassLoader webappClassLoader = getClass().getClassLoader(); // unload all of the jdbc drivers we have loaded. We need to store them and unregister // later to avoid concurrent modification exceptions Enumeration<Driver> drivers = DriverManager.getDrivers(); Set<Driver> driversToUnload = new HashSet<Driver>(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { // the driver class loader can be null if the driver comes from the JDK, such as the // sun.jdbc.odbc.JdbcOdbcDriver ClassLoader driverClassLoader = driver.getClass().getClassLoader(); if (driverClassLoader != null && webappClassLoader.equals(driverClassLoader)) { driversToUnload.add(driver); } } catch (Throwable t) { t.printStackTrace(); } } for (Driver driver : driversToUnload) { try { DriverManager.deregisterDriver(driver); LOGGER.info("Unregistered JDBC driver " + driver); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Could now unload driver " + driver.getClass(), e); } } drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); } try { Class h2Driver = Class.forName("org.h2.Driver"); Method m = h2Driver.getMethod("unload"); m.invoke(null); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to unload the H2 driver", e); } // unload all deferred authority factories so that we get rid of the timer tasks in them try { disposeAuthorityFactories(ReferencingFactoryFinder.getCoordinateOperationAuthorityFactories(null)); } catch (Throwable e) { LOGGER.log(Level.WARNING, "Error occurred trying to dispose authority factories", e); } try { disposeAuthorityFactories(ReferencingFactoryFinder.getCRSAuthorityFactories(null)); } catch (Throwable e) { LOGGER.log(Level.WARNING, "Error occurred trying to dispose authority factories", e); } try { disposeAuthorityFactories(ReferencingFactoryFinder.getCSAuthorityFactories(null)); } catch (Throwable e) { LOGGER.log(Level.WARNING, "Error occurred trying to dispose authority factories", e); } // kill the threads created by referencing WeakCollectionCleaner.DEFAULT.exit(); DeferredAuthorityFactory.exit(); CRS.reset("all"); LOGGER.info("Shut down GT referencing threads "); // reset ReferencingFactoryFinder.reset(); CommonFactoryFinder.reset(); DataStoreFinder.reset(); DataAccessFinder.reset(); LOGGER.info("Shut down GT SPI "); LOGGER.info("Shut down coverage thread pool "); Object o = Hints.getSystemDefault(Hints.EXECUTOR_SERVICE); if (o != null && o instanceof ExecutorService) { final ThreadPoolExecutor executor = (ThreadPoolExecutor) o; try { executor.shutdown(); } finally { try { executor.shutdownNow(); } finally { } } } // unload everything that JAI ImageIO can still refer to // We need to store them and unregister later to avoid concurrent modification exceptions final IIORegistry ioRegistry = IIORegistry.getDefaultInstance(); Set<IIOServiceProvider> providersToUnload = new HashSet(); for (Iterator<Class<?>> cats = ioRegistry.getCategories(); cats.hasNext();) { Class<?> category = cats.next(); for (Iterator it = ioRegistry.getServiceProviders(category, false); it.hasNext();) { final IIOServiceProvider provider = (IIOServiceProvider) it.next(); if (webappClassLoader.equals(provider.getClass().getClassLoader())) { providersToUnload.add(provider); } } } for (IIOServiceProvider provider : providersToUnload) { ioRegistry.deregisterServiceProvider(provider); LOGGER.info("Unregistering Image I/O provider " + provider); } // unload everything that JAI can still refer to final OperationRegistry opRegistry = JAI.getDefaultInstance().getOperationRegistry(); for (String mode : RegistryMode.getModeNames()) { for (Iterator descriptors = opRegistry.getDescriptors(mode).iterator(); descriptors != null && descriptors.hasNext();) { RegistryElementDescriptor red = (RegistryElementDescriptor) descriptors.next(); int factoryCount = 0; int unregisteredCount = 0; // look for all the factories for that operation for (Iterator factories = opRegistry.getFactoryIterator(mode, red.getName()); factories != null && factories.hasNext();) { Object factory = factories.next(); if (factory == null) { continue; } factoryCount++; if (webappClassLoader.equals(factory.getClass().getClassLoader())) { boolean unregistered = false; // we need to scan against all "products" to unregister the factory Vector orderedProductList = opRegistry.getOrderedProductList(mode, red.getName()); if (orderedProductList != null) { for (Iterator products = orderedProductList.iterator(); products != null && products.hasNext();) { String product = (String) products.next(); try { opRegistry.unregisterFactory(mode, red.getName(), product, factory); LOGGER.info("Unregistering JAI factory " + factory.getClass()); } catch (Throwable t) { // may fail due to the factory not being registered against that product } } } if (unregistered) { unregisteredCount++; } } } // if all the factories were unregistered, get rid of the descriptor as well if (factoryCount > 0 && unregisteredCount == factoryCount) { opRegistry.unregisterDescriptor(red); } } } // flush all javabean introspection caches as this too can keep a webapp classloader from being unloaded Introspector.flushCaches(); LOGGER.info("Cleaned up javabean caches"); // unload the logging framework if (!relinquishLoggingControl) LogManager.shutdown(); LogFactory.release(Thread.currentThread().getContextClassLoader()); // GeoTools/GeoServer have a lot of finalizers and until they are run the JVM // itself wil keepup the class loader... try { System.gc(); System.runFinalization(); System.gc(); System.runFinalization(); System.gc(); System.runFinalization(); } catch (Throwable t) { System.out.println("Failed to perform closing up finalization"); t.printStackTrace(); } } catch (Throwable t) { // if anything goes south during the cleanup procedures I want to know what it is t.printStackTrace(); } }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing test counts for each product area. * * @param suites List of test suites * @param areas List of product areas * /*from ww w .j av a 2s.c om*/ * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageAreaTestTimeChart(Vector<CMnDbBuildData> builds, Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) { JFreeChart chart = null; // Collect the average of all test types Hashtable timeAvg = new Hashtable(); DefaultPieDataset dataset = new DefaultPieDataset(); if ((suites != null) && (suites.size() > 0)) { // Collect test data for each of the suites in the list Enumeration suiteList = suites.elements(); while (suiteList.hasMoreElements()) { // Process the data for the current suite CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement(); Long elapsedTime = new Long(suite.getElapsedTime() / (1000 * 60)); CMnDbFeatureOwnerData area = null; // Iterate through each product area to determine who owns this suite CMnDbFeatureOwnerData currentArea = null; Iterator iter = areas.iterator(); while (iter.hasNext()) { currentArea = (CMnDbFeatureOwnerData) iter.next(); if (currentArea.hasFeature(suite.getGroupName())) { Long avgValue = null; String areaName = currentArea.getDisplayName(); if (timeAvg.containsKey(areaName)) { Long oldAvg = (Long) timeAvg.get(areaName); avgValue = oldAvg + elapsedTime; } else { avgValue = elapsedTime; } timeAvg.put(areaName, avgValue); } } } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = timeAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Long total = (Long) timeAvg.get(key); Long avg = new Long(total.longValue() / builds.size()); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Avg Test Time by Area", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatAreaChart(plot, "min"); return chart; }
From source file:com.vsquaresystem.safedeals.readyreckoner.ReadyReckonerService.java
private boolean saveToDatabase(Vector dataHolder) throws IOException { readyReckonerDAL.truncateAll();/*from w w w. j ava 2s . co m*/ dataHolder.remove(0); Readyreckoner readyReckoner = new Readyreckoner(); String id = ""; String locationId = ""; String rrYear = ""; String rrRateLand = ""; String rrRatePlot = ""; String rrRateApartment = ""; System.out.println(dataHolder); DataFormatter formatter = new DataFormatter(); for (Iterator iterator = dataHolder.iterator(); iterator.hasNext();) { List list = (List) iterator.next(); logger.info("list", list); locationId = list.get(1).toString(); rrYear = list.get(2).toString(); rrRateLand = list.get(3).toString(); rrRatePlot = list.get(4).toString(); rrRateApartment = list.get(5).toString(); try { readyReckoner.setLocationId(Integer.parseInt(locationId)); readyReckoner.setRrYear(Double.parseDouble(rrYear)); readyReckoner.setRrRateLand(Double.parseDouble(rrRateLand)); readyReckoner.setRrRatePlot(Double.parseDouble(rrRatePlot)); readyReckoner.setRrRateApartment(Double.parseDouble(rrRateApartment)); readyReckonerDAL.insert(readyReckoner); } catch (Exception e) { e.printStackTrace(); } } File excelFile = attachmentUtils .getDirectoryByAttachmentType(AttachmentUtils.AttachmentType.READY_RECKONER); FileUtils.cleanDirectory(excelFile); return true; }
From source file:nl.nn.adapterframework.jdbc.XmlQuerySender.java
private int countParameters(Vector columns) { int parameterCount = 0; Iterator iter = columns.iterator(); while (iter.hasNext()) { Column column = (Column) iter.next(); if (column.getParameter() != null) { parameterCount++;/*from www . j a v a2 s .co m*/ } } return parameterCount; }
From source file:nl.nn.adapterframework.jdbc.XmlQuerySender.java
private void applyParameters(PreparedStatement statement, Vector columns) throws SQLException { Iterator iter = columns.iterator(); int var = 1; while (iter.hasNext()) { Column column = (Column) iter.next(); if (column.getParameter() != null) { if (column.getParameter() instanceof String) { log.debug(/*from ww w .j av a 2 s . c o m*/ "parm [" + var + "] is a String with value [" + column.getParameter().toString() + "]"); statement.setString(var, (String) column.getParameter()); var++; } if (column.getParameter() instanceof Integer) { log.debug("parm [" + var + "] is an Integer with value [" + column.getParameter().toString() + "]"); statement.setInt(var, Integer.parseInt(column.getParameter().toString())); var++; } if (column.getParameter() instanceof Float) { log.debug( "parm [" + var + "] is a Float with value [" + column.getParameter().toString() + "]"); statement.setFloat(var, Float.parseFloat(column.getParameter().toString())); var++; } if (column.getParameter() instanceof Timestamp) { log.debug("parm [" + var + "] is a Timestamp with value [" + column.getParameter().toString() + "]"); statement.setTimestamp(var, (Timestamp) column.getParameter()); var++; } } } }
From source file:it.eng.spagobi.tools.downloadFiles.service.DownloadZipAction.java
public void createZipFromFiles(Vector<File> files, String outputFileName, String folderName) throws IOException { logger.debug("IN"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFileName)); // Compress the files for (Iterator iterator = files.iterator(); iterator.hasNext();) { File file = (File) iterator.next(); FileInputStream in = new FileInputStream(file); String fileName = file.getName(); // The name to Inssert: remove the parameter folder // int lastIndex=folderName.length(); // String fileToInsert=fileName.substring(lastIndex+1); logger.debug("Adding to zip entry " + fileName); ZipEntry zipEntry = new ZipEntry(fileName); // Add ZIP entry to output stream. out.putNextEntry(zipEntry);// w ww .ja va 2s.c o m // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } // Complete the entry out.closeEntry(); in.close(); } // Complete the ZIP file out.close(); logger.debug("OUT"); }
From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java
private PortType flatten(PortType portType, Definition definition, Definition parentDefinition, List portTypeNames, Map resourcePropertyElements, Map schemaDocumentLocations) throws Exception { Map portTypes = definition.getPortTypes(); Iterator portTypeIterator = portTypes.values().iterator(); while (portTypeIterator.hasNext()) { PortType currentPortType = (PortType) portTypeIterator.next(); if (portTypeNames != null && portTypeNames.contains(currentPortType.getQName())) { log.debug("Found porttype: " + currentPortType.getQName()); QName resourceProperties = (QName) currentPortType.getExtensionAttribute(RP); if (resourceProperties != null) { log.debug("Adding resource properties for porttype: " + currentPortType.getQName()); resourcePropertyElements.putAll(getResourceProperties(resourceProperties, definition, schemaDocumentLocations, this.quiet)); }/*from ww w . j av a2s. c o m*/ List newDependencies = getDependencies(currentPortType); if (newDependencies != null && !newDependencies.isEmpty()) { flatten(currentPortType, definition, parentDefinition, newDependencies, resourcePropertyElements, schemaDocumentLocations); if (!newDependencies.isEmpty() && definition != parentDefinition && !quiet) { log.warn("WARNING: The following porttypes are missing:"); Iterator portTypeNamesIterator = newDependencies.iterator(); while (portTypeNamesIterator.hasNext()) { log.error("\t" + portTypeNamesIterator.next().toString()); } } } fixNameSpaces(currentPortType, parentDefinition); List operations = currentPortType.getOperations(); ListIterator operationsIterator = operations.listIterator(); Operation operation; Input input; Output output; while (operationsIterator.hasNext()) { operation = (Operation) operationsIterator.next(); input = operation.getInput(); output = operation.getOutput(); if (portType.getOperation(operation.getName(), input == null ? null : input.getName(), output == null ? null : output.getName()) == null) { if (input != null && input.getExtensionAttribute(WSA_ACTION) != null) { this.wsaImport = true; Element schema = getSchemaElement(definition); if (schema != null) { XSModel schemaModel = loadSchema(schema, definition); populateLocations(schemaModel, schemaDocumentLocations, definition); } } portType.addOperation(operation); } } addImports(definition, parentDefinition); portTypeNames.remove(currentPortType.getQName()); } } if (portTypeNames == null || portTypeNames.isEmpty()) { return portType; } else { // Only go to immediate imports - nested imports are not processed if (definition == parentDefinition) { Map imports = new HashMap(); imports.putAll(definition.getImports()); Iterator importNSIterator = imports.values().iterator(); while (importNSIterator.hasNext() && !portTypeNames.isEmpty()) { Vector importVector = (Vector) importNSIterator.next(); Iterator importIterator = importVector.iterator(); while (importIterator.hasNext() && !portTypeNames.isEmpty()) { // Name space? // I think the rule is to set the target name space to the // namespace // specified by import statement if not already defined Import importDef = (Import) importIterator.next(); flatten(portType, importDef.getDefinition(), parentDefinition, portTypeNames, resourcePropertyElements, schemaDocumentLocations); } } if (!portTypeNames.isEmpty() && !quiet) { log.warn("The following porttypes are missing:"); Iterator portTypeNamesIterator = portTypeNames.iterator(); while (portTypeNamesIterator.hasNext()) { log.warn("\t" + (portTypeNamesIterator.next()).toString()); } } } return portType; } }
From source file:org.mwc.cmap.LiveDataMonitor.views.LiveDataMonitor.java
/** * a watchable item has been selected, better show it * /* w w w. ja va 2 s . c om*/ * @param attribute * what we're going to watch */ private void storeDataset(final IAttribute attribute, final Object index) { final Vector<DataDoublet> data = attribute.getHistoricValues(index); // is there any data in it? if (data.size() == 0) { _chart.setTitle(attribute.getName()); _chart.getXYPlot().setDataset(null); } else { final TimeSeriesCollection dataset = new TimeSeriesCollection(); final TimeSeries series = new TimeSeries(attribute.getName()); for (final Iterator<DataDoublet> iterator = data.iterator(); iterator.hasNext();) { final DataDoublet thisD = (DataDoublet) iterator.next(); final Object thisVal = thisD.getValue(); if (thisVal instanceof Number) { series.addOrUpdate(new Millisecond(new Date(thisD.getTime())), (Number) thisD.getValue()); } } // did it work? if (!series.isEmpty()) { dataset.addSeries(series); _chart.getXYPlot().setDataset(dataset); _chart.setTitle(attribute.getName()); _chart.getXYPlot().getRangeAxis().setLabel(attribute.getUnits()); } } }
From source file:net.aepik.alasca.plugin.schemaconverter.core.SchemaConverter.java
/** * Retourne l'ensemble des syntaxes de conversion possibles pour la * syntaxe du schma et un dictionnaire donn (tir du traducteur). * @param dictionnaire Le nom du dictionnaire prendre en compte. **///from w ww. j a v a 2s. com public String[] getAvailableSyntaxes(String dictionnary) { String[] result = null; if (traduc.setSelectedDictionnary(dictionnary)) { String[] src = traduc.getSourceSyntaxes(); String[] dst = traduc.getDestinationSyntaxes(); boolean srcOk = false; // On regarde si la syntaxe du schma est dans l'ensemble des // syntaxes sources. String currentSyntax = schema.getSyntax().toString(); for (int i = 0; i < src.length && !srcOk; i++) { if (src[i].equals(currentSyntax)) srcOk = true; } // On regarde si les syntaxes de destinations sont prsentes // dans le logiciel, dans ce cas on les ajoutes dans le rsultat. Vector<String> resultTmp = new Vector<String>(); String[] syntaxes = Schema.getSyntaxes(); // Syntaxes logiciels for (int i = 0; i < dst.length && srcOk; i++) { for (int j = 0; j < syntaxes.length; j++) { if (syntaxes[j].equals(dst[i])) resultTmp.add(dst[i]); } } result = new String[resultTmp.size()]; Iterator<String> it = resultTmp.iterator(); int compteur = 0; while (it.hasNext()) { result[compteur] = it.next(); compteur++; } } if (result != null & result.length == 0) result = null; return result; }
From source file:com.arcbees.plugin.velocity.ResourceManagerImplCustom.java
/** * This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This * Hashtable will be passed in when initializing the the template loader. */// w w w . j a va 2 s .com private void assembleResourceLoaderInitializers() { Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER); StringUtils.trimStrings(resourceLoaderNames); for (Iterator it = resourceLoaderNames.iterator(); it.hasNext();) { /* * The loader id might look something like the following: * * file.resource.loader * * The loader id is the prefix used for all properties * pertaining to a particular loader. */ String loaderName = (String) it.next(); StringBuffer loaderID = new StringBuffer(loaderName); loaderID.append(".").append(RuntimeConstants.RESOURCE_LOADER); ExtendedProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID.toString()); /* * we can't really count on ExtendedProperties to give us an empty set */ if (loaderConfiguration == null) { log.warn("ResourceManager : No configuration information for resource loader named '" + loaderName + "'. Skipping."); continue; } /* * add the loader name token to the initializer if we need it * for reference later. We can't count on the user to fill * in the 'name' field */ loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, loaderName); /* * Add resources to the list of resource loader * initializers. */ sourceInitializerList.add(loaderConfiguration); } }