Example usage for java.util WeakHashMap keySet

List of usage examples for java.util WeakHashMap keySet

Introduction

In this page you can find the example usage for java.util WeakHashMap keySet.

Prototype

public Set<K> keySet() 

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:Main.java

public static void main(String[] args) {
    WeakHashMap<String, String> weakHashMap = new WeakHashMap<String, String>();

    weakHashMap.put("1", "first");
    weakHashMap.put("2", "two");
    weakHashMap.put("3", "from java2s.com");

    // printing the contents of the Map
    System.out.println("Contents of the Map");
    System.out.println(weakHashMap);

    // populating the set
    Set set = weakHashMap.keySet();
    System.out.println("Contents of the set");
    System.out.println(set);/* www.ja  v a2  s  .co m*/
}

From source file:com.benefit.buy.library.http.query.callback.BitmapAjaxCallback.java

@Override
public final void callback(String url, Bitmap bm, AjaxStatus status) {
    ImageView firstView = v.get();
    WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.remove(url);
    //check if view queue already contains first view 
    if ((ivs == null) || !ivs.containsKey(firstView)) {
        checkCb(this, url, firstView, bm, status);
    }/* ww  w. ja  v  a  2 s. c  o m*/
    if (ivs != null) {
        Set<ImageView> set = ivs.keySet();
        for (ImageView view : set) {
            BitmapAjaxCallback cb = ivs.get(view);
            cb.status = status;
            checkCb(cb, url, view, bm, status);
        }
    }
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

@Override
public final void callback(String url, Bitmap bm, AjaxStatus status) {

    ImageView firstView = v.get();
    WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.remove(url);

    //check if view queue already contains first view 
    if (ivs == null || !ivs.containsKey(firstView)) {
        checkCb(this, url, firstView, bm, status);
    }//  w ww .j  a  va  2  s.c o m

    if (ivs != null) {

        Set<ImageView> set = ivs.keySet();

        for (ImageView view : set) {
            BitmapAjaxCallback cb = ivs.get(view);
            cb.status = status;
            checkCb(cb, url, view, bm, status);
        }

    }

}

From source file:com.meltmedia.cadmium.servlets.ClassLoaderLeakPreventor.java

/**
 * Workaround for leak caused by Mojarra JSF implementation if included in the container.
 * See <a href="http://java.net/jira/browse/JAVASERVERFACES-2746">JAVASERVERFACES-2746</a>
 *///from  w ww  .  j  av a2s.  c  o  m
protected void fixJsfLeak() {
    /*
     Note that since a WeakHashMap is used, it is not the map key that is the problem. However the value is a
     Map with java.beans.PropertyDescriptor as value, and java.beans.PropertyDescriptor has a Hashtable in which
     a class is put with "type" as key. This class may have been loaded by the web application.
            
     One example case is the class org.primefaces.component.menubutton.MenuButton that points to a Map with a key 
     "model" whose PropertyDescriptor.table has key "type" with the class org.primefaces.model.MenuModel as its value.
            
     For performance reasons however, we'll only look at the top level key and remove any that has been loaded by the
     web application.     
     */

    Object o = getStaticFieldValue("javax.faces.component.UIComponentBase", "descriptors");
    if (o instanceof WeakHashMap) {
        WeakHashMap descriptors = (WeakHashMap) o;
        final Set<Class> toRemove = new HashSet<Class>();
        for (Object key : descriptors.keySet()) {
            if (key instanceof Class && isLoadedByWebApplication((Class) key)) {
                // For performance reasons, remove all classes loaded in web application
                toRemove.add((Class) key);

                // This would be more correct, but presumably slower
                /*
                Map<String, PropertyDescriptor> m = (Map<String, PropertyDescriptor>) descriptors.get(key);
                for(Map.Entry<String,PropertyDescriptor> entry : m.entrySet()) {
                  Object type = entry.getValue().getValue("type"); // Key constant javax.el.ELResolver.TYPE
                  if(type instanceof Class && isLoadedByWebApplication((Class)type)) {
                    toRemove.add((Class) key); 
                  }
                }
                */
            }
        }

        if (!toRemove.isEmpty()) {
            info("Removing " + toRemove.size() + " classes from Mojarra descriptors cache");
            for (Class clazz : toRemove) {
                descriptors.remove(clazz);
            }
        }
    }
}

From source file:org.apache.axis.handlers.soap.SOAPService.java

/** 
 * Remove all of this Service's serviceObjects from it known sessions
 *///w  ww.ja  v a2s.co m
public void clearSessions() {
    WeakHashMap map = (WeakHashMap) sessions.get(this.getName());
    if (map == null)
        return;
    Iterator iter = map.keySet().iterator();
    while (iter.hasNext()) {
        Session session = (Session) iter.next();
        session.remove(this.getName());
    }
}