Modify BitspliterCodec: only accept valid paraemeters for k and m
authorMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Mon, 17 Nov 2014 11:23:39 +0000 (12:23 +0100)
committerMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Mon, 17 Nov 2014 11:23:39 +0000 (12:23 +0100)
Modifiy JavaCrsCodec: modify parametercheck
Fix Native library load
Modify Splitte.java: allow initialisation without codecParameter=null
Modify Encoding and Decoding Tasks

Splitter-ng-plugin-bitsplitter/src/bitsplitterplugin/CodecBitsplitter.java
Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/JavaCRSCodec.java
Splitter-ng-plugin-jerasure/src/cz/adamh/utils/NativeUtils.java
Splitter-ng-test/src/SplitterTest.java
Splitter-ng/src/splitterng/DecodingTask.java
Splitter-ng/src/splitterng/EncodingTask.java
Splitter-ng/src/splitterng/Splitter.java

index 2eb4757..f41eb3d 100644 (file)
@@ -23,7 +23,7 @@ public class CodecBitsplitter implements SplitterCodec {
 
        public final static String codecID = "bitsplitter";
        public final static String codecName = "Bitsplitter";
-       public final static String codecDescriptionText = "Simple bitsplitter. 1234567812345678 -> 12341234 56785678";
+       public final static String codecDescriptionText = "Simple bitsplitter. 12345678 12345678 -> 12341234 56785678. For k use 2, 4 or (k mod 8 == 0)";
 
        public final static Map <String, Integer []> codecParameterMinMax;
        public final static Map <String, Integer> codecParameterDefaults;
@@ -92,6 +92,19 @@ public class CodecBitsplitter implements SplitterCodec {
                
                k=(int)codecParameter.get("k");
                m=(int)codecParameter.get("m");
+               
+               //Redundanz berechnunung nur wenn gerade
+               if ((m == 1) && (k%2 != 0) ){
+                       throw new IllegalArgumentException("No redundant Fragment supported for odd parameter k");
+               }
+               //Redundanz berechnunung nur wenn gerade
+               if ( ! ((k == 2) || (k == 4) || (k%8 == 0))){
+                       throw new IllegalArgumentException("Value of k not supported, use 2, 4 or (k mod 8 == 0) ");
+               }
+                               
+               
+               
+               
                //System.out.println("Init Bitsplitter");
                bs = new BitSplitter();
        }
index 5131a3f..4a7c0a0 100644 (file)
@@ -82,6 +82,21 @@ public class JavaCRSCodec implements SplitterCodec {
        public JavaCRSCodec(Map<String, Integer> codecParameter) {
                super();
                
+               parameterCheck(codecParameter);
+
+               
+               k=(int)codecParameter.get("k");
+               m=(int)codecParameter.get("m");
+               w=(int)codecParameter.get("w");
+               packetsize=(int)codecParameter.get("packetsize");
+               matrix= Cauchy.good_general_coding_matrix(k, m, w);
+               bitmatrix = new BitMatrix(matrix, w);
+               erasures = new boolean[k + m];
+               
+       }
+
+       private void parameterCheck(Map<String, Integer> codecParameter)
+                       throws IllegalArgumentException {
                //Test CodecParameter
                for (Entry<String, Integer[]> requiredEntry : codecParameterMinMax
                                .entrySet()) {
@@ -106,16 +121,6 @@ public class JavaCRSCodec implements SplitterCodec {
                                                + requiredEntry.getKey());
                        }
                }
-
-               
-               k=(int)codecParameter.get("k");
-               m=(int)codecParameter.get("m");
-               w=(int)codecParameter.get("w");
-               packetsize=(int)codecParameter.get("packetsize");
-               matrix= Cauchy.good_general_coding_matrix(k, m, w);
-               bitmatrix = new BitMatrix(matrix, w);
-               erasures = new boolean[k + m];
-               
        }
 
        private void checkArraySizes(int fragmentsize) {
index 45fb10f..3924240 100644 (file)
@@ -6,6 +6,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
  
 /**
  * Simple library class for working with JNI (Java Native Interface)
index aebb931..5836c14 100644 (file)
@@ -25,6 +25,7 @@ public class SplitterTest implements SplitterCallback {
        private Collection<Splitter> splitters = new LinkedList<Splitter>();
        private List<CodingTask> finished_encoding_task = new LinkedList<CodingTask>();
        private List<CodingTask> finished_decoding_task = new LinkedList<CodingTask>();
+       private List<CodingTask> running_tasks = new LinkedList<CodingTask>();
 
        // in der Map werden die Metadaten-vorlage für jeden Codec gespeichert
        private Map<Splitter, Map<String, Object>> splitter_metadata_map = new HashMap<Splitter, Map<String, Object>>();
@@ -58,6 +59,8 @@ public class SplitterTest implements SplitterCallback {
                                }
                                // Wenn hier eine Konfiguration für eine plugin-codec
                                // Kombination vorhanden ist, wird der Splitter initialisiert.
+                               Map<String, Integer> codecParameter;
+                               Splitter splitter;
                                switch (p.getPluginID() + "/" + c.getCodecID()) {
 ///-----------------------------------------------------------------------------------------------
 ///-----------------------------------------------------------------------------------------------
@@ -65,7 +68,7 @@ public class SplitterTest implements SplitterCallback {
 ///-----------------------------------------------------------------------------------------------
                                case "jerasure/JerasureCauchyGood":
                                        // Codecparameter Bauen
-                                       Map<String, Integer> codecParameter = new TreeMap<String, Integer>();
+                                       codecParameter = new TreeMap<String, Integer>();
                                        codecParameter.put("k", 2);
                                        codecParameter.put("m", 2);
                                        //codecParameter.put("w", 8);
@@ -89,7 +92,7 @@ public class SplitterTest implements SplitterCallback {
                                        splitter_metadata_map.put(splitterjerasure, metadatajerasure);
                                        break;
 ///-----------------------------------------------------------------------------------------------
-                               case "--jerasure/JerasureReedSolomon":
+                               case "jerasure/JerasureReedSolomon":
                                        // Codecparameter Bauen
                                        Map<String, Integer> codecParameter1 = new TreeMap<String, Integer>();
                                        codecParameter1.put("k", 3);
@@ -115,7 +118,7 @@ public class SplitterTest implements SplitterCallback {
                                        splitter_metadata_map.put(splitterjerasure1, metadatajerasure1);
                                        break;
 ///-----------------------------------------------------------------------------------------------
-                               case "--jerasure/JerasureLiber8tion":
+                               case "jerasure/JerasureLiber8tion":
                                        // Codecparameter Bauen
                                        Map<String, Integer> codecParameter2 = new TreeMap<String, Integer>();
                                        codecParameter2.put("k", 3);
@@ -257,6 +260,7 @@ public class SplitterTest implements SplitterCallback {
                                        // Metadaten bauen vorlage
                                        Map<String, Object> metadata1111 = new TreeMap<String, Object>();
                                        metadata1111.put("fragmentsize", (int) 409600);
+                                       metadata1111.put("digest", "SHA-1");
                                        // Beleiebige weitere Metadaten
                                        
                                        splitter_metadata_map.put(splitter1111, metadata1111);
@@ -267,8 +271,15 @@ public class SplitterTest implements SplitterCallback {
 ///-----------------------------------------------------------------------------------------------
 ///-----------------------------------------------------------------------------------------------
                                default:
-                                       System.out.println("\t\tNo Splitter created for: "
-                                                       + p.getPluginID() + "/" + c.getCodecID());
+                                       try {
+                                               splitter = new Splitter(p.getPluginID(), c.getCodecID(),4,1);
+                                               System.out.println("\t\tDefault Splitter created for: "
+                                                               + p.getPluginID() + "/" + c.getCodecID());                                              
+                                       } catch (Exception e) {
+                                               System.out.println("\t\tNO Splitter created for: "
+                                                               + p.getPluginID() + "/" + c.getCodecID() + "\n" + e.getMessage());      
+                                       }
+
                                        break;
                                }
                        }
@@ -326,8 +337,10 @@ public class SplitterTest implements SplitterCallback {
                        
 
                                        // Hier wird codiert. Der Encodingtask
-                                       splitter.encode(new EncodingTask(srcfile, Paths
-                                                       .get("splitDir"), this, metadata));
+                                       EncodingTask task = new EncodingTask(srcfile, Paths
+                                                       .get("splitDir"), this, metadata);
+                                       splitter.encode(task);
+                                       running_tasks.add(task);
                                } catch (InterruptedException | IOException e) {
                                        e.printStackTrace();
                                }
@@ -474,7 +487,7 @@ public class SplitterTest implements SplitterCallback {
 
                                        }
                                        DecodingTask dectask = new DecodingTask(fragmentPaths,
-                                                       restorefile, this, enctask.getMetadata());
+                                                       restorefile, this, enctask.getMetadataAsDeepCopy());
                                        for (Splitter spl : splitters) {
                                                if (spl.getCurrentPlugin().getPluginDescription()
                                                                .getPluginID() == (String) enctask
@@ -485,6 +498,7 @@ public class SplitterTest implements SplitterCallback {
                                                        System.out.println("Auftrag angenommen..."
                                                                        + restorefile);
                                                        spl.decode(dectask);
+                                                       running_tasks.add(dectask);
                                                }
                                        }
 
@@ -556,6 +570,7 @@ public class SplitterTest implements SplitterCallback {
        @Override
        public void codingFailed(CodingTask task, String reason) {
                synchronized (task) { // damit die Ausgabe nicht verwürfelt wird
+                       running_tasks.remove(task);
                        System.err.println("Coding Failed: "
                                        + task.getFilePath().toString() + "  Reason:" + reason);
                }
@@ -566,6 +581,7 @@ public class SplitterTest implements SplitterCallback {
        public synchronized void codingSuccessfull(CodingTask task) {
                synchronized (task) { // damit die Ausgabe nicht verwürfelt wird
                        long duration = 0;
+                       running_tasks.remove(task);
                        if (task instanceof EncodingTask) {
                                finished_encoding_task.add(task);
                                duration = (long) task.getMetadata("time_encode_end")
@@ -576,7 +592,9 @@ public class SplitterTest implements SplitterCallback {
                                                - (long) task.getMetadata("time_decode_start");
                        }
 
-                       System.err.println("Coding OK: " + task.getFilePath().toString()
+                       System.err.println("CodingTask "
+                                       + finished_encoding_task.indexOf(task)
+                                       + " OK: " + task.getFilePath().toString()
                                        + "  Codec: " + task.getMetadata("pluginid") + "/"
                                        + task.getMetadata("codecid") + "  T(ms):" + duration);
                }
index 8898db5..9d9372f 100644 (file)
@@ -47,9 +47,6 @@ public class DecodingTask extends CodingTask {
                erased = new boolean[fragmentPathsMap.size()];
 
                readMetadataMap();
-               if (digestFunction != null){
-                       digestCheck(); // remove from fragmentPathsMap when not OK
-               }
                
        }
 
@@ -64,7 +61,7 @@ public class DecodingTask extends CodingTask {
                erased = new boolean[this.dataFragmentMap.size()];
 
                readMetadataMap();
-
+               
        }
 
        private void readMetadataMap() {
@@ -104,7 +101,10 @@ public class DecodingTask extends CodingTask {
                                                                        "")), (String) e.getValue());
                                }
                        }
-
+                       if (digestFunction != null){
+                               digestCheck(); // remove from fragmentPathsMap when not OK
+                       }
+                       
                }
 
        }
@@ -162,6 +162,7 @@ public class DecodingTask extends CodingTask {
        }
 
        private void digestCheck() {
+               //TODO digestCheck for Byte Arrays 
                if (isFileTask) {
                        for (Entry<Integer, Path> entry : fragmentPathsMap.entrySet()) {
                                if (entry.getValue() != null) {
@@ -179,7 +180,7 @@ public class DecodingTask extends CodingTask {
                                        } catch (NoSuchAlgorithmException e) {
                                                fragmentDigests=null;
                                                digestFunction=null;
-                                               setMetadata("digest_error", e.getMessage());
+                                               setMetadata("digesterror", e.getMessage());
                                                break;
                                        } catch (IOException e) {
                                                setMetadata("digestcheck_" + entry.getKey(), e.getMessage());
index 708430a..69a9680 100644 (file)
@@ -184,7 +184,7 @@ public class EncodingTask extends CodingTask {
                                        //TODO Besseres Handling, wenn Algorithm nicht vorhanden
                                        fragmentDigests=null;
                                        digestFunction=null;
-                                       setMetadata("digest_error", e.getMessage());
+                                       setMetadata("digesterror", e.getMessage());
                                        break;
                                }
                        }
index ff9d1b6..f9f7d3d 100644 (file)
@@ -82,6 +82,9 @@ public class Splitter {
                        throws IllegalArgumentException {
                
                checkAndSetPlugin(pluginID, codecID);
+               if (codecParameter == null) {
+                       codecParameter = new HashMap<String, Integer>();
+               }
                this.codecParameter = codecParameter;
                codecParameter.put("k", k);
                codecParameter.put("m", m);