List of usage examples for java.util WeakHashMap WeakHashMap
public WeakHashMap()
From source file:com.mike.aframe.http.KJHttp.java
/** * ?httpClient/*from w w w .j av a 2 s. com*/ */ private void initHttpClient() { BasicHttpParams httpParams = new BasicHttpParams(); ConnManagerParams.setTimeout(httpParams, config.getConnectTimeOut()); ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(config.getMaxConnections())); ConnManagerParams.setMaxTotalConnections(httpParams, config.getMaxConnections()); HttpConnectionParams.setSoTimeout(httpParams, config.getConnectTimeOut()); HttpConnectionParams.setConnectionTimeout(httpParams, config.getConnectTimeOut()); HttpConnectionParams.setTcpNoDelay(httpParams, true); HttpConnectionParams.setSocketBufferSize(httpParams, config.getSocketBuffer()); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(httpParams, "KJLibrary"); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry); httpContext = new SyncBasicHttpContext(new BasicHttpContext()); httpClient = new DefaultHttpClient(cm, httpParams); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } for (Entry<String, String> entry : config.getHeader().entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } } }); httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(HttpResponse response, HttpContext context) { final HttpEntity entity = response.getEntity(); if (entity == null) { return; } final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase("gzip")) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); threadPool = (ThreadPoolExecutor) KJThreadExecutors.newCachedThreadPool(); httpClient.setHttpRequestRetryHandler(new RetryHandler(config.getReadTimeout())); requestMap = new WeakHashMap<Context, List<WeakReference<Future<?>>>>(); }
From source file:org.apache.axiom.om.util.StAXUtils.java
/** * @return XMLOutputFactory for the current classloader *//*from ww w.j a v a 2 s .c o m*/ private static XMLOutputFactory getXMLOutputFactory_perClassLoader(StAXWriterConfiguration configuration) { ClassLoader cl = getContextClassLoader(); XMLOutputFactory factory; if (cl == null) { factory = getXMLOutputFactory_singleton(configuration); } else { if (configuration == null) { configuration = StAXWriterConfiguration.DEFAULT; } Map map = (Map) outputFactoryPerCLMap.get(configuration); if (map == null) { map = Collections.synchronizedMap(new WeakHashMap()); outputFactoryPerCLMap.put(configuration, map); factory = null; } else { factory = (XMLOutputFactory) map.get(cl); } if (factory == null) { if (log.isDebugEnabled()) { log.debug("About to create XMLOutputFactory implementation with " + "classloader=" + cl); log.debug("The classloader for javax.xml.stream.XMLOutputFactory is: " + XMLOutputFactory.class.getClassLoader()); } try { factory = newXMLOutputFactory(null, configuration); } catch (ClassCastException cce) { if (log.isDebugEnabled()) { log.debug("Failed creation of XMLOutputFactory implementation with " + "classloader=" + cl); log.debug("Exception is=" + cce); log.debug("Attempting with classloader: " + XMLOutputFactory.class.getClassLoader()); } factory = newXMLOutputFactory(XMLOutputFactory.class.getClassLoader(), configuration); } if (factory != null) { map.put(cl, factory); if (log.isDebugEnabled()) { log.debug("Created XMLOutputFactory = " + factory.getClass() + " for classloader=" + cl); log.debug("Configuration = " + configuration); log.debug("Size of XMLOutFactory map for this configuration = " + map.size()); log.debug("Configurations for which factories have been cached = " + outputFactoryPerCLMap.keySet()); } } else { factory = getXMLOutputFactory_singleton(configuration); } } } return factory; }
From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java
private void addQueue(String url, ImageView iv) { WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.get(url); if (ivs == null) { if (queueMap.containsKey(url)) { //already a image view fetching ivs = new WeakHashMap<ImageView, BitmapAjaxCallback>(); ivs.put(iv, this); queueMap.put(url, ivs);//www . j ava 2s. c o m } else { //register a view by putting a url with no value queueMap.put(url, null); } } else { //add to list of image views ivs.put(iv, this); } }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
private void addQueue(String url, ImageView iv) { WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.get(url); if (ivs == null) { if (queueMap.containsKey(url)) { //already a image view fetching ivs = new WeakHashMap<ImageView, BitmapAjaxCallback>(); ivs.put(iv, this); queueMap.put(url, ivs);//from w w w. ja va2s .c o m } else { //register a view by putting a url with no value queueMap.put(url, null); } } else { //add to list of image views ivs.put(iv, this); } }
From source file:org.dragonet.plugin.MixedPluginManager.java
@Override public void subscribeToPermission(String permission, Permissible permissible) { String name = permission.toLowerCase(); Map<Permissible, Boolean> map = permSubs.get(name); if (map == null) { map = new WeakHashMap<Permissible, Boolean>(); permSubs.put(name, map);/*from w w w .ja v a2 s. com*/ } map.put(permissible, true); }
From source file:org.dragonet.plugin.MixedPluginManager.java
@Override public void subscribeToDefaultPerms(boolean op, Permissible permissible) { Map<Permissible, Boolean> map = defSubs.get(op); if (map == null) { map = new WeakHashMap<Permissible, Boolean>(); defSubs.put(op, map);//from w w w . ja va 2 s. c om } map.put(permissible, true); }
From source file:hudson.scm.SubversionSCM.java
private synchronized Map<AbstractProject, List<External>> getProjectExternalsCache() { if (projectExternalsCache == null) { projectExternalsCache = new WeakHashMap<AbstractProject, List<External>>(); }//from w w w . ja v a2s . c om return projectExternalsCache; }
From source file:conf.Configuration.java
/** * Load a class by name.//from w w w .ja va 2 s.c om * * @param name the class name. * @return the class object. * @throws ClassNotFoundException if the class is not found. */ public Class<?> getClassByName(String name) throws ClassNotFoundException { Map<String, Class<?>> map; synchronized (CACHE_CLASSES) { map = CACHE_CLASSES.get(classLoader); if (map == null) { map = Collections.synchronizedMap(new WeakHashMap<String, Class<?>>()); CACHE_CLASSES.put(classLoader, map); } } Class clazz = map.get(name); if (clazz == null) { clazz = Class.forName(name, true, classLoader); if (clazz != null) { // two putters can race here, but they'll put the same class map.put(name, clazz); } } return clazz; }
From source file:org.jiemamy.utils.collection.CollectionsUtil.java
/** * {@link WeakHashMap}?????//from ww w . j a v a 2 s. c o m * * @param <K> {@link WeakHashMap}?? * @param <V> {@link WeakHashMap}?? * @return {@link WeakHashMap}??? * @see WeakHashMap#WeakHashMap() */ public static <K, V> WeakHashMap<K, V> newWeakHashMap() { return new WeakHashMap<K, V>(); }
From source file:co.cask.cdap.common.conf.Configuration.java
/** * Load a class by name, returning null rather than throwing an exception * if it couldn't be loaded. This is to avoid the overhead of creating * an exception.//www . j a v a 2 s. c om * * @param name the class name * @return the class object, or null if it could not be found. */ public Class<?> getClassByNameOrNull(String name) { Map<String, Class<?>> map; synchronized (CACHE_CLASSES) { map = CACHE_CLASSES.get(classLoader); if (map == null) { map = Collections.synchronizedMap(new WeakHashMap<String, Class<?>>()); CACHE_CLASSES.put(classLoader, map); } } Class<?> clazz = map.get(name); if (clazz == null) { try { clazz = Class.forName(name, true, classLoader); } catch (ClassNotFoundException e) { // Leave a marker that the class isn't found map.put(name, NEGATIVE_CACHE_SENTINEL); return null; } // two putters can race here, but they'll put the same class map.put(name, clazz); return clazz; } else if (clazz == NEGATIVE_CACHE_SENTINEL) { return null; // not found } else { // cache hit return clazz; } }