This repository was archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathAbstractLogProvider.java
74 lines (66 loc) · 2.5 KB
/
AbstractLogProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Amazon Software License (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/asl/
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.dynamodb.bootstrap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.amazonaws.dynamodb.bootstrap.constants.BootstrapConstants;
/**
* Abstract class to send inputs from a source to a consumer.
*/
public abstract class AbstractLogProvider {
/**
* Logger for the DynamoDBBootstrapWorker.
*/
private static final Logger LOGGER = LogManager
.getLogger(AbstractLogProvider.class);
protected ExecutorService threadPool;
/**
* Begins to read log results and transfer them to the consumer who will
* write the results.
*/
public abstract void pipe(final AbstractLogConsumer consumer)
throws ExecutionException, InterruptedException;
/**
* Shuts the thread pool down.
*
* @param <awaitTermination>
* If true, this method waits for the threads in the pool to
* finish. If false, this thread pool shuts down without
* finishing their current tasks.
*/
public void shutdown(boolean awaitTermination) {
if (awaitTermination) {
boolean interrupted = false;
threadPool.shutdown();
try {
while (!threadPool.awaitTermination(BootstrapConstants.WAITING_PERIOD_FOR_THREAD_TERMINATION_SECONDS, TimeUnit.SECONDS)) {
LOGGER.info("Waiting for the threadpool to terminate...");
}
} catch (InterruptedException e) {
interrupted = true;
LOGGER.warn("Threadpool was interrupted when trying to shutdown: "
+ e.getMessage());
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
} else {
threadPool.shutdownNow();
}
}
}