?? stresswwjiterator.java
字號(hào):
/* Copyright (C) 2001, 2007 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples;import gov.nasa.worldwind.ViewStateIterator;import gov.nasa.worldwind.awt.WorldWindowGLCanvas;import gov.nasa.worldwind.util.Logging;import gov.nasa.worldwind.render.markers.*;import gov.nasa.worldwind.render.Material;import gov.nasa.worldwind.layers.*;import gov.nasa.worldwind.geom.Position;import gov.nasa.worldwind.geom.Angle;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.view.FlyToOrbitViewStateIterator;import gov.nasa.worldwind.view.OrbitView;import gov.nasa.worldwind.view.EyePositionIterator;//import gov.nasa.worldwind.util.PerformanceLogger;import javax.swing.*;import javax.swing.border.TitledBorder;import javax.swing.border.CompoundBorder;import java.util.Date;import java.util.ArrayList;import java.util.Properties;import java.util.logging.Level;import java.awt.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.net.URISyntaxException;/** * App for stress testing WWJ functions. Just start it and let it run. * * @author jparsons * @version $Id$ */public class StressWWJIterator implements ActionListener{ private WorldWindowGLCanvas wwd; private ApplicationTemplate.AppFrame frame; private int viewIterations=0; private long totIterations=0; private int markerIterations=0; private int numRounds = 0; private int airspaceIterations=0; private static ArrayList<Marker> markers = new ArrayList<Marker>(); private static StressAirspace airspace; private int wmsIterations=0; private int wmsLayerCount=0; private StressWMS stressWMS=null; private ArrayList<Layer> addedLayers = new ArrayList<Layer>(); private long maxMemUsed=0; private long currentMemUsed=0; //Max values private int maxViewIterations = 1; private int maxMarkerIterations = 10; private int numMarkersPerIteration = 1000; private int maxAirspaceIterations = 10; private int numAirspacePerIteration = 500; private int timePerIteration = 45000; //in ms private int maxWMSIterations = 2; private final long maxCacheCap = 220000000; private final long minCacheCap = 180000000; private final long maxCacheLowCap = 180000000; private final long minCacheLowCap = 10000000; private boolean minimizeWindow = false; private String externalWMSURL = "http://neowms.sci.gsfc.nasa.gov/wms/wms"; //Property Keys public static String PROPERTIES_FILE = "config/stresswwj.properties"; public static String VIEW_ITERATIONS_KEY = "gov.nasa.worldwind.avkey.ViewIterations"; public static String TIME_PER_ITERTION_KEY = "gov.nasa.worldwind.avkey.TimePerIteration"; public static String MARKER_ITERATIONS_KEY = "gov.nasa.worldwind.avkey.MarkerIterations"; public static String AIRSPACE_ITERATIONS_KEY = "gov.nasa.worldwind.avkey.AirspaceIterations"; public static String MARKERS_PER_ITERATION_KEY = "gov.nasa.worldwind.avkey.MarkersPerIteration"; public static String AIRSPACES_PER_ITERATION_KEY = "gov.nasa.worldwind.avkey.AirspacesPerIteration"; public static String WMS_ITERATIONS_KEY = "gov.nasa.worldwind.avkey.WMSIterations"; public static String MINIMIZE_WINDOW_KEY = "gov.nasa.worldwind.avkey.MinimizeWindow"; public static String EXTERNAL_WMS_KEY = "gov.nasa.worldwind.avkey.ExternalWMS"; //label strings private final static String FREE_MEM_STR= "Free memory: "; private final static String TOTAL_MEM_STR="Total memory: "; private final static String TOT_ITERATIONS_STR = "Total iterations: "; private final static String NUM_ROUNDS_STR = "Number of completed rounds: "; private final static String NUM_ACTIVE_MARKERS_STR = "# Active Markers: "; private final static String NUM_VIEW_ITERATIONS_STR = "View iterations: "; private final static String NUM_MARKER_ITERATIONS_STR = "Marker iterations: "; //Labels private JLabel freeMemLbl = new JLabel(FREE_MEM_STR); private JLabel totalMemLbl = new JLabel(TOTAL_MEM_STR); private JLabel iterationsLbl = new JLabel(TOT_ITERATIONS_STR); private JLabel roundsLbl = new JLabel(NUM_ROUNDS_STR); private JLabel viewLbl = new JLabel(NUM_VIEW_ITERATIONS_STR + "0 of "+maxViewIterations); private JLabel markerLbl = new JLabel(NUM_MARKER_ITERATIONS_STR + "0 of "+maxMarkerIterations); private JLabel airspaceLbl = new JLabel("Airspace iterations: " + "0 of "+maxAirspaceIterations); private JLabel numObjectsLbl = new JLabel(); private JLabel statusLbl = new JLabel("status:"); private JLabel wmsLbl = new JLabel("WMS Iterations " + wmsIterations + " of " + maxWMSIterations); private static final MarkerAttributes[] attrs = new BasicMarkerAttributes[] { new BasicMarkerAttributes(Material.DARK_GRAY,BasicMarkerShape.SPHERE, 1d, 10, 5), new BasicMarkerAttributes(Material.RED, BasicMarkerShape.CONE, 0.7), new BasicMarkerAttributes(Material.YELLOW, BasicMarkerShape.CYLINDER, 0.9), new BasicMarkerAttributes(Material.CYAN, BasicMarkerShape.SPHERE, 0.7), new BasicMarkerAttributes(Material.GREEN, BasicMarkerShape.CONE, 1d), new BasicMarkerAttributes(Material.PINK, BasicMarkerShape.ORIENTED_SPHERE, 0.8), new BasicMarkerAttributes(Material.BLUE, BasicMarkerShape.CONE, 0.6), }; public StressWWJIterator(ApplicationTemplate.AppFrame frame0) { this.frame=frame0; this.wwd=frame.getWwd(); readPropertiesFile(); airspace = new StressAirspace(); try{ if (maxWMSIterations > 0) stressWMS=new StressWMS(externalWMSURL); }catch(URISyntaxException uriEX) { Logging.logger().severe("Error initializing WMS component: " + uriEX.getMessage()); } } public void actionPerformed(ActionEvent e) { long timeToMove = timePerIteration / 2L; //time for "movements" nextViewState( timeToMove); } private void readPropertiesFile() { StressTestConfiguration readProp = new StressTestConfiguration(PROPERTIES_FILE); maxViewIterations = readProp.getIntegerValue(VIEW_ITERATIONS_KEY, maxViewIterations); maxMarkerIterations = readProp.getIntegerValue(MARKER_ITERATIONS_KEY, maxMarkerIterations); timePerIteration = readProp.getIntegerValue(TIME_PER_ITERTION_KEY, timePerIteration); maxAirspaceIterations = readProp.getIntegerValue(AIRSPACE_ITERATIONS_KEY, maxAirspaceIterations); numMarkersPerIteration = readProp.getIntegerValue(MARKERS_PER_ITERATION_KEY, numMarkersPerIteration); numAirspacePerIteration = readProp.getIntegerValue(AIRSPACES_PER_ITERATION_KEY, numAirspacePerIteration); maxWMSIterations = readProp.getIntegerValue(WMS_ITERATIONS_KEY, maxWMSIterations); String oms = readProp.getStringValue(MINIMIZE_WINDOW_KEY); if (oms != null) minimizeWindow = oms.startsWith("t") || oms.startsWith("T"); } public void runWWJIterator() { javax.swing.Timer timer = new javax.swing.Timer(timePerIteration, this); timer.setInitialDelay(5000); Logging.logger().info("Starting Stress Iterator"); timer.start(); } public ArrayList<Marker> getMarkers() { return markers; } public AirspaceLayer getAirspaceLayer() { return airspace.getAirspaceLayer(); } public void updateStressStatsPanel() { long freeMem = (java.lang.Runtime.getRuntime().freeMemory()/(1024*1024)); long totalMem = (java.lang.Runtime.getRuntime().totalMemory()/(1024*1024)); currentMemUsed = totalMem-freeMem; maxMemUsed = Math.max(currentMemUsed, maxMemUsed); freeMemLbl.setText(FREE_MEM_STR + freeMem +"mb"); totalMemLbl.setText(TOTAL_MEM_STR + totalMem +"mb"); iterationsLbl.setText(TOT_ITERATIONS_STR + totIterations); roundsLbl.setText(NUM_ROUNDS_STR + numRounds); viewLbl.setText(NUM_VIEW_ITERATIONS_STR + viewIterations + " of " +maxViewIterations); markerLbl.setText(NUM_MARKER_ITERATIONS_STR + markerIterations + " of " + maxMarkerIterations ); if ( markers.size() > 0) numObjectsLbl.setText(NUM_ACTIVE_MARKERS_STR + markers.size()); else if (airspace.size() > 0) numObjectsLbl.setText("Airspace objects: " + airspace.size()); else numObjectsLbl.setText("no surface objects"); airspaceLbl.setText("Airspace iterations: " + airspaceIterations + " of " + maxAirspaceIterations ); wmsLbl.setText("WMS iterations: " + wmsIterations + " of " + maxWMSIterations ); } private void nextViewState(long timeToMove) { String logMsg; if (wwd != null && wwd.getView() != null && wwd.getView() instanceof OrbitView && wwd.getModel() != null && wwd.getModel().getGlobe() != null) { Globe globe = wwd.getModel().getGlobe(); if (viewIterations < maxViewIterations) { viewIterations++; totIterations++; logMsg = "Round: " + numRounds + " | Total Iterations: " + totIterations + " | View Iterations: " + viewIterations; Position randPos = randomPosition(globe); double zoom = randPos.getElevation() + 2000 + (2000 * Math.random()); Position center = new Position(randPos, zoom); moveToandAlter(timeToMove, center, viewIterations); } else if (markerIterations < maxMarkerIterations) { markerIterations++; totIterations++; logMsg = "Round: " + numRounds + " | Total Iterations: " + totIterations + " | Marker Iterations: " + markerIterations; Position randPos=null; statusLbl.setText("status: Adding Markers"); final ArrayList<Marker> newMarkers = new ArrayList<Marker>(); for (int i=0; i < numMarkersPerIteration; i++) { randPos = randomPosition(globe); double lat = randPos.getLatitude().getDegrees(); double lon = randPos.getLongitude().getDegrees(); Marker marker = new BasicMarker(Position.fromDegrees( lat, lon, 0), attrs[(int) (Math.abs(lat) + Math.abs(lon)) % attrs.length]); marker.setPosition(Position.fromDegrees(lat, lon, 0)); marker.setHeading(Angle.fromDegrees(lat * 5)); newMarkers.add(marker); } SwingUtilities.invokeLater(new Runnable() { public void run() { markers.addAll(newMarkers); } }); //zoom to last marker created Position center = new Position(randPos, 50000); moveToandAlter(timeToMove, center, markerIterations); } else if ( airspaceIterations < maxAirspaceIterations) { statusLbl.setText("status: Adding Airspace objects"); if ( airspaceIterations == 0) { SwingUtilities.invokeLater(new Runnable() { public void run() { if(markers.size() > 0) markers.clear(); } }); } //Call GC System.gc(); airspaceIterations++; totIterations++; logMsg = "Round: " + numRounds + " | Total Iterations: " + totIterations + " | Airspace Iterations: " + airspaceIterations; Position randPos=null; for (int i=0; i < numAirspacePerIteration; i++) { randPos=randomPosition(globe); airspace.addAirspace(randPos); } statusLbl.setText("status: Moving to new location"); //zoom to last marker created Position center = new Position(randPos, 1000000); //markers are big, don't zoom in close moveToandAlter(timeToMove, center, airspaceIterations); } else if (wmsIterations < maxWMSIterations) { if(wmsIterations == 0) { SwingUtilities.invokeLater(new Runnable() { public void run() { if(markers.size() > 0) markers.clear(); if ( airspace.size() > 0) airspace.clearAirspace(); } }); } //Call GC System.gc(); wmsIterations++; totIterations++; logMsg = "Round: " + numRounds + " | Total Iterations: " + totIterations + " | WMS Iterations: " + wmsIterations; if (( wmsLayerCount <= (stressWMS.size()-1)) && ((wmsIterations % 3) == 1)) { statusLbl.setText("status: Adding WMS Layer"); SwingUtilities.invokeLater(new Runnable() { public void run()
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -