Author: andre
Date: 2010-05-31 11:19:38 +0200 (Mon, 31 May 2010)
New Revision: 42317

Removed:
   
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/RecreateCacheFunction.java
Modified:
   
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java
Log:
MMB-1954 plus removed RecreateCachesF. and put code in CreateCachesFunctions

Modified: 
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java
===================================================================
--- 
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java
  2010-05-31 09:16:48 UTC (rev 42316)
+++ 
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java
  2010-05-31 09:19:38 UTC (rev 42317)
@@ -39,9 +39,11 @@
 /**
  * Triggers (re)creation of caches (streamsourcescaches) of a source node 
  * (streamsources). The parameter 'all' determines whether to recreate all 
caches
- * or just to transcode newly configured streams.
+ * or just to transcode newly configured streams. The parameter 'cache' can 
hold the
+ * node number of a singe caches node to retranscode.
  *
  * @author Michiel Meeuwissen
+ * @author André van Toly
  * @version $Id$
  */
 
@@ -49,9 +51,12 @@
 
     private static final Logger LOG = 
Logging.getLoggerInstance(CreateCachesFunction.class);
 
-    public final static Parameter[] CACHE_PARAMETERS = { new Parameter("all", 
java.lang.Boolean.class) };
+    public final static Parameter[] PARAMETERS = { 
+        new Parameter("all", java.lang.Boolean.class),
+        new Parameter("cache", org.mmbase.bridge.Node.class)
+    };
     public CreateCachesFunction() {
-        super("createcaches", CACHE_PARAMETERS);
+        super("createcaches", PARAMETERS);
     }
 
     /**
@@ -86,27 +91,62 @@
                 && 
node.getCloud().may(ActionRepository.getInstance().get("streams", 
"retrigger_jobs"), null)) {
             
             Boolean all = (Boolean) parameters.get("all");
-            LOG.info("Recreating caches for #" + node.getNumber() + ", doing 
all: " + all);
-            final Field url = node.getNodeManager().getField("url");
+            Node cache = (Node) parameters.get("cache");
 
             {
-                Node mediafragment = node.getNodeValue("mediafragment");
-                String cachestype = 
node.getNodeManager().getProperty("org.mmbase.streams.cachestype");
-                NodeList list = SearchUtil.findRelatedNodeList(mediafragment, 
cachestype, "related"); 
-                
-                // when the streamsourcescaches are initially of the wrong 
type they don't get deleted, this helps a bit
-                if (list.size() < 1) {
-                    if (cachestype.startsWith("video")) {
-                        list = SearchUtil.findRelatedNodeList(mediafragment, 
"audiostreamsourcescaches", "related");
-                    } else if (cachestype.startsWith("audio")) {
-                        list = SearchUtil.findRelatedNodeList(mediafragment, 
"videostreamsourcescaches", "related");
-                    }
-                }
-
+                final Field url = node.getNodeManager().getField("url");
                 final Processor cc = getCacheCreator(url);                
                 Map<String, JobDefinition> jdlist = cc.getCreatecachesList();
-                if ( list.size() > 0 && ! all ) {
-                    jdlist = newJobList(list, jdlist);
+
+                if (cache != null && 
node.getCloud().hasNode(cache.getNumber())) {
+                    // just one
+                    String in = null;
+                    Node inNode = cache.getNodeValue("id");
+                    if (inNode.getNumber() != node.getNumber()) {
+                        in = "" + inNode.getNumber();
+                    }
+                    String id     = "re-cache";
+                    String label  = cache.getStringValue("label");
+                    MimeType mt   = new MimeType( 
cache.getStringValue("mimetype") );
+                    String key    = cache.getStringValue("key");
+                    Transcoder tr = null;
+                    try {
+                        tr = AbstractTranscoder.getInstance(key);
+                    } catch (ClassNotFoundException cnf) {
+                        LOG.error("Class not found, transcoder in key '" + key 
+ "' does not exist? - " + cnf);
+                        return false;
+                    } catch (InstantiationException ie) {
+                        LOG.error("Exception while instantiating transcoder 
for key '" + key + "' - " + ie);
+                        return false;
+                    } catch (Exception e) {
+                        LOG.error("Exception while trying to (re)transcode - " 
+ e);
+                        return false;
+                    }
+        
+                    JobDefinition jd = new JobDefinition(id, in, label, tr, 
mt, Stage.TRANSCODER);
+                    jdlist.clear();
+                    jdlist.put(id, jd);
+                    LOG.info("Re-transcodig cache #" + cache.getNumber() + " : 
" + id + " [" + jd + "]");
+                    
+                } else {
+                    // list
+                    Node mediafragment = node.getNodeValue("mediafragment");
+                    String cachestype = 
node.getNodeManager().getProperty("org.mmbase.streams.cachestype");
+                    NodeList list = 
SearchUtil.findRelatedNodeList(mediafragment, cachestype, "related"); 
+                    
+                    // when the streamsourcescaches are initially of the wrong 
type they don't get deleted, this helps a bit
+                    if (list.size() < 1) {
+                        if (cachestype.startsWith("video")) {
+                            list = 
SearchUtil.findRelatedNodeList(mediafragment, "audiostreamsourcescaches", 
"related");
+                        } else if (cachestype.startsWith("audio")) {
+                            list = 
SearchUtil.findRelatedNodeList(mediafragment, "videostreamsourcescaches", 
"related");
+                        }
+                    }
+    
+                    if ( list.size() > 0 && ! all ) {
+                        jdlist = newJobList(list, jdlist);
+                    }
+                    LOG.info("Recreating caches for #" + node.getNumber() + ", 
doing all: " + all);
                 }
                 
                 if (cc != null) {
@@ -125,8 +165,9 @@
     
     private Map<String, JobDefinition> newJobList(NodeList list, Map<String, 
JobDefinition> jdlist) {
         Map<String, JobDefinition> new_jdlist = new LinkedHashMap<String, 
JobDefinition>();
+        Map<String, String> caches = new HashMap<String, String>();
+        Map<String, String> config = new HashMap<String, String>();
         // make keys from current config entries
-        Map<String, String> config = new HashMap<String, String>();
         for (Map.Entry<String, JobDefinition> entry : jdlist.entrySet()) {
             String id = entry.getKey();
             JobDefinition jd = entry.getValue();
@@ -136,7 +177,6 @@
             }
         }
         // for convenience make a map of caches keys 
-        Map<String, String> caches = new HashMap<String, String>();
         for (Node cache : list) {
             caches.put("" + cache.getNumber(), cache.getStringValue("key"));
         }
@@ -150,8 +190,6 @@
             
             if (config_key != null && !caches.containsValue(config_key)) {
                 // not in caches, must be new config
-                LOG.info("@ (new config) not in caches : " + config_id + " [" 
+ config_key + "]");
-                
                 JobDefinition jd = jdlist.get(config_id);
                 Transcoder tr = jd.getTranscoder(); 
                 String label = jd.getLabel(); 
@@ -162,36 +200,32 @@
                 
                 // check if it's inId is already a cached node
                 if (caches.containsValue(inKey)) {
-                    LOG.info("@ in new_jdlist: " + inId + " [" + inKey + "]");
                     String in = "";
                     for (Node n : list) {
                         if (n.getStringValue("key").equals(inKey)) {
                             in = "" + n.getNumber();
-                            LOG.info("@ cache as source node #" + in);
-                            break;
+                            break;  // can only be 1
                         }
                     }
                     
                     jd = new JobDefinition(config_id, in, label, tr, mt, 
Stage.TRANSCODER);
                     if (! new_jdlist.containsKey(config_id)) {
                         new_jdlist.put(config_id, jd);
-                        LOG.info("@ put in new_jdlist: " + config_id);
                     }
                     
                 } else {
                     // inId not yet cached
                     if (! new_jdlist.containsKey(inId)) {
                         new_jdlist.put(inId, jdlist.get(inId) );
-                        LOG.info("@ inId in new_jdlist: " + inId);
                     }
                     
                     if (! new_jdlist.containsKey(config_id)) {
                         new_jdlist.put(config_id, jdlist.get(config_id) );
-                        LOG.info("@ config_id in new_jdlist: " + config_id);
                     }
                 }
             }
         }
+
         return new_jdlist;
     }    
 }

Deleted: 
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/RecreateCacheFunction.java
===================================================================
--- 
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/RecreateCacheFunction.java
 2010-05-31 09:16:48 UTC (rev 42316)
+++ 
mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/RecreateCacheFunction.java
 2010-05-31 09:19:38 UTC (rev 42317)
@@ -1,118 +0,0 @@
-/*
-
-This file is part of the MMBase Streams application,
-which is part of MMBase - an open source content management system.
-    Copyright (C) 2009 André van Toly, Michiel Meeuwissen
-
-MMBase Streams is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-MMBase Streams is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with MMBase. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-package org.mmbase.streams;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-
-
-import org.mmbase.streams.createcaches.*;
-import org.mmbase.streams.createcaches.Processor;
-import org.mmbase.streams.transcoders.*;
-
-import org.mmbase.util.MimeType;
-import org.mmbase.util.functions.*;
-import org.mmbase.bridge.*;
-import org.mmbase.bridge.util.*;
-import org.mmbase.storage.search.FieldCompareConstraint;
-import org.mmbase.security.ActionRepository;
-import org.mmbase.datatypes.processors.*;
-import org.mmbase.util.logging.*;
-
-/**
- * Triggers recreation of one streamsourcescaches belonging to a streamsources 
node.
- * Uses for id of input stream not id from configuration but nodenumber of 
previously 
- * cached stream node.
- *
- * @author Michiel Meeuwissen
- * @author Andr&eacute; van Toly
- * @version $Id$
- */
-
-public class RecreateCacheFunction extends NodeFunction<Boolean> {
-
-    private static final Logger LOG = 
Logging.getLoggerInstance(RecreateCacheFunction.class);
-
-    // parameter definitions
-    public final static Parameter[] RECACHE_PARAMETERS = { new 
Parameter("recache", org.mmbase.bridge.Node.class) };
-
-    public RecreateCacheFunction() {
-        super("recache", RECACHE_PARAMETERS);
-    }
-
-    @Override
-    protected Boolean getFunctionValue(final Node node, final Parameters 
parameters) {
-        LOG.debug("params: " + parameters);
-        if (node.getNumber() > 0
-                && 
node.getCloud().may(ActionRepository.getInstance().get("streams", 
"retrigger_jobs"), null)) {
-
-            Node recache = (Node) parameters.get("recache");
-            LOG.info("Recreating cache #" + recache.getNumber() + " for node 
#" + node.getNumber());
-            final Field url = node.getNodeManager().getField("url");
-
-            String in = null;
-            Node inNode = recache.getNodeValue("id");
-            if (inNode.getNumber() != node.getNumber()) {
-                in = "" + inNode.getNumber();
-            }
-            String id        = "recache";
-            String label     = recache.getStringValue("label");
-            String mimetype  = recache.getStringValue("mimetype");
-            String key       = recache.getStringValue("key");
-            Transcoder transcoder = null;
-            try {
-                transcoder = AbstractTranscoder.getInstance(key);
-            } catch (ClassNotFoundException cnf) {
-                LOG.error("Class not found, transcoder in key '" + key + "' 
does not exist? - " + cnf);
-                return false;
-            } catch (InstantiationException ie) {
-                LOG.error("Exception while instantiating transcoder for key '" 
+ key + "' - " + ie);
-                return false;
-            } catch (Exception e) {
-                LOG.error("Exception while trying to (re)transcode - " + e);
-                return false;
-            }
-
-            JobDefinition jd = new JobDefinition(id, in, label, transcoder, 
new MimeType(mimetype), Stage.TRANSCODER);
-            Map<String, JobDefinition> jdlist = new LinkedHashMap<String, 
JobDefinition>();
-            jdlist.put(id, jd);
-
-            {
-                final Processor cc = CreateCachesFunction.getCacheCreator(url);
-
-                if (cc != null) {
-                    LOG.service("Calling " + cc);
-                    
cc.createCaches(node.getCloud().getNonTransactionalCloud(), node.getNumber(), 
jdlist);
-
-                    return true;
-                } else {
-                    LOG.error("No CreateCacheProcessor in " + url);
-                    return false;
-                }
-            }
-
-        } else {
-            return false;
-        }
-    }
-
-}

_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to