What's the thinking behind the SerialExecutor?

On Wednesday 20 August 2008 19:00, saces at freenetproject.org wrote:
> Author: saces
> Date: 2008-08-20 18:00:30 +0000 (Wed, 20 Aug 2008)
> New Revision: 22054
> 
> Modified:
>    trunk/freenet/src/freenet/node/Node.java
>    trunk/freenet/src/freenet/pluginmanager/FredPluginThemed.java
>    trunk/freenet/src/freenet/pluginmanager/PluginHandler.java
>    trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
>    trunk/freenet/src/freenet/pluginmanager/PluginManager.java
>    trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java
> Log:
> plugin look&feel integration
> 
> Modified: trunk/freenet/src/freenet/node/Node.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/Node.java  2008-08-20 17:58:52 UTC (rev 
22053)
> +++ trunk/freenet/src/freenet/node/Node.java  2008-08-20 18:00:30 UTC (rev 
22054)
> @@ -217,6 +217,7 @@
>                       } catch (MissingResourceException e) {
>                               throw new 
> InvalidConfigValueException(e.getLocalizedMessage());
>                       }
> +                     PluginManager.setLanguage(L10n.getSelectedLanguage());
>               }
>               
>               public void setPossibleValues(String[] val) {
> 
> Modified: trunk/freenet/src/freenet/pluginmanager/FredPluginThemed.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/FredPluginThemed.java     
> 2008-08-20 
17:58:52 UTC (rev 22053)
> +++ trunk/freenet/src/freenet/pluginmanager/FredPluginThemed.java     
> 2008-08-20 
18:00:30 UTC (rev 22054)
> @@ -3,6 +3,8 @@
>   * http://www.gnu.org/ for further details of the GPL. */
>  package freenet.pluginmanager;
>  
> +import freenet.clients.http.PageMaker.THEME;
> +
>  /**
>   * Interface that has to be implemented for plugins that wants to use
>   * nodes html look (css theme) but not PageMaker.<br /> 
> @@ -14,6 +16,6 @@
>   */
>  public interface FredPluginThemed {
>  
> -     public void setTheme(String theme);
> +     public void setTheme(THEME theme);
>  
>  }
> 
> Modified: trunk/freenet/src/freenet/pluginmanager/PluginHandler.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginHandler.java        
> 2008-08-20 
17:58:52 UTC (rev 22053)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginHandler.java        
> 2008-08-20 
18:00:30 UTC (rev 22054)
> @@ -20,7 +20,7 @@
>        * @param plug
>        */
>       public static PluginInfoWrapper startPlugin(PluginManager pm, String 
filename, FredPlugin plug, PluginRespirator pr) {
> -             final PluginInfoWrapper pi = new PluginInfoWrapper(plug, 
> filename);
> +             final PluginInfoWrapper pi = new PluginInfoWrapper(pr, plug, 
> filename);
>               final PluginStarter ps = new PluginStarter(pr, pi);
>               ps.setPlugin(pm, plug);
>               // We must start the plugin *after startup has finished*
> 
> Modified: trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java    
2008-08-20 17:58:52 UTC (rev 22053)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java    
2008-08-20 18:00:30 UTC (rev 22054)
> @@ -13,6 +13,7 @@
>       private final String className;
>       private Thread thread;
>       private final long start;
> +     final PluginRespirator pr;
>       private final String threadName;
>       final FredPlugin plug;
>       private final boolean isPproxyPlugin;
> @@ -27,11 +28,14 @@
>       private HashSet<String> toadletLinks = new HashSet<String>();
>       private volatile boolean stopping = false;
>       private volatile boolean unregistered = false;
> +     private final boolean isThemedPlugin;
> +     private final boolean isL10nPlugin;
>       
> -     public PluginInfoWrapper(FredPlugin plug, String filename) {
> +     public PluginInfoWrapper(PluginRespirator pr, FredPlugin plug, String 
filename) {
>               this.plug = plug;
>               className = plug.getClass().toString();
>               this.filename = filename;
> +             this.pr = pr;
>               threadName = 'p' + className.replaceAll("^class ", "") + '_' + 
hashCode();
>               start = System.currentTimeMillis();
>               fedPluginThread = true;
> @@ -43,6 +47,8 @@
>               isMultiplePlugin = (plug instanceof FredPluginMultiple);
>               isFCPPlugin = (plug instanceof FredPluginFCP);
>               isVersionedPlugin = (plug instanceof FredPluginVersioned);
> +             isThemedPlugin = (plug instanceof FredPluginThemed);
> +             isL10nPlugin = (plug instanceof FredPluginL10n);
>       }
>  
>       void setThread(Thread ps) {
> @@ -179,6 +185,13 @@
>       public boolean isFCPPlugin() {
>               return isFCPPlugin;
>       }
> +     
> +     public boolean isThemedPlugin() {
> +             return isThemedPlugin;
> +     }
> +     public boolean isL10nPlugin() {
> +             return isL10nPlugin;
> +     }
>  
>       public synchronized boolean isStopping() {
>               return stopping;
> 
> Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginManager.java        
> 2008-08-20 
17:58:52 UTC (rev 22053)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java        
> 2008-08-20 
18:00:30 UTC (rev 22054)
> @@ -25,10 +25,12 @@
>  import java.util.zip.ZipException;
>  
>  import freenet.client.HighLevelSimpleClient;
> +import freenet.clients.http.PageMaker.THEME;
>  import freenet.config.InvalidConfigValueException;
>  import freenet.config.SubConfig;
>  import freenet.keys.FreenetURI;
>  import freenet.l10n.L10n;
> +import freenet.l10n.L10n.LANGUAGE;
>  import freenet.node.Node;
>  import freenet.node.NodeClientCore;
>  import freenet.node.RequestStarter;
> @@ -38,10 +40,12 @@
>  import freenet.support.HexUtil;
>  import freenet.support.JarClassLoader;
>  import freenet.support.Logger;
> +import freenet.support.SerialExecutor;
>  import freenet.support.api.HTTPRequest;
>  import freenet.support.api.StringArrCallback;
>  import freenet.support.io.Closer;
>  import freenet.support.io.FileUtil;
> +import freenet.support.io.NativeThread;
>  
>  public class PluginManager {
>  
> @@ -65,9 +69,14 @@
>       private boolean logMINOR;
>       private boolean logDEBUG;
>       private final HighLevelSimpleClient client;
> +     
> +     private static PluginManager selfinstance = null;
>  
> +     private THEME fproxyTheme;
> +     
> +     private final SerialExecutor executor;
> +
>       public PluginManager(Node node) {
> -
>               logMINOR = Logger.shouldLog(Logger.MINOR, this);
>               logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
>               // config 
> @@ -85,7 +94,10 @@
>  
>               client = 
> core.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS, 
true);
>  
> -
> +             // callback executor
> +             executor = new SerialExecutor(NativeThread.NORM_PRIORITY);
> +             executor.start(node.executor, "PM callback executor");
> +             
>               pmconfig = new SubConfig("pluginmanager", node.config);
>  //           pmconfig.register("configfile", "fplugins.ini", 9, true, 
true, "PluginConfig.configFile", "PluginConfig.configFileLong",
>  //                           new StringCallback() {
> @@ -140,6 +152,9 @@
>                               startPluginAuto(name, false);
>  
>               pmconfig.finishedInitialization();
> +             
> +             fproxyTheme = 
THEME.themeFromName(node.config.get("fproxy").getString("css"));
> +             selfinstance = this;
>       }
>  
>       private String[] getConfigLoadString() {
> @@ -204,7 +219,7 @@
>       }
>  
>       public void startPluginFreenet(final String filename, boolean store) {
> -             realStartPlugin(new PluginDownLoaderFreenet(client), filename, 
> true);
> +             realStartPlugin(new PluginDownLoaderFreenet(client), filename, 
> store);
>       }
>  
>       private void realStartPlugin(final PluginDownLoader pdl, final String 
filename, final boolean store) {
> @@ -222,7 +237,7 @@
>                               try {
>                                       plug = loadPlugin(pdl, filename);
>                                       
> pluginProgress.setProgress(PluginProgress.STARTING);
> -                                     PluginInfoWrapper pi = 
> PluginHandler.startPlugin(PluginManager.this, 
filename, plug, new PluginRespirator(node, PluginManager.this));
> +                                     PluginInfoWrapper pi = 
> PluginHandler.startPlugin(PluginManager.this, 
filename, plug, new PluginRespirator(node, PluginManager.this, plug));
>                                       synchronized(pluginWrappers) {
>                                               pluginWrappers.add(pi);
>                                       }
> @@ -845,4 +860,52 @@
>                       return "PluginProgress[name=" + name + ",startingTime=" 
> + startingTime 
+ ",progress=" + pluginProgress + "]";
>               }
>       }
> +
> +     public void setFProxyTheme(final THEME cssName) {
> +             //if (fproxyTheme.equals(cssName)) return;
> +             fproxyTheme = cssName;
> +             synchronized(pluginWrappers) {
> +                     for(PluginInfoWrapper pi: pluginWrappers) {
> +                             pi.pr.getPageMaker().setTheme(cssName);
> +                             if(pi.isThemedPlugin()) {
> +                                     final FredPluginThemed plug = 
> (FredPluginThemed)(pi.plug);
> +                                     executor.execute(new Runnable() {
> +                                             public void run() {
> +                                                     try {
> +                                                             
> plug.setTheme(cssName);
> +                                                     } catch (Throwable t) {
> +                                                             
> Logger.error(this, "Cought Trowable in Callback", t);
> +                                                     }
> +                                             }}, "Callback");
> +                             }
> +                     }
> +             }
> +     }
> +
> +     public static void setLanguage(LANGUAGE lang) {
> +             if (selfinstance == null) return;
> +             selfinstance.setPluginLanguage(lang);
> +     }
> +
> +     private void setPluginLanguage(final LANGUAGE lang) {
> +             synchronized(pluginWrappers) {
> +                     for(PluginInfoWrapper pi: pluginWrappers) {
> +                             if(pi.isL10nPlugin()) {
> +                                     final FredPluginL10n plug = 
> (FredPluginL10n)(pi.plug);
> +                                     executor.execute(new Runnable() {
> +                                             public void run() {
> +                                                     try {
> +                                                             
> plug.setLanguage(lang);
> +                                                     } catch (Throwable t) {
> +                                                             
> Logger.error(this, "Cought Trowable in Callback", t);
> +                                                     }
> +                                             }}, "Callback");
> +                             }
> +                     }
> +             }
> +     }
> +
> +     public THEME getFProxyTheme() {
> +             return fproxyTheme;
> +     }
>  }
> 
> Modified: trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java     
> 2008-08-20 
17:58:52 UTC (rev 22053)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java     
> 2008-08-20 
18:00:30 UTC (rev 22054)
> @@ -14,11 +14,18 @@
>       private final HighLevelSimpleClient hlsc;
>       private final Node node;
>       private final PageMaker pageMaker;
> +     private final FredPlugin plugin;
> +     private final PluginManager pluginManager;
>       
> -     public PluginRespirator(Node node, PluginManager pm) {
> +     public PluginRespirator(Node node, PluginManager pm, FredPlugin plug) {
>               this.node = node;
>               this.hlsc = 
node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS);
> -             this.pageMaker = new PageMaker("clean");
> +             this.plugin = plug;
> +             this.pluginManager = pm;
> +             if (plugin instanceof FredPluginL10n)
> +                     pageMaker = new PageMaker((FredPluginL10n)plugin, 
pluginManager.getFProxyTheme());
> +             else
> +                     pageMaker = new PageMaker(null, 
> pluginManager.getFProxyTheme());
>       }
>       
>       //public HighLevelSimpleClient getHLSimpleClient() throws 
PluginSecurityException {
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20080823/44ccbba0/attachment.pgp>

Reply via email to