List of usage examples for java.util WeakHashMap WeakHashMap
public WeakHashMap()
From source file:com.jaspersoft.jasperserver.api.metadata.common.domain.util.FileBufferedOutputStream.java
public FileBufferedOutputStream(int memoryThreshold, int initialMemoryBufferSize, int inputBufferLength) { this.memoryThreshold = memoryThreshold; this.initialMemoryBufferSize = initialMemoryBufferSize; this.inputBufferLength = inputBufferLength; size = 0;/*from ww w.ja va2 s . co m*/ if (this.memoryThreshold == 0) { memoryOutput = null; } else { int initialSize = this.initialMemoryBufferSize; if (initialSize > this.memoryThreshold) { initialSize = this.memoryThreshold; } memoryOutput = new ByteArrayOutputStream(initialSize); } this.inputStreams = new WeakHashMap<DataStream, Boolean>(); }
From source file:org.openmrs.module.ModuleClassLoader.java
/** * @param module Module/*from ww w .j a va2 s.c o m*/ * @param urls resources "managed" by this class loader * @param parent parent class loader * @param factory URL stream handler factory * @see URLClassLoader#URLClassLoader(java.net.URL[], java.lang.ClassLoader, * java.net.URLStreamHandlerFactory) */ protected ModuleClassLoader(final Module module, final List<URL> urls, final ClassLoader parent, final URLStreamHandlerFactory factory) { super(urls.toArray(new URL[urls.size()]), parent, factory); if (parent instanceof OpenmrsClassLoader) { throw new IllegalArgumentException("Parent must not be OpenmrsClassLoader nor null"); } else if (parent instanceof ModuleClassLoader) { throw new IllegalArgumentException("Parent must not be ModuleClassLoader"); } if (log.isDebugEnabled()) { log.debug("URLs length: " + urls.size()); } this.module = module; requiredModules = collectRequiredModuleImports(module); awareOfModules = collectAwareOfModuleImports(module); libraryCache = new WeakHashMap<URI, File>(); }
From source file:org.eknet.neoswing.view.DefaultVisualizationViewFactory.java
@Override public VisualizationViewer<Vertex, Edge> createViewer(Graph<Vertex, Edge> graph, GraphDb db) { final VisualizationViewer<Vertex, Edge> vv = new VisualizationViewer<Vertex, Edge>( new FRLayout2<Vertex, Edge>(graph)); vv.getModel().getRelaxer().setSleepTime(0); DefaultModalGraphMouse<Vertex, Edge> mouseSupport = new DefaultModalGraphMouse<Vertex, Edge>(); final GraphModel model = new SimpleGraphModel(graph, vv, db); addMousePlugins(mouseSupport, model); vv.setGraphMouse(mouseSupport);//from w w w .j a v a2s . c o m vv.addKeyListener(mouseSupport.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); VertexLabelAsShapeRenderer<Vertex, Edge> vertexShape = new VertexLabelAsShapeRenderer<Vertex, Edge>( vv.getRenderContext()) { @Override public Shape transform(Vertex v) { Rectangle rect = (Rectangle) super.transform(v); return new RoundRectangle2D.Double(rect.x - 3, rect.y - 3, rect.width + 7, rect.height + 7, 10, 10); } }; vertexShape.setPosition(Renderer.VertexLabel.Position.CNTR); vv.setBackground(Color.WHITE); vv.getRenderContext().setVertexShapeTransformer(vertexShape); vv.getRenderContext().setVertexLabelTransformer(new VertexTransformer(model)); vv.getRenderer().setVertexLabelRenderer(vertexShape); vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<Vertex, Paint>() { private Color nodefill = Color.getHSBColor(207, 19, 97); @Override public Paint transform(Vertex v) { // if (v.getId() == 0) { // return Color.green; // } return nodefill; } }); vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Edge, String>() { private final WeakHashMap<Object, String> cache = new WeakHashMap<Object, String>(); @Override public String transform(final Edge e) { String s = cache.get(e.getId()); if (s == null) { s = "<null>"; GraphDb.Tx tx = model.getDatabase().beginTx(); try { Edge edge = model.getDatabase().lookupEdge(e.getId()); s = edge.getLabel(); tx.success(); cache.put(edge.getId(), s); } catch (Exception e1) { log.error("Error obtaining edge label", e1); } finally { tx.finish(); } } return s; } }); return vv; }
From source file:org.esa.snap.timeseries.ui.graph.TimeSeriesGraphModel.java
TimeSeriesGraphModel(XYPlot plot, Validation validation) { timeSeriesPlot = plot;/*from w w w . ja v a 2 s . c o m*/ this.validation = validation; validation.addValidationListener(() -> { updateTimeSeries(null, TimeSeriesType.INSITU); updateTimeSeries(null, TimeSeriesType.PIN); }); eoVariableBands = new ArrayList<>(); displayControllerMap = new WeakHashMap<>(); workerChainSupport = createWorkerChainSupport(); workerChain = new WorkerChain(); initPlot(); }
From source file:uk.ac.cam.cl.dtg.segue.auth.FacebookAuthenticator.java
/** * @param clientId The registered Facebook client ID * @param clientSecret The client secret provided by the Facebook api (https://developers.facebook.com/apps/) * @param callbackUri The callback url from the oauth process * @param requestedScopes The facebook permissions requested by this application */// w w w . j a va 2 s. c o m @Inject public FacebookAuthenticator(@Named(Constants.FACEBOOK_CLIENT_ID) final String clientId, @Named(Constants.FACEBOOK_SECRET) final String clientSecret, @Named(Constants.FACEBOOK_CALLBACK_URI) final String callbackUri, @Named(Constants.FACEBOOK_OAUTH_SCOPES) final String requestedScopes) { this.jsonFactory = new JacksonFactory(); this.httpTransport = new NetHttpTransport(); this.clientSecret = clientSecret; this.clientId = clientId; this.callbackUri = callbackUri; this.requestedScopes = Arrays.asList(requestedScopes.split(",")); if (null == credentialStore) { credentialStore = new WeakHashMap<>(); } if (null == tokenVerifier) { tokenVerifier = new GoogleIdTokenVerifier(httpTransport, jsonFactory); } }
From source file:org.enerj.apache.commons.beanutils.BeanificationTestCase.java
/** Tests whether classloaders and beans are released from memory by the map used by beanutils */ public void testMemoryLeak2() throws Exception { // tests when the map used by beanutils has the right behaviour if (isPre14JVM()) { System.out.println("WARNING: CANNOT TEST MEMORY LEAK ON PRE1.4 JVM"); return;// w w w . jav a2s . c o m } // many thanks to Juozas Baliuka for suggesting this methodology TestClassLoader loader = new TestClassLoader(); ReferenceQueue queue = new ReferenceQueue(); WeakReference loaderReference = new WeakReference(loader, queue); Integer test = new Integer(1); WeakReference testReference = new WeakReference(test, queue); //Map map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true); Map map = new WeakHashMap(); map.put(loader, test); assertEquals("In map", test, map.get(loader)); assertNotNull("Weak reference released early (1)", loaderReference.get()); assertNotNull("Weak reference released early (2)", testReference.get()); // dereference strong references loader = null; test = null; int iterations = 0; int bytz = 2; while (true) { System.gc(); if (iterations++ > MAX_GC_ITERATIONS) { fail("Max iterations reached before resource released."); } map.isEmpty(); if (loaderReference.get() == null && testReference.get() == null) { break; } else { // create garbage: byte[] b = new byte[bytz]; bytz = bytz * 2; } } }
From source file:org.shaman.terrain.sketch.SketchTerrain.java
public SketchTerrain() { this.featureCurves = new ArrayList<>(); this.featureCurveNodes = new ArrayList<>(); this.featureCurveMesh = new ArrayList<>(); this.presets = DefaultCurvePresets.DEFAULT_PRESETS; this.controlPointMap = new WeakHashMap<>(); }
From source file:WeakHashSet.java
/** * Constructs a new, empty set; the backing <tt>WeakHashMap</tt> instance has * default initial capacity (16) and load factor (0.75). *///from w w w.j av a 2s. c o m public WeakHashSet() { map = new WeakHashMap(); }
From source file:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java
TimeSeriesGraphModel(XYPlot plot, Validation validation) { timeSeriesPlot = plot;//from w w w .j av a2s . c o m this.validation = validation; validation.addValidationListener(new ValidationListener() { @Override public void expressionChanged() { updateTimeSeries(null, TimeSeriesType.INSITU); updateTimeSeries(null, TimeSeriesType.PIN); } }); eoVariableBands = new ArrayList<List<Band>>(); displayControllerMap = new WeakHashMap<AbstractTimeSeries, TimeSeriesGraphDisplayController>(); workerChainSupport = createWorkerChainSupport(); workerChain = new WorkerChain(); initPlot(); }
From source file:org.jhotdraw.samples.svg.figures.SVGImage.java
public SVGImage clone() { SVGImage that = (SVGImage) super.clone(); that.bounds = (Rectangle2D.Double) bounds.clone(); that.scaledImages = new WeakHashMap<Double, BufferedImage>(); return that;/*www .j a v a2 s . co m*/ }