Fix problem with too many open files and problem with not-flushed
[proteocache.git] / datadb / compbio / cassandra / JpredParserLocalFile.java
index c37ec7a..a3e1520 100644 (file)
@@ -14,10 +14,10 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
-public class JpredParserLocalFile {
+public class JpredParserLocalFile implements JpredParser {
        private CassandraCreate cc = new CassandraCreate();
        private String dirprefix;
-       
+
        public void setSource (String newsourceprefix) {
                this.dirprefix = newsourceprefix;
        }
@@ -39,11 +39,13 @@ public class JpredParserLocalFile {
                        int year = cal.get(Calendar.YEAR);
                        int day = cal.get(Calendar.DATE);
                        String date = year + "/" + month + "/" + day;
-                       ParsingForDate(source, date);
+                       if (0 < ParsingForDate(source, date)) {
+                               cc.flushData();
+                       }
                }
        }
 
-       private void ParsingForDate(String input, String date) {
+       private int ParsingForDate(String input, String date) {
                int totalcount = 0;
                int countNoData = 0;
                int countUnclearFASTAid = 0;
@@ -51,6 +53,7 @@ public class JpredParserLocalFile {
                int countinserted = 0;
                int counAlignments = 0;
                int countStrange = 0;
+               int njobs = 0;
 
                System.out.println("Inserting jobs for " + date);
                try {
@@ -92,11 +95,14 @@ public class JpredParserLocalFile {
                                                                        }
                                                                        cc.InsertData(dateWork1, table[0], table[1], table[2], id, "OK", "OK", newprotein, seqs);
                                                                        ++countinsertions;
-                                                                       // flush every 100 insertions
-                                                                       if (0 == countinsertions % 100) {
+                                                                       ++njobs;
+                                                                       // flush every 50 insertions
+                                                                       if (0 == countinsertions % 50) {
                                                                                cc.flushData();
+                                                                               njobs -= 50;
                                                                        }
                                                                }
+                                                               fr.close();
                                                        } catch (IOException e) {
                                                                e.printStackTrace();
                                                        }
@@ -127,5 +133,6 @@ public class JpredParserLocalFile {
                } catch (IOException e) {
                        e.printStackTrace();
                }
+               return njobs;
        }
 }