changeset 193:955da8a90b33

Made PluginObjectStore a singleton.
author Denis Lila <dlila@redhat.com>
date Thu, 31 Mar 2011 15:15:29 -0400
parents cea9ea395406
children fc3bcf836c77
files ChangeLog plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java plugin/icedteanp/java/sun/applet/PluginObjectStore.java
diffstat 3 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Mar 31 14:35:01 2011 -0400
+++ b/ChangeLog	Thu Mar 31 15:15:29 2011 -0400
@@ -1,3 +1,13 @@
+2011-03-31  Denis Lila  <dlila@redhat.com>
+
+	* plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java
+	(store): Make private and remove fixme to make private.
+	* plugin/icedteanp/java/sun/applet/PluginObjectStore.java
+	(PluginObjectStore): Make it a singleton using enum.
+	(objects, counts, identifiers, lock, wrapped, nextUniqueIdentifier,
+	 checkNeg): Made instance methods/members.
+	(getInstance): New static method.
+
 2011-03-31  Denis Lila  <dlila@redhat.com>
 
 	* plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java
--- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java	Thu Mar 31 14:35:01 2011 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java	Thu Mar 31 15:15:29 2011 -0400
@@ -225,8 +225,7 @@
     private static Hashtable<ClassLoader, URL> classLoaders = new Hashtable<ClassLoader, URL>();
     private static Hashtable<Integer, ClassLoader> instanceClassLoaders = new Hashtable<Integer, ClassLoader>();
 
-    // FIXME: make private
-    public PluginObjectStore store = new PluginObjectStore();
+    private PluginObjectStore store = PluginObjectStore.getInstance();
     private Throwable throwable = null;
     private ClassLoader liveconnectLoader = ClassLoader.getSystemClassLoader();
     int identifier = 0;
--- a/plugin/icedteanp/java/sun/applet/PluginObjectStore.java	Thu Mar 31 14:35:01 2011 -0400
+++ b/plugin/icedteanp/java/sun/applet/PluginObjectStore.java	Thu Mar 31 15:15:29 2011 -0400
@@ -40,14 +40,21 @@
 import java.util.HashMap;
 import java.util.Map;
 
-public class PluginObjectStore {
-    private static HashMap<Integer, Object> objects = new HashMap<Integer, Object>();
-    private static HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
-    private static HashMap<Object, Integer> identifiers = new HashMap<Object, Integer>();
-    private static final Object lock = new Object();
+// Enums are the best way to implement singletons.
+enum PluginObjectStore {
+    INSTANCE;
 
-    private static boolean wrapped = false;
-    private static int nextUniqueIdentifier = 1;
+    private HashMap<Integer, Object> objects = new HashMap<Integer, Object>();
+    private HashMap<Integer, Integer> counts = new HashMap<Integer, Integer>();
+    private HashMap<Object, Integer> identifiers = new HashMap<Object, Integer>();
+    private final Object lock = new Object();
+
+    private boolean wrapped = false;
+    private int nextUniqueIdentifier = 1;
+
+    public static PluginObjectStore getInstance() {
+        return INSTANCE;
+    }
 
     public Object getObject(Integer identifier) {
         synchronized(lock) {
@@ -78,7 +85,7 @@
         }
     }
 
-    private static boolean checkNeg() {
+    private boolean checkNeg() {
         if (nextUniqueIdentifier < 1) {
             wrapped = true;
             nextUniqueIdentifier = 1;