1 | |
package org.kuali.maven.wagon; |
2 | |
|
3 | |
import static org.apache.commons.lang.StringUtils.leftPad; |
4 | |
|
5 | |
import java.util.List; |
6 | |
|
7 | |
import org.slf4j.Logger; |
8 | |
import org.slf4j.LoggerFactory; |
9 | |
|
10 | |
import com.amazonaws.services.s3.AmazonS3Client; |
11 | |
import com.amazonaws.services.s3.model.PutObjectRequest; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
public class PutThread implements Runnable { |
17 | 0 | private final Logger logger = LoggerFactory.getLogger(PutThread.class); |
18 | |
|
19 | |
PutThreadContext context; |
20 | |
|
21 | |
public PutThread() { |
22 | 0 | this(null); |
23 | 0 | } |
24 | |
|
25 | |
public PutThread(PutThreadContext context) { |
26 | 0 | super(); |
27 | 0 | this.context = context; |
28 | 0 | } |
29 | |
|
30 | |
public void run() { |
31 | 0 | logger.debug("[Thread-" + context.getId() + "] Starting"); |
32 | 0 | int offset = context.getOffset(); |
33 | 0 | int length = context.getLength(); |
34 | 0 | List<PutFileContext> list = context.getContexts(); |
35 | 0 | RequestFactory factory = context.getFactory(); |
36 | 0 | AmazonS3Client client = context.getClient(); |
37 | 0 | for (int i = offset; i < offset + length; i++) { |
38 | 0 | if (context.getHandler().isStopThreads()) { |
39 | 0 | break; |
40 | |
} |
41 | 0 | PutFileContext pc = list.get(i); |
42 | 0 | pc.setProgress(null); |
43 | 0 | PutObjectRequest request = factory.getPutObjectRequest(pc); |
44 | |
|
45 | 0 | logger.debug(leftPad(context.getId() + "", 2, " ") + " - " + pc.getSource().getAbsolutePath()); |
46 | 0 | client.putObject(request); |
47 | 0 | context.getTracker().increment(); |
48 | |
|
49 | |
} |
50 | 0 | logger.debug("Thread " + context.getId() + " stopping"); |
51 | 0 | } |
52 | |
|
53 | |
public PutThreadContext getContext() { |
54 | 0 | return context; |
55 | |
} |
56 | |
|
57 | |
public void setContext(PutThreadContext context) { |
58 | 0 | this.context = context; |
59 | 0 | } |
60 | |
} |