/*-
* ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
package org.openecomp.appc.executionqueue.impl;
+import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;
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;
@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){
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;
}
}