1 | |
package org.kuali.maven.mojo.s3; |
2 | |
|
3 | |
import static org.apache.commons.lang.StringUtils.leftPad; |
4 | |
|
5 | |
import java.io.IOException; |
6 | |
import java.util.List; |
7 | |
|
8 | |
import org.slf4j.Logger; |
9 | |
import org.slf4j.LoggerFactory; |
10 | |
|
11 | |
import com.amazonaws.AmazonServiceException; |
12 | |
|
13 | |
public class UpdateDirectoryThread implements Runnable { |
14 | 0 | final Logger logger = LoggerFactory.getLogger(UpdateDirectoryThread.class); |
15 | |
|
16 | |
UpdateDirectoryThreadContext context; |
17 | |
|
18 | |
public UpdateDirectoryThread() { |
19 | 0 | this(null); |
20 | 0 | } |
21 | |
|
22 | |
public UpdateDirectoryThread(UpdateDirectoryThreadContext context) { |
23 | 0 | super(); |
24 | 0 | this.context = context; |
25 | 0 | } |
26 | |
|
27 | |
@Override |
28 | |
public void run() { |
29 | 0 | logger.debug("[Thread-" + context.getId() + "] Starting"); |
30 | 0 | int offset = context.getOffset(); |
31 | 0 | int length = context.getLength(); |
32 | 0 | List<UpdateDirectoryContext> list = context.getContexts(); |
33 | 0 | BucketUpdater updater = context.getUpdater(); |
34 | 0 | for (int i = offset; i < offset + length; i++) { |
35 | 0 | if (context.getHandler().isStopThreads()) { |
36 | 0 | break; |
37 | |
} |
38 | 0 | UpdateDirectoryContext udc = list.get(i); |
39 | |
try { |
40 | 0 | updater.updateDirectory(udc); |
41 | 0 | } catch (IOException e) { |
42 | 0 | throw new AmazonServiceException("Unexpected error", e); |
43 | 0 | } |
44 | 0 | logger.debug(leftPad(context.getId() + "", 2, " ") + " - " + udc.getCopyToKey()); |
45 | 0 | context.getTracker().increment(); |
46 | |
} |
47 | 0 | logger.debug("Thread " + context.getId() + " stopping"); |
48 | 0 | } |
49 | |
|
50 | |
public UpdateDirectoryThreadContext getContext() { |
51 | 0 | return context; |
52 | |
} |
53 | |
|
54 | |
public void setContext(UpdateDirectoryThreadContext context) { |
55 | 0 | this.context = context; |
56 | 0 | } |
57 | |
|
58 | |
} |