1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal

File AbstractMailStatusResult.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
11
6
1
85
49
9
0.82
1.83
6
1.5

Classes

Class Line # Actions
AbstractMailStatusResult 32 11 0% 9 2
0.894736889.5%
 

Contributing tests

This file is covered by 16 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.mail.internal;
21   
22    import org.apache.commons.lang3.exception.ExceptionUtils;
23    import org.slf4j.Logger;
24    import org.slf4j.LoggerFactory;
25   
26    /**
27    * Helper for implementations of {@link UpdateableMailStatusResult}.
28    *
29    * @version $Id: 2a15a1fac79bea1ed753895fc5c9eb8833dd2360 $
30    * @since 7.1M2
31    */
 
32    public abstract class AbstractMailStatusResult implements UpdateableMailStatusResult
33    {
34    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractMailStatusResult.class);
35   
36    private long totalSize = -1;
37   
38    private long currentSize;
39   
 
40  45 toggle @Override
41    public void setTotalSize(long totalSize)
42    {
43  45 this.totalSize = totalSize;
44    }
45   
 
46  32 toggle @Override
47    public void incrementCurrentSize()
48    {
49  32 this.currentSize++;
50    }
51   
 
52  44 toggle @Override
53    public long getTotalMailCount()
54    {
55  44 return this.totalSize;
56    }
57   
 
58  45 toggle @Override
59    public long getProcessedMailCount()
60    {
61  45 return this.currentSize;
62    }
63   
 
64  13 toggle @Override
65    public void waitTillProcessed(long timeout)
66    {
67  13 long startTime = System.currentTimeMillis();
68  38 while (!isProcessed() && System.currentTimeMillis() - startTime < timeout) {
69  25 try {
70  25 Thread.sleep(100L);
71    } catch (InterruptedException e) {
72    // Ignore but consider that the mail was sent
73  0 LOGGER.warn("Interrupted while waiting for mails to be sent. Reason [{}]",
74    ExceptionUtils.getRootCauseMessage(e));
75  0 break;
76    }
77    }
78    }
79   
 
80  44 toggle @Override
81    public boolean isProcessed()
82    {
83  44 return getTotalMailCount() == getProcessedMailCount();
84    }
85    }