Subversion Repositories bacoAlunos

Rev

Rev 1426 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1426 Rev 1427
Line 31... Line 31...
31
    }
31
    }
32
 
32
 
33
 
33
 
34
 
34
 
35
 
35
 
-
 
36
    //TODO WHEN BACK TO BCC REMOVE this to 20 and remove Thread
-
 
37
    private static final int NUMBER_EMAILS_TO = 1;
-
 
38
    private static final int pauseTime = 1000;
-
 
39
 
-
 
40
 
36
    public void runJob()
41
    public void runJob()
37
    {
42
    {
-
 
43
        final Email cloned = email.cloneEmailForJob();
-
 
44
        logger.info("Opening new Thread to send emails");
-
 
45
        new 1.5.0/docs/api/java/lang/Thread.html">Thread(
-
 
46
                new 1.5.0/docs/api/java/lang/Runnable.html">Runnable() {
-
 
47
                    @1.5.0/docs/api/java/lang/Override.html">Override
-
 
48
                    public void run() {
38
        if(Globals.TEST_ENVIRONEMENT && !email.isSystemAssumingTestEmail())
49
                        if(Globals.TEST_ENVIRONEMENT && !cloned.isSystemAssumingTestEmail())
39
        {
50
                        {
40
            1.5.0/docs/api/java/lang/String.html">String warn = "System in TEST Environement - will not send EMAIL";
51
                            1.5.0/docs/api/java/lang/String.html">String warn = "System in TEST Environement - will not send EMAIL";
41
            logger.warn(warn);
52
                            logger.warn(warn);
42
            return;
53
                            return;
43
        }
54
                        }
44
        try
55
                        try
45
        {
56
                        {
46
            List<String> recipientsOriginal = new ArrayList<String>();
57
                            List<String> recipientsOriginal = new ArrayList<String>();
47
            List<String> recipients = new ArrayList<String>();
58
                            List<String> recipients = new ArrayList<String>();
48
            recipients.addAll(email.getRecipients());
59
                            recipients.addAll(cloned.getRecipients());
49
            recipientsOriginal.addAll(email.getRecipients());
60
                            recipientsOriginal.addAll(cloned.getRecipients());
50
            while(recipients.size() > 0)
61
                            while(recipients.size() > 0)
51
            {
62
                            {
52
                List<String> recipientsToSend = new ArrayList<String>();
63
                                List<String> recipientsToSend = new ArrayList<String>();
53
 
64
 
54
                int contador = 0;
65
                                int contador = 0;
55
                Iterator<String> iter = recipients.iterator();
66
                                Iterator<String> iter = recipients.iterator();
56
                while(iter.hasNext() && contador < 20)
67
                                while(iter.hasNext() && contador < NUMBER_EMAILS_TO)
57
                {
68
                                {
58
                    recipientsToSend.add(iter.next());
69
                                    recipientsToSend.add(iter.next());
59
                    iter.remove();
70
                                    iter.remove();
60
                    contador++;
71
                                    contador++;
61
                }
72
                                }
62
                email.setRecipients(recipientsToSend);
73
                                cloned.setRecipients(recipientsToSend);
63
                new SendEmailService().sendEmail(email);
74
                                new SendEmailService().sendEmail(cloned);
-
 
75
                                try {
-
 
76
                                    1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(pauseTime);
-
 
77
                                } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) {
-
 
78
                                    logger.error(e,e);
-
 
79
                                }
-
 
80
                            }
64
                try {
81
                            try {
65
                    1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(1000);
82
                                1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(1000);
66
                } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) {
83
                            } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) {
67
                    logger.error(e,e);
84
                                logger.error(e,e);
-
 
85
                            }
-
 
86
                            cloned.setRecipients(recipientsOriginal);
-
 
87
                        }
-
 
88
                        catch (ServiceException e)
-
 
89
                        {
-
 
90
                            logger.error("Sending EMAIL:" + e.toString(),e);
-
 
91
                        }
-
 
92
                    }
68
                }
93
                }
69
            }
-
 
70
            try {
94
        ).start();
71
                1.5.0/docs/api/java/lang/Thread.html">Thread.sleep(1000);
-
 
72
            } catch (1.5.0/docs/api/java/lang/InterruptedException.html">InterruptedException e) {
-
 
73
                logger.error(e,e);
-
 
74
            }
-
 
75
            email.setRecipients(recipientsOriginal);
-
 
76
        }
-
 
77
        catch (ServiceException e)
-
 
78
        {
-
 
79
            logger.error("Sending EMAIL:" + e.toString(),e);
-
 
80
        }
-
 
81
    }
95
    }
-
 
96
 
-
 
97
 
82
}
98
}