Changeset 352 for kraken-cron/src

Show
Ignore:
Timestamp:
10/17/09 14:47:45 (11 months ago)
Author:
periphery
Message:

minor modifications on kraken-cron.
exception handling and logging.
scheduler reverted from singleton class.
etc..

Location:
kraken-cron/src/main/java/org/krakenapps/cron
Files:
1 removed
13 modified
1 moved

Legend:

Unmodified
Added
Removed
  • kraken-cron/src/main/java/org/krakenapps/cron/CronScript.java

    r346 r352  
    22 
    33import java.text.ParseException; 
     4import java.util.NoSuchElementException; 
    45 
    56import org.krakenapps.api.Script; 
     
    7475                        builder.set(CronField.Type.Day_of_Week, args[4]); 
    7576                        manager.registerSchedule(builder.build()); 
    76                          
     77 
    7778                        context.println("Cron : registered."); 
    7879                } catch (ParseException e) { 
     
    8889                        context.println("Cron : unregistered."); 
    8990                } catch (NumberFormatException e) { 
    90                         context.print("USAGE : SCHEDULE_ID"); 
     91                        context.println("USAGE : SCHEDULE_ID"); 
     92                } catch (NoSuchElementException e){ 
     93                        context.println("cron script: no schedule of given id %d", Integer.parseInt(args[0])); 
    9194                } 
    9295        } 
     
    9598        public void usage(String[] args) { 
    9699                context.println("SYNTAX :"); 
    97                 context.println("* * * * * RUNNABLE_NAME\n\r" + "- - - - -\n\r" + "| | | | |\n\r" 
     100                context.println("* * * * * Runnable instance.name\n\r" + "- - - - -\n\r" + "| | | | |\n\r" 
    98101                                + "| | | | +----- day of week (0 - 6) (Sunday=0)\n\r" + "| | | +------- month (1 - 12)\n\r" 
    99102                                + "| | +--------- day of month (1 - 31)\n\r" + "| +----------- hour (0 - 23)\n\r" 
     
    128131                                        context.println("run completed."); 
    129132                                } catch (Exception e) { 
    130                                         context.println("run error: " + e.toString()); 
     133                                        context.println("run() error: " + e.toString()); 
    131134                                        logger.warn("cron script: run error", e); 
    132135                                } 
     
    139142 
    140143        @ScriptUsage(description = "list all active Runnables") 
    141         public void runnable(String[] args) throws InvalidSyntaxException { 
     144        public void runnables(String[] args) throws InvalidSyntaxException { 
    142145                context.println("======================"); 
    143146                context.println(" Active Runnable List"); 
     
    155158                        } 
    156159                } catch (InvalidSyntaxException e) { 
    157                         logger.warn("cron script: runnable error", e); 
     160                        logger.warn("cron script: runnables error", e); 
    158161                } 
    159162        } 
  • kraken-cron/src/main/java/org/krakenapps/cron/CronService.java

    r346 r352  
    1111public interface CronService { 
    1212        void registerSchedule(Schedule schedule); 
     13 
    1314        void unregisterSchedule(int i); 
     15 
    1416        List<String> getScheduleList(); 
     17 
    1518        List<String> getJobList(); 
    1619} 
  • kraken-cron/src/main/java/org/krakenapps/cron/Schedule.java

    r346 r352  
    22 
    33import java.text.ParseException; 
    4 import java.util.Calendar; 
    5 import java.util.Date; 
    64import java.util.HashMap; 
    75import java.util.Map; 
    86 
    97import org.krakenapps.cron.impl.CronField; 
    10 import org.krakenapps.cron.impl.IllegalTypeException; 
    118import org.krakenapps.cron.impl.CronField.Type; 
    129 
     
    1815 */ 
    1916public final class Schedule { 
    20          
     17 
     18        /** 
     19         * fieldName to CronField mapping 
     20         */ 
    2121        private final Map<String, CronField> map; 
    2222        private final String taskName; 
     
    2727        } 
    2828 
    29         private Schedule(Builder builder){ 
     29        private Schedule(Builder builder) { 
    3030                this.map = new HashMap<String, CronField>(); 
    3131                this.map.put("Minute", builder.map.get("Minute")); 
     
    3535                CronField dom = builder.map.get("DayOfMonth"); 
    3636                CronField dow = builder.map.get("DayOfWeek"); 
    37                 try{ 
    38                 CronField.solveCollision(dom, dow); 
    39                 }catch (Exception e) { 
    40                         //must succeed. ignore. 
     37                try { 
     38                        CronField.solveCollision(dom, dow); 
     39                } catch (Exception e) { 
     40                        // must succeed. ignore. 
    4141                } 
    4242                this.map.put("DayOfMonth", dom); 
     
    4545        } 
    4646 
    47  
    4847        /** 
    4948         * returns task Name 
    5049         */ 
    51         public String getTaskInstanceName() { 
     50        public String getTaskName() { 
    5251                return this.taskName; 
    5352        } 
     
    5554        @Override 
    5655        public String toString() { 
    57                 return String.format("%8s %8s %8s %8s %8s / %8s", map.get("Minute"), 
    58                                 map.get("Hour"), map.get("DayOfMonth"), map.get("Month"), map 
    59                                                 .get("DayOfWeek"), taskName); 
     56                return String.format("%8s %8s %8s %8s %8s / %8s", map.get("Minute"), map.get("Hour"), map.get("DayOfMonth"), 
     57                                map.get("Month"), map.get("DayOfWeek"), taskName); 
    6058        } 
    6159 
     
    7674        @Override 
    7775        public boolean equals(Object sche) { 
    78                 return (sche instanceof Schedule) 
    79                                 && this.toString().equals(((Schedule) sche).toString()); 
     76                return (sche instanceof Schedule) && this.toString().equals(((Schedule) sche).toString()); 
    8077        } 
    8178 
     
    10097                        this.taskName = taskName; 
    10198                        try { 
    102                                 this.map.put("Minute", new CronField(CronField.Type.Minute, 
    103                                                 null)); 
     99                                this.map.put("Minute", new CronField(CronField.Type.Minute, null)); 
    104100                                this.map.put("Hour", new CronField(CronField.Type.Hour, null)); 
    105                                 this.map.put("DayOfMonth", new CronField( 
    106                                                 CronField.Type.Day_of_Month, null)); 
    107                                 this.map 
    108                                                 .put("Month", new CronField(CronField.Type.Month, null)); 
    109                                 this.map.put("DayOfWeek", new CronField( 
    110                                                 CronField.Type.Day_of_Week, null)); 
     101                                this.map.put("DayOfMonth", new CronField(CronField.Type.Day_of_Month, null)); 
     102                                this.map.put("Month", new CronField(CronField.Type.Month, null)); 
     103                                this.map.put("DayOfWeek", new CronField(CronField.Type.Day_of_Week, null)); 
    111104                        } catch (ParseException e) { 
    112105                                // must succeed. ignored. 
     
    115108 
    116109                /** 
    117                 * Set cron field with given expression. 
    118                 * Following expressions are supported. 
    119                 * 1. comma(',') as list. e.g:"1,3,4,8" (space inside the list must not 
    120                 * be used) 
    121                 * 2. dash('-') as range. e.g:"1-6", which means 1 to 6 
    122                 * 3. asterisk('*') as wild. e.g:"*", which means every~ 
    123                 * 4. slash('/') as interval. e.g:"* /5" which means every five~ (without whitespace) 
    124                 */ 
    125                 public Builder set(CronField.Type type, String exp) 
    126                                 throws ParseException { 
     110                 * Set cron field with given expression. Following expressions are 
     111                 * supported.  
     112                 * 1. comma(',') as list. e.g:"1,3,4,8" (space inside the list must not be used)  
     113                 * 2. dash('-') as range. e.g:"1-6", which means 1 to 6  
     114                 * 3. asterisk('*') as wild. e.g:"*", which means every~  
     115                 * 4. slash('/') as interval. e.g:"* /5" which means every five~ (without whitespace) 
     116                 */ 
     117                public Builder set(CronField.Type type, String exp) throws ParseException { 
    127118                        this.map.put(type.toString(), new CronField(type, exp)); 
    128119                        return this; 
     
    130121 
    131122                /** 
    132                  * returns schedule object representing scheduling rule of current build 
    133                  * object. e.g. new 
    134                  * Schedule.Builder("test").set(CronField.Type.Minute,"5").build(); 
     123                 * returns schedule object representing scheduling rule of current build object.  
     124                 * e.g. new Schedule.Builder("test").set(CronField.Type.Minute,"5").build(); 
    135125                 * represents schedule of "5 * * * * / test" 
    136126                 */ 
    137                 public Schedule build(){ 
     127                public Schedule build() { 
    138128                        return new Schedule(this); 
    139129                } 
     
    201191        } 
    202192 
     193 
    203194} 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/CronConfig.java

    r346 r352  
    1818 */ 
    1919public class CronConfig { 
    20         // jdbc operations 
    2120        final Logger logger = LoggerFactory.getLogger(CronConfig.class.getName()); 
    2221        private Connection connection; 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/CronField.java

    r346 r352  
    66 
    77/** 
    8  * component of {@link Schedule}. 
    9  * represents a field of the schedule. 
     8 * component of {@link Schedule}. represents a field of the schedule. 
     9 *  
    1010 * @author periphery 
    1111 * @since 1.0.0 
     
    1717        private final String exp; 
    1818 
    19  
    2019        public enum Type { 
    21                 Minute("Minute", 60, 0), Hour("Hour", 24, 0), Day_of_Month( 
    22                                 "DayOfMonth", 31, 1), Month("Month", 12, 1), Day_of_Week( 
    23                                 "DayOfWeek", 7, 0); 
    24                 private final String string; //name of the type. 
    25                 private final int bitLength;  
     20                Minute("Minute", 60, 0),  
     21                Hour("Hour", 24, 0),  
     22                Day_of_Month("DayOfMonth", 31, 1),  
     23                Month("Month", 12, 1),  
     24                Day_of_Week("DayOfWeek", 7, 0); 
     25 
     26                private final String fieldName; // name of the type. 
     27                private final int bitLength; 
    2628                private final int base; 
    2729 
    28                 Type(String arg, int bitLength, int base) { 
    29                         this.string = arg; 
     30                Type(String fieldName, int bitLength, int base) { 
     31                        this.fieldName = fieldName; 
    3032                        this.bitLength = bitLength; 
    3133                        this.base = base; 
     
    3335 
    3436                public String toString() { 
    35                         return this.string; 
     37                        return this.fieldName; 
    3638                } 
    3739 
     
    4446                } 
    4547 
    46                 private int getLast(){ 
     48                private int getLast() { 
    4749                        return this.getBase() + this.getBitLength() - 1; 
    4850                } 
     51 
    4952                /** 
    5053                 * return true if the num is out of range of given type. valid range of 
     
    5659                } 
    5760 
    58  
    5961                private void setBits(BitSet bits, int num) { 
    6062                        if (this.base == 0) 
     
    6365                                bits.set(num - 1); 
    6466                } 
     67 
    6568                /** 
    6669                 * initialize to all_false if type is day of week. 
     
    7073                                bits.set(0, this.bitLength); 
    7174                } 
    72                  
    73                 private boolean isAllTrue(BitSet bits){ 
     75 
     76                private boolean isAllTrue(BitSet bits) { 
    7477                        return bits.nextClearBit(0) >= this.bitLength; 
    7578                } 
    76                 private boolean isAllFalse(BitSet bits){ 
     79 
     80                private boolean isAllFalse(BitSet bits) { 
    7781                        return (bits.nextSetBit(0) == -1); 
    7882                } 
     
    8690 
    8791        /** 
    88          * parse expression and set bitmap. 
    89          * if the expression is null, it is same as expression "*"(wild card) 
    90          */ 
    91         private static String parseExp(CronField.Type type, BitSet bits, String exp) 
    92                         throws ParseException { 
    93                 //filter "*" or null. 
     92         * parse expression and set bitmap. if the expression is null, it is same as 
     93         * expression "*"(wild card) 
     94         */ 
     95        private static String parseExp(CronField.Type type, BitSet bits, String exp) throws ParseException { 
     96                // filter "*" or null. 
    9497                if (exp == null || exp.matches("[*]")) { 
    9598                        type.setBits(bits); 
    9699                        return "*"; 
    97                 //filter empty string. throw Exception. 
     100                        // filter empty string. throw Exception. 
    98101                } else if (exp.length() == 0) { 
    99                         throw new ParseException( 
    100                                         "cron field cannot be set with an empty string : " + exp, 0); 
    101                 //filter list type. 
     102                        throw new ParseException("cron field cannot be set with an empty string : " + exp, 0); 
     103                        // filter list type. 
    102104                } else if (exp.matches("([0-9]+[,])+[0-9]+")) { 
    103105                        String[] splited = exp.split("[,]"); 
     
    105107                                parseExp(type, bits, sp);// recursive call 
    106108                        } 
    107                 //filter interval type 
     109                        // filter interval type 
    108110                } else if (exp.matches("[*]/[0-9]+")) { 
    109111                        try { 
     
    113115                                } 
    114116                        } catch (Exception e) { 
    115                                 throw new ParseException( 
    116                                                 "wrong interval format. e.g. 2/* = every 2nd : " + exp, 
    117                                                 0); 
     117                                throw new ParseException("wrong interval format. e.g. 2/* = every 2nd : " + exp, 0); 
    118118                        } 
    119                 //filter range type 
     119                        // filter range type 
    120120                } else if (exp.matches("[0-9]+[-][0-9]+")) { 
    121121                        int from = Integer.parseInt(exp.split("[-]")[0]); 
    122122                        int to = Integer.parseInt(exp.split("[-]")[1]); 
    123123                        if (to < from || type.invalid(to) || type.invalid(from)) 
    124                                 throw new ParseException("invalida range. e.g. 2-5 = 2 to 5 : " 
    125                                                 + exp, 0); 
     124                                throw new ParseException("invalida range. e.g. 2-5 = 2 to 5 : " + exp, 0); 
    126125                        for (int i = from; !type.invalid(i) && i <= to; i++) { 
    127126                                type.setBits(bits, i); 
    128127                        } 
    129                 //filter single number 
     128                        // filter single number 
    130129                } else if (exp.matches("[0-9]+")) { 
    131130                        int num = Integer.parseInt(exp); 
     
    137136                return exp; 
    138137        } 
    139          
    140         /** 
    141          * if day_of_week is not all_false and day_of_month is all_true, 
    142          * set day_of_month to all_false. 
    143          * this is because it is natural to think "0 0 * * 0" as 'weekly' not 'daily'. 
    144          * this is the reason why day_of_week is initially set to all_false. 
    145          * @param dom day of month 
    146          * @param dow day of week 
    147          * @throws IllegalTypeException when called with cronfield except for dom and dow. 
     138 
     139        /** 
     140         * if day_of_week is not all_false and day_of_month is all_true, set 
     141         * day_of_month to all_false. this is because it is natural to think 
     142         * "0 0 * * 0" as 'weekly' not 'daily'. this is the reason why day_of_week 
     143         * is initially set to all_false. 
     144         *  
     145         * @param dom 
     146         *            day of month 
     147         * @param dow 
     148         *            day of week 
     149         * @throws IllegalTypeException 
     150         *             when called with cronfield except for dom and dow. 
    148151         */ 
    149152        public static void solveCollision(CronField dom, CronField dow) throws IllegalTypeException { 
    150                 if(dom.type != Type.Day_of_Month || dow.type != Type.Day_of_Week)  
     153                if (dom.type != Type.Day_of_Month || dow.type != Type.Day_of_Week) 
    151154                        throw new IllegalTypeException("solveCollision should only be called with dom and dow."); 
    152                 if(dom.type.isAllTrue(dom.bits) && !dow.type.isAllFalse(dow.bits)){ 
     155 
     156                if (dom.type.isAllTrue(dom.bits) && !dow.type.isAllFalse(dow.bits)) { 
    153157                        dom.bits.clear(); 
    154158                } 
    155159        } 
    156          
    157         /** 
    158          * returns next matching occurrence after given start value.(including start value itself)  
     160 
     161        /** 
     162         * returns next matching occurrence after given start value.(including start 
     163         * value itself) 
     164         *  
    159165         * @param start 
    160166         * @return next matching occurrence 
    161          * @throws IllegalTypeException when called with dom or dow. should call next(Calender, CronField) instead. 
    162          */ 
    163         public int next(int start) throws IllegalTypeException{ 
    164                 if(this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 
    165                         throw new IllegalTypeException("not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 
     167         * @throws IllegalTypeException 
     168         *             when called with dom or dow. should call next(Calender, 
     169         *             CronField) instead. 
     170         */ 
     171        public int next(int start) throws IllegalTypeException { 
     172                if (this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 
     173                        throw new IllegalTypeException( 
     174                                        "not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 
    166175                return this.bits.nextSetBit(start); 
    167176        } 
     
    169178        /** 
    170179         * returns the first matching occurrence. 
     180         *  
    171181         * @return first matching occurrence. 
    172          * @throws IllegalTypeException when called with dom or dow. should call first(Calender, CronField) instead. 
     182         * @throws IllegalTypeException 
     183         *             when called with dom or dow. should call first(Calender, 
     184         *             CronField) instead. 
    173185         */ 
    174186        public int first() throws IllegalTypeException { 
    175                 if(this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 
    176                         throw new IllegalTypeException("not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 
    177                 return this.next(0);  
    178         } 
    179  
    180         /** 
    181          * returns next matching occurrence after given start value.(including start value itself)  
     187                if (this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 
     188                        throw new IllegalTypeException( 
     189                                        "not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 
     190                 
     191                return this.next(0); 
     192        } 
     193 
     194        /** 
     195         * returns next matching occurrence after given start value.(including start 
     196         * value itself) 
     197         *  
    182198         * @param base 
    183          * @param dow day of week 
     199         * @param dow 
     200         *            day of week 
    184201         * @return 
    185          * @throws IllegalTypeException when called with a cronField except for dom 
     202         * @throws IllegalTypeException 
     203         *             when called with a cronField except for dom 
    186204         */ 
    187205        public int next(Calendar base, CronField dow) throws IllegalTypeException { 
    188                 if(!this.type.equals(CronField.Type.Day_of_Month)) 
     206                if (!this.type.equals(CronField.Type.Day_of_Month)) 
    189207                        throw new IllegalTypeException("only for day_of_month. use next(Calendar, CronField) instead."); 
    190                 return dow2month(base, dow).nextSetBit(base.get(Calendar.DAY_OF_MONTH) -1); 
    191         } 
     208                 
     209                return dow2month(base, dow).nextSetBit(base.get(Calendar.DAY_OF_MONTH) - 1); 
     210        } 
     211 
    192212        /** 
    193213         * returns the first matching occurrence. 
     214         *  
    194215         * @return first matching occurrence. 
    195          * @throws IllegalTypeException when called with a cronField except for dom 
    196          */ 
    197         public int first(Calendar base, CronField dow) throws IllegalTypeException{ 
    198                 if(!this.type.equals(CronField.Type.Day_of_Month)) 
     216         * @throws IllegalTypeException 
     217         *             when called with a cronField except for dom 
     218         */ 
     219        public int first(Calendar base, CronField dow) throws IllegalTypeException { 
     220                if (!this.type.equals(CronField.Type.Day_of_Month)) 
    199221                        throw new IllegalTypeException("only for day_of_month. use next(Calendar, CronField) instead."); 
     222                 
    200223                return dow2month(base, dow).nextSetBit(0); 
    201224        } 
    202          
    203         //for merging day_of_month and day_of_week.  
    204         //generates new bitmap. 
    205         private BitSet dow2month(Calendar base, CronField dow){ 
     225 
     226        // for merging day_of_month and day_of_week. 
     227        // generates new bitmap. 
     228        private BitSet dow2month(Calendar base, CronField dow) { 
    206229                Calendar clone = (Calendar) base.clone(); 
    207230                clone.set(Calendar.DAY_OF_MONTH, 1); 
    208                 int weekDayOf_1 = clone.get(Calendar.DAY_OF_WEEK) - 1; //1 for offset 
    209                 //merge dow and dom bitmaps. 
     231                int weekDayOf_1 = clone.get(Calendar.DAY_OF_WEEK) - 1; // 1 for offset 
     232                 
     233                // merge dow and dom bitmaps. 
    210234                BitSet dow2month = mergeBits(weekDayOf_1, this.bits, dow.bits); 
    211                 //turn off for surplus days of month. (e.g. turn off 30 and 31 from Feb.) 
     235                // turn off for surplus days of month. (e.g. turn off 30 and 31 from 
     236                // Feb.) 
     237                 
    212238                clone.add(Calendar.MONTH, 1); 
    213239                clone.add(Calendar.DAY_OF_MONTH, -1); 
    214240                int lastDayOfMonth = clone.get(Calendar.DAY_OF_MONTH); 
    215                 for(int i = lastDayOfMonth; i<this.type.bitLength; i++) 
     241                 
     242                for (int i = lastDayOfMonth; i < this.type.bitLength; i++) 
    216243                        dow2month.clear(i); 
     244                 
    217245                return dow2month; 
    218246        } 
    219         //generate 31 length bitmap by duplicating dow bitmap. 
    220         private static BitSet mergeBits(int weekDayOf_1, BitSet dom, BitSet dow){ 
     247 
     248        // generate 31 length bitmap by duplicating dow bitmap. 
     249        private static BitSet mergeBits(int weekDayOf_1, BitSet dom, BitSet dow) { 
    221250                BitSet dow2month = new BitSet(); 
    222                 for(int i=0; i<CronField.Type.Day_of_Month.getBitLength(); i++){ 
    223                         int weekDayOf_i = (i + weekDayOf_1)%7; 
     251                for (int i = 0; i < CronField.Type.Day_of_Month.getBitLength(); i++) { 
     252                        int weekDayOf_i = (i + weekDayOf_1) % 7; 
    224253                        dow2month.set(i, dow.get(weekDayOf_i)); 
    225254                } 
    226                 dow2month.or(dom); //dow bits and dom bits are merged by OR operation. 
     255                 
     256                dow2month.or(dom); // dow bits and dom bits are merged by OR operation. 
    227257                return dow2month; 
    228258        } 
    229259 
    230260        @Override 
    231         public String toString(){ 
     261        public String toString() { 
    232262                return this.exp; 
    233263        } 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/CronServiceImpl.java

    r346 r352  
    66import java.util.List; 
    77import java.util.Map; 
     8import java.util.NoSuchElementException; 
    89import java.util.concurrent.ConcurrentHashMap; 
    910import java.util.concurrent.ConcurrentMap; 
     
    2425public class CronServiceImpl implements CronService { 
    2526        private static BundleContext bundleContext; 
     27        /** 
     28         * schedule id to Schedule mapping. 
     29         */ 
    2630        private ConcurrentMap<Integer, Schedule> map; 
    2731        private final CronConfig config; 
     32        private final Scheduler scheduler = new Scheduler(); 
    2833 
    2934        public CronServiceImpl(BundleContext context) throws ParseException { 
     
    3439 
    3540        /** 
    36          * register schedule. 
    37          * schedule is saved in db, and added to scheduler. 
     41         * register schedule. schedule is saved in db, and added to scheduler. 
    3842         */ 
    3943        @Override 
    40         public void registerSchedule(Schedule schedule){ 
     44        public void registerSchedule(Schedule schedule) { 
    4145                int id = config.addEntry(schedule); 
    4246                this.map.put(id, schedule); 
    43                 Scheduler.instance.insertToQueue(id, schedule); 
     47                scheduler.put(id, schedule); 
    4448        } 
    4549 
    4650        /** 
    47          * unregister schedule. 
    48          * schedule is removed from db, and from scheduler. 
     51         * unregister schedule. schedule is removed from db, and from scheduler. 
    4952         */ 
    5053        @Override 
    51         public void unregisterSchedule(int i){ 
     54        public void unregisterSchedule(int i) { 
     55                if(null==this.map.remove(i)) throw new NoSuchElementException(); 
    5256                config.removeEntry(i); 
    53                 this.map.remove(i); 
    54                 Scheduler.instance.deleteFromQueue(i); 
     57                scheduler.remove(i); 
    5558        } 
    5659 
     
    5861         * start scheduler 
    5962         */ 
    60         public void validate(){ 
    61                 Scheduler.instance.start(getMap()); 
     63        public void validate() { 
     64                scheduler.start(getMap()); 
    6265        } 
    6366 
     
    6669         */ 
    6770        public void invalidate() { 
    68                 Scheduler.instance.stop(); 
     71                scheduler.stop(); 
    6972        } 
    7073 
    7174        /** 
    7275         * load schedules from db. 
    73          * @throws ParseException when data in db is corrupted and unable to parse as schedule. 
     76         *  
     77         * @throws ParseException 
     78         *             when data in db is corrupted and unable to parse as schedule. 
    7479         */ 
    7580        private void refreshMap() throws ParseException { 
     
    9297        @Override 
    9398        public List<String> getJobList() { 
    94                 return Scheduler.instance.getJobList(); 
     99                return scheduler.getJobList(); 
    95100        } 
    96101 
     
    100105 
    101106        /** 
    102          * get reference of current active Runnable given its . 
     107         * get reference of current active Runnable given its instance name. 
     108         *  
    103109         * @param context 
    104          * @param instanceName instance name of the Runnable 
     110         * @param instanceName 
     111         *            instance name of the Runnable 
    105112         * @return 
    106          * @throws InvalidSyntaxException when given instance name is not a valid string.  
     113         * @throws InvalidSyntaxException 
     114         *             when given instance name is not a valid string. 
    107115         */ 
    108         private static Runnable getRef(BundleContext context, String instanceName) 
    109                         throws InvalidSyntaxException { 
    110                 ServiceReference[] refs; 
    111                 refs = context.getServiceReferences(Runnable.class.getName(), 
    112                                 "(instance.name=" + instanceName + ")"); 
     116        private static Runnable getRef(BundleContext context, String instanceName) throws InvalidSyntaxException { 
     117                ServiceReference[] refs = context.getServiceReferences(Runnable.class.getName(), "(instance.name=" + instanceName + ")"); 
    113118                if (refs == null || refs.length == 0) { 
    114119                        throw new NullPointerException(); 
    115120                } 
     121                 
    116122                Runnable task = ((Runnable) context.getService(refs[0])); 
    117123                return task; 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/IllegalTypeException.java

    r323 r352  
    33/** 
    44 * throws when given cron field type is not allowed for the method. 
     5 *  
    56 * @author periphery 
    67 *  
    78 */ 
    89public class IllegalTypeException extends Exception { 
     10        private static final long serialVersionUID = 1L; 
    911 
    1012        public IllegalTypeException(String string) { 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/Job.java

    r346 r352  
    11package org.krakenapps.cron.impl; 
    22 
    3 import java.util.Calendar; 
    43import java.util.Date; 
    5 import java.util.Map; 
    64 
    75import org.krakenapps.cron.Schedule; 
     
    1412 * @since 1.0.0 
    1513 */ 
    16 public class Job implements Comparable<Job> , Cloneable{ 
     14public class Job implements Comparable<Job>, Cloneable { 
    1715        public final int scheduleId; 
    1816        public final Schedule schedule; 
    1917        public Date date; 
    20          
    21         public Job(int schduleId, Schedule schedule){ 
     18 
     19        public Job(int schduleId, Schedule schedule) { 
    2220                this.scheduleId = schduleId; 
    2321                this.schedule = schedule; 
     
    2523        } 
    2624 
    27         public boolean timeToDo(){ 
    28                 return timeToDo(new Date()); 
     25        public boolean isTimeToDo() { 
     26                return isTimeToDo(new Date()); 
    2927        } 
    30          
    31         //return true for jobs whose time passed 
    32         public boolean timeToDo(Date now){ 
    33                 if(now.getTime()/1000 - date.getTime()/1000 < 0){ 
     28 
     29        /** 
     30         * return true for jobs whose time passed. 
     31         */ 
     32        public boolean isTimeToDo(Date now) { 
     33                if (now.getTime() / 1000 - date.getTime() / 1000 < 0) { 
    3434                        return false; 
    35                 }else{ 
     35                } else { 
    3636                        return true; 
    3737                } 
    3838        } 
    39          
    40         public int getScheduleId(){ 
     39 
     40        public int getScheduleId() { 
    4141                return this.scheduleId; 
    4242        } 
    43          
     43 
    4444        @Override 
    4545        public int compareTo(Job o) { 
    4646                return this.date.compareTo(o.date); 
    4747        } 
    48          
     48 
    4949        public void setNextOccurence(Date now) { 
    50                 this.date = NextOccurenceGenerator.getNextOccurence(schedule, now); 
     50                this.date = NextOccurenceCalculator.getNextOccurence(schedule, now); 
    5151        } 
    52          
     52 
    5353        public void setNextOccurence() { 
    54                 this.date = NextOccurenceGenerator.getNextOccurence(schedule, new Date()); 
     54                this.date = NextOccurenceCalculator.getNextOccurence(schedule, new Date()); 
    5555        } 
    56          
    57          
    58          
    59         public String toString(){ 
    60                 return String.format("[%3d] %15s / %8s", this.scheduleId, this.date, this.schedule.getTaskInstanceName()); 
     56 
     57        public String toString() { 
     58                return String.format("[%3d] %15s / %8s", this.scheduleId, this.date, this.schedule.getTaskName()); 
    6159        } 
    6260 
    6361        @Override 
    64         public Job clone(){ 
    65                 try{ 
     62        public Job clone() { 
     63                try { 
    6664                        return (Job) super.clone(); 
    67                 }catch (Exception e) { 
     65                } catch (Exception e) { 
    6866                        throw new AssertionError(); 
    6967                } 
     
    7169 
    7270        public void run() throws NullPointerException, InvalidSyntaxException { 
    73                 Runnable task = CronServiceImpl.getRef(this.schedule.getTaskInstanceName());     
    74                 if(task == null){ 
     71                Runnable task = CronServiceImpl.getRef(this.schedule.getTaskName()); 
     72                if (task == null) { 
    7573                        throw new NullPointerException("runnable not active"); 
    7674                } 
     75                 
    7776                task.run(); 
    7877        } 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/NextOccurenceCalculator.java

    r346 r352  
    66import org.krakenapps.cron.Schedule; 
    77 
    8 public abstract class NextOccurenceGenerator { 
     8public abstract class NextOccurenceCalculator { 
    99        private static final int MONTH_TYPE = 1; 
    1010        private static final int DAY_TYPE = 2; 
     
    4040        private static final int calendarTypes[] = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 
    4141                        Calendar.HOUR_OF_DAY, Calendar.MINUTE }; 
     42 
    4243        private static final int upperCalendarTypes[] = { 0, Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 
    4344                        Calendar.HOUR_OF_DAY }; 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/QueryStringGenerator.java

    r344 r352  
    55/** 
    66 * generates query string for hsql db. 
     7 *  
    78 * @author periphery 
    89 * 
     
    3940                                                day_of_week, task, sche.get(CronField.Type.Minute), sche.get(CronField.Type.Hour), sche.get(CronField.Type.Day_of_Month), 
    4041                                                sche.get(CronField.Type.Month), sche.get(CronField.Type.Day_of_Week), 
    41                                                 sche.getTaskInstanceName()); 
     42                                                sche.getTaskName()); 
    4243        } 
    4344 
  • kraken-cron/src/main/java/org/krakenapps/cron/impl/Scheduler.java

    r346 r352  
    2121        private final Thread loop = new Thread(new Loop()); 
    2222        private boolean running; 
    23         public static Scheduler instance = new Scheduler(); 
    24  
    25         private Scheduler() { 
    26         } 
    2723 
    2824        public void stop() { 
     
    5349         *            new schedule to add 
    5450         */ 
    55         public void insertToQueue(int id, Schedule sche) { 
     51        public void put(int id, Schedule sche) { 
    5652                Job job = new Job(id, sche); 
    5753                synchronized (queue) { 
     
    6662         *            id of the deleting schedule 
    6763         */ 
    68         public void deleteFromQueue(int id) { 
     64        public void remove(int id) { 
    6965                synchronized (queue) { 
    7066                        for (Object job : queue.toArray()) { 
     
    141137                public boolean itIsTime() { 
    142138                        try { 
    143                                 return queue.peek().timeToDo(); 
     139                                return queue.peek().isTimeToDo(); 
    144140                        } catch (Exception e) { // empty queue 
    145141                                return false; 
     
    161157                                job.run(); 
    162158                        } catch (NullPointerException e) { 
    163                                 logger.debug("Cron: unable to run " + job + ". runnable \'" + job.schedule.getTaskInstanceName() 
     159                                logger.debug("Cron: unable to run " + job + ". runnable \'" + job.schedule.getTaskName() 
    164160                                                + "\' is not active."); 
    165161                        } catch (InvalidSyntaxException e) { 
  • kraken-cron/src/main/java/org/krakenapps/cron/test/JobTest.java

    r323 r352  
    1414public class JobTest { 
    1515        @Test 
    16         public void testTimeToDo() { 
     16        public void testisTimeToDo() { 
    1717                try { 
    1818                        Schedule sche1 = new Schedule.Builder("job").build(); 
    1919                        Job job1 = new Job(21, sche1); 
    20                         assertEquals(job1.timeToDo(), true); 
     20                        assertEquals(job1.isTimeToDo(), true); 
    2121 
    2222                        Schedule sche2 = new Schedule.Builder("job").build("*/3 * * * *"); 
     
    3232                        date = cal.getTime(); 
    3333 
    34                         assertFalse(job2.timeToDo(date));// not yet 
     34                        assertFalse(job2.isTimeToDo(date));// not yet 
    3535 
    3636                        cal.set(Calendar.MINUTE, 1); 
    3737                        date = cal.getTime(); 
    38                         assertFalse(job2.timeToDo(date));// not yet 
     38                        assertFalse(job2.isTimeToDo(date));// not yet 
    3939 
    4040                        cal.set(Calendar.MINUTE, 2); 
    4141                        date = cal.getTime(); 
    42                         assertFalse(job2.timeToDo(date));// not yet 
     42                        assertFalse(job2.isTimeToDo(date));// not yet 
    4343 
    4444                        cal.set(Calendar.MINUTE, 3);// now 
    4545                        date = cal.getTime(); 
    46                         assertTrue(job2.timeToDo(date)); 
     46                        assertTrue(job2.isTimeToDo(date)); 
    4747 
    4848                        cal.set(Calendar.MINUTE, 4);// still 
    4949                        date = cal.getTime(); 
    50                         assertTrue(job2.timeToDo(date)); 
     50                        assertTrue(job2.isTimeToDo(date)); 
    5151 
    5252                        cal.set(Calendar.SECOND, 20);// time over 
    5353                        date = cal.getTime(); 
    54                         assertTrue(job2.timeToDo(date)); 
     54                        assertTrue(job2.isTimeToDo(date)); 
    5555 
    5656                        cal.set(Calendar.SECOND, 40);// time over 
    5757                        date = cal.getTime(); 
    58                         assertTrue(job2.timeToDo(date)); 
     58                        assertTrue(job2.isTimeToDo(date)); 
    5959 
    6060                } catch (InvalidSyntaxException e) { 
    61                         // TODO Auto-generated catch block 
    6261                        e.printStackTrace(); 
    6362                } catch (Exception e) { 
    64                         // TODO Auto-generated catch block 
    6563                        e.printStackTrace(); 
    6664                } 
  • kraken-cron/src/main/java/org/krakenapps/cron/test/NextOccurTest.java

    r346 r352  
    11package org.krakenapps.cron.test; 
    22 
     3import java.text.SimpleDateFormat; 
    34import java.util.Calendar; 
    45import java.util.Date; 
     
    78import org.junit.Test; 
    89import org.krakenapps.cron.Schedule; 
    9 import org.krakenapps.cron.impl.NextOccurenceGenerator; 
     10import org.krakenapps.cron.impl.NextOccurenceCalculator; 
    1011import org.osgi.framework.InvalidSyntaxException; 
    1112import static org.junit.Assert.*;  
     
    1314public class NextOccurTest { 
    1415 
     16        @SuppressWarnings("deprecation") 
    1517        @Test 
    1618        public void testNext1() throws InvalidSyntaxException, Exception { 
     19                 
    1720 
    18                 // Schedule sche1 = new 
    19                 // Schedule.Builder("test1").build("*/30 * 3,18 * 0"); 
    20                 // Schedule sche2 = new 
    21                 // Schedule.Builder("test2").build("20-40 * * 4-7 *"); 
    2221                Date date = new Date(Date.parse("Feb 27, 2009 8:14 PM")); 
    2322                System.out.println("============ test1 : " + date + "============="); 
     
    3635                Schedule sche12 = new Schedule.Builder("awef").build("* * 31 * 0"); 
    3736 
    38 //              System.out.println(sche1.getNextOccurence(date)); 
    39 //              System.out.println(sche2.getNextOccurence(date)); 
    40 //              System.out.println(sche3.getNextOccurence(date)); 
    41 //              System.out.println(sche4.getNextOccurence( date)); 
    42 //              System.out.println(sche5.getNextOccurence(date)); 
    43 //              System.out.println(sche6.getNextOccurence(date)); 
    44 //              System.out.println(sche7.getNextOccurence(date)); 
    45 //              System.out.println(sche8.getNextOccurence(date)); 
    46 //              System.out.println(sche9.getNextOccurence(date)); 
    47 //              System.out.println(sche10.getNextOccurence(date)); 
    48 //              System.out.println(sche11.getNextOccurence( date)); 
    49 //              System.out.println(sche12.getNextOccurence( date)); 
    50                  
    5137         
    52                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche1, date).toString(),"Fri Feb 27 20:14:00 KST 2009"); 
    53                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche2, date).toString(),"Fri Feb 27 21:00:00 KST 2009"); 
    54                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche3, date).toString(),"Sat Feb 28 00:00:00 KST 2009"); 
    55                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche4, date).toString(),"Sun Mar 01 00:00:00 KST 2009"); 
    56                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 
    57                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche6, date).toString(),"Fri Feb 27 20:30:00 KST 2009"); 
    58                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche7, date).toString(),"Fri Feb 27 20:17:00 KST 2009"); 
    59                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche8, date).toString(),"Fri Feb 27 21:03:00 KST 2009"); 
    60                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche9, date).toString(),"Sat Feb 28 00:00:00 KST 2009"); 
    61                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche10, date).toString(),"Thu Mar 05 00:00:00 KST 2009"); 
    62                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche11, date).toString(),"Mon Mar 02 00:00:00 KST 2009"); 
    63                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche12, date).toString(),"Sun Mar 01 00:00:00 KST 2009"); 
     38                assertEquals(NextOccurenceCalculator.getNextOccurence(sche1, date).toString(),"Fri Feb 27 20:14:00 KST 2009"); 
     39                assertEquals(NextOccurenceCalculator.getNextOccurence(sche2, date).toString(),"Fri Feb 27 21:00:00 KST 2009"); 
     40                assertEquals(NextOccurenceCalculator.getNextOccurence(sche3, date).toString(),"Sat Feb 28 00:00:00 KST 2009"); 
     41                assertEquals(NextOccurenceCalculator.getNextOccurence(sche4, date).toString(),"Sun Mar 01 00:00:00 KST 2009"); 
     42                assertEquals(NextOccurenceCalculator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 
     43                assertEquals(NextOccurenceCalculator.getNextOccurence(sche6, date).toString(),"Fri Feb 27 20:30:00 KST 2009"); 
     44                assertEquals(NextOccurenceCalculator.getNextOccurence(sche7, date).toString(),"Fri Feb 27 20:17:00 KST 2009"); 
     45                assertEquals(NextOccurenceCalculator.getNextOccurence(sche8, date).toString(),"Fri Feb 27 21:03:00 KST 2009"); 
     46                assertEquals(NextOccurenceCalculator.getNextOccurence(sche9, date).toString(),"Sat Feb 28 00:00:00 KST 2009"); 
     47                assertEquals(NextOccurenceCalculator.getNextOccurence(sche10, date).toString(),"Thu Mar 05 00:00:00 KST 2009"); 
     48                assertEquals(NextOccurenceCalculator.getNextOccurence(sche11, date).toString(),"Mon Mar 02 00:00:00 KST 2009"); 
     49                assertEquals(NextOccurenceCalculator.getNextOccurence(sche12, date).toString(),"Sun Mar 01 00:00:00 KST 2009"); 
    6450        } 
    6551 
     52        @SuppressWarnings("deprecation") 
    6653        @Test 
    6754        public void testNext2() throws InvalidSyntaxException, Exception { 
    6855 
    69                 // Schedule sche1 = new 
    70                 // Schedule.Builder("test1").build("*/30 * 3,18 * 0"); 
    71                 // Schedule sche2 = new 
    72                 // Schedule.Builder("test2").build("20-40 * * 4-7 *"); 
    7356                Date date = new Date(Date.parse("Aug 6, 2009 1:11 AM")); 
    7457                System.out.println("============ test2 : " + date + "============="); 
     
    8669                Schedule sche11 = new Schedule.Builder("awef").build("0 0 5,28 3 1"); 
    8770 
    88 //              System.out.println(sche1.getNextOccurence(date)); 
    89 //              System.out.println(sche2.getNextOccurence(date)); 
    90 //              System.out.println(sche3.getNextOccurence(date)); 
    91 //              System.out.println(sche4.getNextOccurence(date)); 
    92 //              System.out.println(sche5.getNextOccurence(date)); 
    93 //              System.out.println(sche6.getNextOccurence(date)); 
    94 //              System.out.println(sche7.getNextOccurence(date)); 
    95 //              System.out.println(sche8.getNextOccurence(date)); 
    96 //              System.out.println(sche9.getNextOccurence(date)); 
    97 //              System.out.println(sche10.getNextOccurence( date)); 
    98 //              System.out.println(sche11.getNextOccurence( date)); 
    99 //               
    100                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche1, date).toString(),"Thu Aug 06 01:11:00 KST 2009"); 
    101                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche2, date).toString(),"Thu Aug 06 02:00:00 KST 2009"); 
    102                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche3, date).toString(),"Fri Aug 07 00:00:00 KST 2009"); 
    103                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche4, date).toString(),"Sun Aug 09 00:00:00 KST 2009"); 
    104                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 
    105                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche6, date).toString(),"Thu Aug 06 01:30:00 KST 2009"); 
    106                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche7, date).toString(),"Thu Aug 06 01:17:00 KST 2009"); 
    107                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche8, date).toString(),"Thu Aug 06 03:03:00 KST 2009"); 
    108                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche9, date).toString(),"Fri Aug 28 00:00:00 KST 2009"); 
    109                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche10, date).toString(),"Fri Mar 05 00:00:00 KST 2010"); 
    110                 assertEquals(NextOccurenceGenerator.getNextOccurence(sche11, date).toString(),"Mon Mar 01 00:00:00 KST 2010"); 
     71                assertEquals(NextOccurenceCalculator.getNextOccurence(sche1, date).toString(),"Thu Aug 06 01:11:00 KST 2009"); 
     72                assertEquals(NextOccurenceCalculator.getNextOccurence(sche2, date).toString(),"Thu Aug 06 02:00:00 KST 2009"); 
     73                assertEquals(NextOccurenceCalculator.getNextOccurence(sche3, date).toString(),"Fri Aug 07 00:00:00 KST 2009"); 
     74                assertEquals(NextOccurenceCalculator.getNextOccurence(sche4, date).toString(),"Sun Aug 09 00:00:00 KST 2009"); 
     75                assertEquals(NextOccurenceCalculator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 
     76                assertEquals(NextOccurenceCalculator.getNextOccurence(sche6, date).toString(),"Thu Aug 06 01:30:00 KST 2009"); 
     77                assertEquals(NextOccurenceCalculator.getNextOccurence(sche7, date).toString(),"Thu Aug 06 01:17:00 KST 2009"); 
     78                assertEquals(NextOccurenceCalculator.getNextOccurence(sche8, date).toString(),"Thu Aug 06 03:03:00 KST 2009"); 
     79                assertEquals(NextOccurenceCalculator.getNextOccurence(sche9, date).toString(),"Fri Aug 28 00:00:00 KST 2009"); 
     80                assertEquals(NextOccurenceCalculator.getNextOccurence(sche10, date).toString(),"Fri Mar 05 00:00:00 KST 2010"); 
     81                assertEquals(NextOccurenceCalculator.getNextOccurence(sche11, date).toString(),"Mon Mar 01 00:00:00 KST 2010"); 
    11182        } 
    11283         
     
    11889                System.out.println("============ daily : " + date1 + "============="); 
    11990                for(int i = 0 ; i < 20; i++){ 
    120                         date1 = NextOccurenceGenerator.getNextOccurence(sche, date1); 
     91                        date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 
    12192                        System.out.println(date1); 
    12293                        date1 = new Date(date1.getTime() + 60 * 1000); 
     
    131102                System.out.println("============ weekly : " + date1 + "============="); 
    132103                for(int i = 0 ; i < 20; i++){ 
    133                         date1 = NextOccurenceGenerator.getNextOccurence(sche, date1); 
     104                        date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 
    134105                        System.out.println(date1); 
    135106                        date1 = new Date(date1.getTime() + 60 * 1000); 
     
    144115                System.out.println("============ mondayAnd10th : " + date1 + "============="); 
    145116                for(int i = 0 ; i < 20; i++){ 
    146                         date1 = NextOccurenceGenerator.getNextOccurence(sche, date1); 
     117                        date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 
    147118                        System.out.println(date1); 
    148119                        date1 = new Date(date1.getTime() + 60 * 1000); 
     
    150121        } 
    151122         
     123        @SuppressWarnings("deprecation") 
    152124        @Test 
    153125        public void test31th() throws InvalidSyntaxException, Exception{ 
     
    157129                System.out.println("============ 31th : " + date1 + "============="); 
    158130                for(int i = 0 ; i < 20; i++){ 
    159                         date1 = NextOccurenceGenerator.getNextOccurence(sche, date1); 
     131                        date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 
    160132                        System.out.println(date1); 
    161133                        Calendar cal = Calendar.getInstance(); 
  • kraken-cron/src/main/java/org/krakenapps/cron/test/ScheduleBuildTest.java

    r323 r352  
    1414        public void testBuildManual() throws Exception { 
    1515                try { 
    16                         Schedule test = new Schedule.Builder("daily").set( 
    17                                         CronField.Type.Day_of_Week, "0").set( 
    18                                         CronField.Type.Day_of_Month, "*/10").set( 
    19                                         CronField.Type.Hour, "4-10").set(CronField.Type.Minute, 
     16                        Schedule test = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "0").set( 
     17                                        CronField.Type.Day_of_Month, "*/10").set(CronField.Type.Hour, "4-10").set(CronField.Type.Minute, 
    2018                                        "0,3,59").set(CronField.Type.Month, "12").build(); 
    21                         Schedule test2 = new Schedule.Builder("daily").set( 
    22                                         CronField.Type.Day_of_Week, "3").set( 
    23                                         CronField.Type.Day_of_Month, "1").set(CronField.Type.Hour, 
    24                                         "0-23").set(CronField.Type.Minute, "2,3,3").build(); 
     19                        Schedule test2 = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "3").set( 
     20                                        CronField.Type.Day_of_Month, "1").set(CronField.Type.Hour, "0-23").set(CronField.Type.Minute, 
     21                                        "2,3,3").build(); 
    2522 
    2623                        System.out.println("test1" + test); 
     
    2825 
    2926                        assertEquals(test.fieldMembers(CronField.Type.Minute), "{0, 3, 59}"); 
    30                         assertEquals(test.fieldMembers(CronField.Type.Day_of_Month), 
    31                                         "{0, 10, 20, 30}"); // interval 
    32                         assertEquals(test.fieldMembers(CronField.Type.Hour), 
    33                                         "{4, 5, 6, 7, 8, 9, 10}"); // range 
     27                        assertEquals(test.fieldMembers(CronField.Type.Day_of_Month), "{0, 10, 20, 30}"); // interval 
     28                        assertEquals(test.fieldMembers(CronField.Type.Hour), "{4, 5, 6, 7, 8, 9, 10}"); // range 
    3429                        assertEquals(test.fieldMembers(CronField.Type.Month), "{11}"); 
    3530 
    3631                        assertEquals(test2.fieldMembers(CronField.Type.Minute), "{2, 3}"); // specify 
    37                         assertEquals(test2.fieldMembers(CronField.Type.Month), 
    38                                         "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"); // default 
     32                        assertEquals(test2.fieldMembers(CronField.Type.Month), "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"); // default 
    3933 
    40                         assertEquals(test, new Schedule.Builder("daily") 
    41                                         .build("0,3,59 4-10 */10 12 0")); 
     34                        assertEquals(test, new Schedule.Builder("daily").build("0,3,59 4-10 */10 12 0")); 
    4235                } catch (Exception e) { 
    4336                        fail(); 
     
    4538                } 
    4639        } 
    47          
     40 
    4841        @Test 
    4942        public void testBuildString() throws InvalidSyntaxException, Exception { 
     
    5245                        System.out.println("test3" + test3); 
    5346 
    54                         assertEquals(test3.fieldMembers(CronField.Type.Day_of_Week), 
    55                                         "{3, 4, 5, 6}"); 
     47                        assertEquals(test3.fieldMembers(CronField.Type.Day_of_Week), "{3, 4, 5, 6}"); 
    5648                        assertEquals(test3.fieldMembers(CronField.Type.Day_of_Month), "{0}"); 
    5749                        assertEquals(test3.fieldMembers(CronField.Type.Month), "{0}"); 
    5850                } catch (Exception e) { 
    5951                        fail(); 
    60                         // TODO: handle exception 
    6152                } 
    6253 
     
    7768                        System.out.println("test7" + test7); 
    7869 
    79                         assertEquals(test8, new Schedule.Builder("daily") 
    80                                         .build("* * * * * ")); 
    81                         assertEquals(test4, new Schedule.Builder("daily") 
    82                                         .build("0 0 1 1 *")); 
    83                         assertEquals(test5, new Schedule.Builder("daily") 
    84                                         .build("0 0 1 * *")); 
    85                         assertEquals(test6, new Schedule.Builder("daily") 
    86                                         .build("0 0 * * *")); 
    87                         assertEquals(test7, new Schedule.Builder("daily") 
    88                                         .build("0 0 * * 0")); 
     70                        assertEquals(test8, new Schedule.Builder("daily").build("* * * * * ")); 
     71                        assertEquals(test4, new Schedule.Builder("daily").build("0 0 1 1 *")); 
     72                        assertEquals(test5, new Schedule.Builder("daily").build("0 0 1 * *")); 
     73                        assertEquals(test6, new Schedule.Builder("daily").build("0 0 * * *")); 
     74                        assertEquals(test7, new Schedule.Builder("daily").build("0 0 * * 0")); 
    8975                } catch (Exception e) { 
    9076                        fail(); 
     
    10591                } catch (Exception e) { 
    10692                        fail(); 
    107                         // TODO: handle exception 
    10893                } 
    10994        } 
     
    11398                try { 
    11499                        Schedule test8 = new Schedule.Builder("daily").build(); 
    115                         Schedule test9 = new Schedule.Builder("daily").set( 
    116                                         CronField.Type.Day_of_Week, "*").build(); 
    117                         Schedule test10 = new Schedule.Builder("daily").set( 
    118                                         CronField.Type.Day_of_Week, "3").build(); 
     100                        Schedule test9 = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "*").build(); 
     101                        Schedule test10 = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "3").build(); 
    119102                        System.out.println("test8" + test8); 
    120103                        System.out.println("test9" + test9); 
     
    136119                        fail(); 
    137120                } catch (ParseException e) { 
    138                         // TODO Auto-generated catch block 
    139                 }  
     121                } 
    140122                try { 
    141123                        new Schedule.Builder("daily").set(CronField.Type.Day_of_Month, "0"); 
    142124                        fail(); 
    143125                } catch (ParseException e) { 
    144                         // TODO Auto-generated catch block 
    145                 }  
     126                } 
    146127                try { 
    147128                        new Schedule.Builder("daily").set(CronField.Type.Hour, "24"); 
    148129                        fail(); 
    149130                } catch (ParseException e) { 
    150                         // TODO Auto-generated catch block 
    151                 }  
     131                } 
    152132                try { 
    153133                        new Schedule.Builder("daily").set(CronField.Type.Hour, "-4"); 
    154134                        fail(); 
    155135                } catch (ParseException e) { 
    156                         // TODO Auto-generated catch block 
    157                 }  
     136                } 
    158137                try { 
    159138                        new Schedule.Builder("daily").build("0 0 0 0"); 
    160139                        fail(); 
    161140                } catch (ParseException e) { 
    162                         // TODO Auto-generated catch block 
    163                 }catch (Exception e) { 
    164                         // TODO Auto-generated catch block 
     141                } catch (Exception e) { 
    165142                } 
    166143        }