diff options
author | Denis Lila <[email protected]> | 2011-03-07 10:45:38 -0500 |
---|---|---|
committer | Denis Lila <[email protected]> | 2011-03-07 10:45:38 -0500 |
commit | 9bc8e7fc91fa792f30093e8a24396d4aa5b9a9b5 (patch) | |
tree | 2be5034044f99b97c1cc3386194f8abf4338bd30 /plugin | |
parent | edd9ce90aa909a19467fc121d8a937b3885e3520 (diff) |
Minor refactoring.
Diffstat (limited to 'plugin')
6 files changed, 41 insertions, 107 deletions
diff --git a/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java b/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java index c758bac..14a839f 100644 --- a/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java +++ b/plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java @@ -43,7 +43,6 @@ import java.util.HashMap; public class AppletSecurityContextManager { // Context identifier -> PluginAppletSecurityContext object. - // FIXME: make private private static HashMap<Integer, PluginAppletSecurityContext> contexts = new HashMap<Integer, PluginAppletSecurityContext>(); diff --git a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java index 4858dc4..0bab269 100644 --- a/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java +++ b/plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java @@ -1228,15 +1228,14 @@ public class PluginAppletSecurityContext { Class<?> c = (Class<?>) store.getObject(classID); Method m = null; Constructor cs = null; - Object o = null; try { if (methodName.equals("<init>") || methodName.equals("<clinit>")) { - o = cs = c.getConstructor(signature.getClassArray()); + cs = c.getConstructor(signature.getClassArray()); store.reference(cs); } else { - o = m = c.getMethod(methodName, signature.getClassArray()); + m = c.getMethod(methodName, signature.getClassArray()); store.reference(m); } } catch (NoSuchMethodException e) { diff --git a/plugin/icedteanp/java/sun/applet/PluginCallRequest.java b/plugin/icedteanp/java/sun/applet/PluginCallRequest.java index 17aa84c..5d78e34 100644 --- a/plugin/icedteanp/java/sun/applet/PluginCallRequest.java +++ b/plugin/icedteanp/java/sun/applet/PluginCallRequest.java @@ -40,10 +40,10 @@ package sun.applet; // FIXME: for each type of request extend a new (anonymous?) // PluginCallRequest. public abstract class PluginCallRequest { - String message; - Long reference; - PluginCallRequest next; - boolean done = false; + private String message; + private Long reference; + private PluginCallRequest next; + private boolean done = false; public PluginCallRequest(String message, Long reference) { this.message = message; diff --git a/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java b/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java index 189f381..bb9f94c 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java +++ b/plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java @@ -38,29 +38,29 @@ exception statement from your version. */ package sun.applet; import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; import java.util.LinkedList; class PluginMessageConsumer { - private static int MAX_PARALLEL_INITS = 1; + private static final int MAX_PARALLEL_INITS = 1; // Each initialization requires 5 responses (tag, handle, width, proxy, cookie) // before the message stack unlocks/collapses. This works out well because we // want to allow upto 5 parallel tasks anyway - private static int MAX_WORKERS = MAX_PARALLEL_INITS * 4; - private static int PRIORITY_WORKERS = MAX_PARALLEL_INITS * 2; + private static final int MAX_WORKERS = MAX_PARALLEL_INITS * 4; + private static final int PRIORITY_WORKERS = MAX_PARALLEL_INITS * 2; - private static Hashtable<Integer, PluginMessageHandlerWorker> initWorkers = new Hashtable<Integer, PluginMessageHandlerWorker>(2); - - LinkedList<String> readQueue = new LinkedList<String>(); private static LinkedList<String> priorityWaitQueue = new LinkedList<String>(); - ArrayList<PluginMessageHandlerWorker> workers = new ArrayList<PluginMessageHandlerWorker>(); - PluginStreamHandler streamHandler = null; - AppletSecurity as; - ConsumerThread consumerThread = new ConsumerThread(); - private static ArrayList<Integer> processedIds = new ArrayList<Integer>(); + + private LinkedList<String> readQueue = new LinkedList<String>(); + private ArrayList<PluginMessageHandlerWorker> workers = new ArrayList<PluginMessageHandlerWorker>(); + private PluginStreamHandler streamHandler; + private ConsumerThread consumerThread = new ConsumerThread(); + + public PluginMessageConsumer(PluginStreamHandler streamHandler) { + this.streamHandler = streamHandler; + this.consumerThread.start(); + } /** * Registers a reference to wait for. Responses to registered priority @@ -78,78 +78,45 @@ class PluginMessageConsumer { * * @param searchString the string to look for in a response */ - public static void registerPriorityWait(String searchString) { + private static void registerPriorityWait(String searchString) { PluginDebug.debug("Registering priority for string " + searchString); synchronized (priorityWaitQueue) { - if (!priorityWaitQueue.contains(searchString)) + if (!priorityWaitQueue.contains(searchString)) { priorityWaitQueue.add(searchString); + } } } /** - * Unregisters a priority reference to wait for. - * - * @param reference The reference to remove - */ - public static void unRegisterPriorityWait(Long reference) { - unRegisterPriorityWait(reference.toString()); - } - - /** * Unregisters a priority string to wait for. * * @param searchString The string to unregister from the priority list */ - public static void unRegisterPriorityWait(String searchString) { + private static void unRegisterPriorityWait(String searchString) { synchronized (priorityWaitQueue) { priorityWaitQueue.remove(searchString); } } - public PluginMessageConsumer(PluginStreamHandler streamHandler) { - - as = new AppletSecurity(); - this.streamHandler = streamHandler; - this.consumerThread.start(); - } - - private String getPriorityStrIfPriority(String message) { + private static String getPriorityStrIfPriority(String message) { // Destroy messages are permanently high priority - if (message.endsWith("destroy")) + if (message.endsWith("destroy")) { return "destroy"; + } synchronized (priorityWaitQueue) { - Iterator<String> it = priorityWaitQueue.iterator(); - - while (it.hasNext()) { - String priorityStr = it.next(); - if (message.indexOf(priorityStr) > 0) - return priorityStr; + for (String priorityStr : priorityWaitQueue) { + if (message.indexOf(priorityStr) > 0) { + return priorityStr; + } } } return null; } - private void addToInitWorkers(Integer instanceNum, PluginMessageHandlerWorker worker) { - synchronized (initWorkers) { - initWorkers.put(instanceNum, worker); - } - } - public void notifyWorkerIsFree(PluginMessageHandlerWorker worker) { - synchronized (initWorkers) { - Iterator<Integer> i = initWorkers.keySet().iterator(); - while (i.hasNext()) { - Integer key = i.next(); - if (initWorkers.get(key).equals(worker)) { - processedIds.add(key); - initWorkers.remove(key); - } - } - } - consumerThread.interrupt(); } @@ -201,8 +168,6 @@ class PluginMessageConsumer { if (message != null) { - String[] msgParts = message.split(" "); - String priorityStr = getPriorityStrIfPriority(message); boolean isPriorityResponse = (priorityStr != null); @@ -220,9 +185,6 @@ class PluginMessageConsumer { continue; // re-loop to try next msg } - if (msgParts[2].equals("tag")) - addToInitWorkers((new Integer(msgParts[1])), worker); - if (isPriorityResponse) { unRegisterPriorityWait(priorityStr); } @@ -257,10 +219,10 @@ class PluginMessageConsumer { if (workers.size() < (MAX_WORKERS - PRIORITY_WORKERS)) { PluginDebug.debug("Cannot find free worker, creating worker " + workers.size()); - worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), as, false); + worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), false); } else if (prioritized) { PluginDebug.debug("Cannot find free worker, creating priority worker " + workers.size()); - worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), as, true); + worker = new PluginMessageHandlerWorker(this, streamHandler, workers.size(), true); } else { return null; } diff --git a/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java b/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java index 17e7a39..26ab3cc 100644 --- a/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java +++ b/plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java @@ -40,16 +40,16 @@ package sun.applet; class PluginMessageHandlerWorker extends Thread { private boolean free = true; - private boolean isPriorityWorker = false; - private int id; - private String message = null; - PluginStreamHandler streamHandler = null; - PluginMessageConsumer consumer = null; + private final boolean isPriorityWorker; + private final int id; + private String message; + private PluginStreamHandler streamHandler; + private PluginMessageConsumer consumer; public PluginMessageHandlerWorker( PluginMessageConsumer consumer, PluginStreamHandler streamHandler, int id, - SecurityManager sm, boolean isPriorityWorker) { + boolean isPriorityWorker) { this.id = id; this.streamHandler = streamHandler; @@ -70,7 +70,7 @@ class PluginMessageHandlerWorker extends Thread { PluginDebug.debug("Consumer (priority=" + isPriorityWorker + ") thread " + id + " consuming " + message); - // ideally, whoever returns things object should mark it + // ideally, whoever returns this object should mark it // busy first, but just in case.. busy(); diff --git a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java index 4eff8dd..d68e8e4 100644 --- a/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java +++ b/plugin/icedteanp/java/sun/applet/PluginStreamHandler.java @@ -46,8 +46,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.nio.charset.Charset; -import java.util.Date; -import java.util.LinkedList; import javax.swing.SwingUtilities; @@ -60,27 +58,14 @@ public class PluginStreamHandler { private JavaConsole console = new JavaConsole(); - LinkedList<String> writeQueue = new LinkedList<String>(); + private PluginMessageConsumer consumer; + private Boolean shuttingDown = false; - PluginMessageConsumer consumer; - Boolean shuttingDown = false; - - PluginAppletViewer pav; public PluginStreamHandler(InputStream inputstream, OutputStream outputstream) throws MalformedURLException, IOException { PluginDebug.debug("Current context CL=" + Thread.currentThread().getContextClassLoader()); - try { - pav = (PluginAppletViewer) ClassLoader.getSystemClassLoader().loadClass("sun.applet.PluginAppletViewer").newInstance(); - PluginDebug.debug("Loaded: " + pav + " CL=" + pav.getClass().getClassLoader()); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } PluginDebug.debug("Creating consumer..."); consumer = new PluginMessageConsumer(this); @@ -353,17 +338,6 @@ public class PluginStreamHandler { return; } - public boolean messageAvailable() { - return writeQueue.size() != 0; - } - - public String getMessage() { - synchronized (writeQueue) { - String ret = writeQueue.size() > 0 ? writeQueue.poll() : ""; - return ret; - } - } - private void showConsole() { SwingUtilities.invokeLater(new Runnable() { public void run() { |