summaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-dispatcher-common
diff options
context:
space:
mode:
authorGary Wu <gary.i.wu@huawei.com>2017-05-08 12:59:44 -0700
committerPatrick Brady <pb071s@att.com>2017-05-16 18:13:41 +0000
commit753cb638fcb58f355f2c979e9e0a43cba2832984 (patch)
tree55526dce196663d6c5c4265e504882e3deec2cc2 /appc-dispatcher/appc-dispatcher-common
parentf16391cacb2e91063bbe9ad66cb2310855c93695 (diff)
Migrate to Java 8 Time API
Migrate the uses of the old Date class in CommonHeader, RuntimeContext, QueueMessage, and TransactionRecord to Java 8 Time API. Change-Id: I3b0c18b2e63cdab06e37587d2010cb7f626a0396 Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common')
-rw-r--r--appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java8
-rw-r--r--appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java7
-rw-r--r--appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java20
-rw-r--r--appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java10
-rw-r--r--appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java15
-rw-r--r--appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java6
-rw-r--r--appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java20
7 files changed, 42 insertions, 44 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java
index 0819a58d5..30459465f 100644
--- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java
+++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/CommonHeader.java
@@ -21,13 +21,13 @@
package org.openecomp.appc.domainmodel.lcm;
-import java.util.Date;
+import java.time.Instant;
public class CommonHeader {
private Flags flags;
- private Date timestamp;
+ private Instant timestamp;
private String apiVer;
private String originatorId;
private String requestId;
@@ -41,11 +41,11 @@ public class CommonHeader {
this.flags = flags;
}
- public Date getTimeStamp() {
+ public Instant getTimeStamp() {
return timestamp;
}
- public void setTimestamp(Date timestamp) {
+ public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java
index fd2bcffbf..e47f5469a 100644
--- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java
+++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/main/java/org/openecomp/appc/domainmodel/lcm/RuntimeContext.java
@@ -21,6 +21,7 @@
package org.openecomp.appc.domainmodel.lcm;
+import java.time.Instant;
import java.util.Date;
@@ -31,7 +32,7 @@ public class RuntimeContext {
private VNFContext vnfContext;
//TODO move fields timeStart abd isLockAcquired to a better place
- private Date timeStart;
+ private Instant timeStart;
private boolean isLockAcquired;
private String rpcName;
@@ -43,7 +44,7 @@ public class RuntimeContext {
this.rpcName = rpcName;
}
- public Date getTimeStart() {
+ public Instant getTimeStart() {
return timeStart;
}
@@ -55,7 +56,7 @@ public class RuntimeContext {
this.isLockAcquired = isLockAcquired;
}
- public void setTimeStart(Date timeStart) {
+ public void setTimeStart(Instant timeStart) {
this.timeStart = timeStart;
}
diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java
index 2ac383696..672f4aa9b 100644
--- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java
+++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/ExecutionQueueServiceImpl.java
@@ -21,6 +21,7 @@
package org.openecomp.appc.executionqueue.impl;
+import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@@ -29,6 +30,7 @@ import org.openecomp.appc.exceptions.APPCException;
import org.openecomp.appc.executionqueue.ExecutionQueueService;
import org.openecomp.appc.executionqueue.MessageExpirationListener;
import org.openecomp.appc.executionqueue.impl.object.QueueMessage;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -49,7 +51,7 @@ public class ExecutionQueueServiceImpl<M extends Runnable> implements ExecutionQ
@Override
public void putMessage(M message, long timeout, TimeUnit unit) throws APPCException{
try {
- Date expirationTime = calculateExpirationTime(timeout,unit);
+ Instant expirationTime = calculateExpirationTime(timeout,unit);
QueueManager queueManager = QueueManager.getInstance();
boolean enqueueTask = queueManager.enqueueTask(new QueueMessage<M>(message,expirationTime));
if(!enqueueTask){
@@ -66,15 +68,15 @@ public class ExecutionQueueServiceImpl<M extends Runnable> implements ExecutionQ
QueueManager.getInstance().setListener(listener);
}
- private Date calculateExpirationTime(long timeToLive, TimeUnit unit) {
- Date expirationTime = null;
- if(timeToLive > 0){
- long currentTime = System.currentTimeMillis();
- Calendar cal = Calendar.getInstance();
- cal.setTimeInMillis(currentTime + unit.toMillis(timeToLive));
- expirationTime = cal.getTime();
+ private Instant calculateExpirationTime(long timeToLive, TimeUnit unit) {
+ if (timeToLive > 0 && unit != null) {
+ // as of Java 8, there is no built-in conversion method from
+ // TimeUnit to ChronoUnit; do it manually
+ return Instant.now().plusMillis(unit.toMillis(timeToLive));
+ } else {
+ // never expires
+ return Instant.MAX;
}
- return expirationTime;
}
}
diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java
index cf625b4d5..056bfda29 100644
--- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java
+++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/QueueManager.java
@@ -28,6 +28,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import org.openecomp.appc.executionqueue.MessageExpirationListener;
import org.openecomp.appc.executionqueue.helper.Util;
import org.openecomp.appc.executionqueue.impl.object.QueueMessage;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -69,7 +70,7 @@ public class QueueManager {
while (true){
try{
QueueMessage<? extends Runnable> queueMessage = queue.take();
- if(messageExpired(queueMessage)){
+ if (queueMessage.isExpired()) {
logger.debug("Message expired "+ queueMessage.getMessage());
if(listener != null){
listener.onMessageExpiration(queueMessage.getMessage());
@@ -98,11 +99,4 @@ public class QueueManager {
return queue.offer(queueMessage);
}
- private boolean messageExpired(QueueMessage<? extends Runnable> queueMessage) {
- if(queueMessage.getExpirationTime() != null){
- return queueMessage.getExpirationTime().getTime() < System.currentTimeMillis();
- }
- return false;
- }
-
}
diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java
index bbf805871..d3097e650 100644
--- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java
+++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/openecomp/appc/executionqueue/impl/object/QueueMessage.java
@@ -21,22 +21,23 @@
package org.openecomp.appc.executionqueue.impl.object;
-import java.util.Date;
+import java.time.Instant;
+import java.util.Objects;
public class QueueMessage<M extends Runnable> {
- M message;
- Date expirationTime;
- public QueueMessage(M message, Date expirationTime){
+ private final M message;
+ private final Instant expirationTime;
+ public QueueMessage(M message, Instant expirationTime){
this.message = message;
- this.expirationTime = expirationTime;
+ this.expirationTime = Objects.requireNonNull(expirationTime);
}
public M getMessage() {
return message;
}
- public Date getExpirationTime() {
- return expirationTime;
+ public boolean isExpired() {
+ return expirationTime.isBefore(Instant.now());
}
}
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java
index 74040d3e4..c5278e57c 100644
--- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java
+++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/impl/TransactionRecorderImpl.java
@@ -54,10 +54,10 @@ public class TransactionRecorderImpl implements TransactionRecorder {
}
connection = DBUtils.getConnection(APPCCTL_SCHEMA);
stmt = connection.prepareStatement(queryString);
- stmt.setTimestamp(1, new java.sql.Timestamp(record.getTimeStamp().getTime()));
+ stmt.setTimestamp(1, new java.sql.Timestamp(record.getTimeStamp().toEpochMilli()));
stmt.setString(2, record.getRequestID());
- stmt.setTimestamp(3, new java.sql.Timestamp(record.getStartTime().getTime()));
- stmt.setTimestamp(4, new java.sql.Timestamp(record.getEndTime().getTime()));
+ stmt.setTimestamp(3, new java.sql.Timestamp(record.getStartTime().toEpochMilli()));
+ stmt.setTimestamp(4, new java.sql.Timestamp(record.getEndTime().toEpochMilli()));
stmt.setString(5, record.getTargetID());
stmt.setString(6, record.getTargetType());
stmt.setString(7, record.getSubComponent());
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java
index 4807aed0a..c2c662703 100644
--- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java
+++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/openecomp/appc/transactionrecorder/objects/TransactionRecord.java
@@ -21,7 +21,7 @@
package org.openecomp.appc.transactionrecorder.objects;
-import java.util.Date;
+import java.time.Instant;
public class TransactionRecord {
@@ -38,10 +38,10 @@ public class TransactionRecord {
- Result - Success/Error code + description,as published to the initiator RequestHandlerResponse.ACCEPTED/RequestHandlerResponse.REJECTED + String (description)
*/
- private Date timeStamp;
+ private Instant timeStamp;
private String requestID;
- private Date startTime;
- private Date endTime;
+ private Instant startTime;
+ private Instant endTime;
private String targetID;
private String targetType;
private String subComponent;
@@ -49,11 +49,11 @@ public class TransactionRecord {
private String resultCode;
private String description;
- public Date getTimeStamp() {
+ public Instant getTimeStamp() {
return timeStamp;
}
- public void setTimeStamp(Date timeStamp) {
+ public void setTimeStamp(Instant timeStamp) {
this.timeStamp = timeStamp;
}
@@ -65,19 +65,19 @@ public class TransactionRecord {
this.requestID = requestID;
}
- public Date getStartTime() {
+ public Instant getStartTime() {
return startTime;
}
- public void setStartTime(Date startTime) {
+ public void setStartTime(Instant startTime) {
this.startTime = startTime;
}
- public Date getEndTime() {
+ public Instant getEndTime() {
return endTime;
}
- public void setEndTime(Date endTime) {
+ public void setEndTime(Instant endTime) {
this.endTime = endTime;
}