/*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.listeners.TypedMessageListener;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.pap.main.parameters.PdpParameters;
 
 /**
  * Listener for PDP Status messages which either represent registration or heart beat.
  */
 public class PdpHeartbeatListener implements TypedMessageListener<PdpStatus> {
 
+    private final PdpParameters params;
+
+    /**
+     * Constructs the object.
+     *
+     * @param params PDP parameters
+     */
+    public PdpHeartbeatListener(PdpParameters params) {
+        this.params = params;
+    }
+
     @Override
     public void onTopicEvent(final CommInfrastructure infra, final String topic, final PdpStatus message) {
 
-        final PdpStatusMessageHandler handler = new PdpStatusMessageHandler();
+        final PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params);
         handler.handlePdpStatus(message);
     }
 }
 
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 import java.util.Arrays;
 import java.util.List;
 import java.util.Optional;
-
+import java.util.concurrent.TimeUnit;
 import org.apache.commons.lang3.builder.EqualsBuilder;
 import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.pap.main.PapConstants;
 import org.onap.policy.pap.main.PolicyPapException;
+import org.onap.policy.pap.main.parameters.PdpParameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PdpStatusMessageHandler extends PdpMessageGenerator {
     private static final Logger LOGGER = LoggerFactory.getLogger(PdpStatusMessageHandler.class);
 
+    private final PdpParameters params;
+
     /**
      * Constructs the object.
+     *
+     * @param params PDP parameters
      */
-    public PdpStatusMessageHandler() {
+    public PdpStatusMessageHandler(PdpParameters params) {
         super(true);
+        this.params = params;
     }
 
     /**
      * @param message the PdpStatus message
      */
     public void handlePdpStatus(final PdpStatus message) {
+        long diffms = System.currentTimeMillis() - message.getTimestampMs();
+        if (diffms > params.getMaxMessageAgeMs()) {
+            long diffsec = TimeUnit.SECONDS.convert(diffms, TimeUnit.MILLISECONDS);
+            LOGGER.info("discarding status message from {} age {}s", message.getName(), diffsec);
+            return;
+        }
+
         synchronized (updateLock) {
             try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
                 if (message.getPdpSubgroup() == null) {
 
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.pap.main.parameters;
 
+import java.util.concurrent.TimeUnit;
 import lombok.Getter;
 import org.onap.policy.common.parameters.ParameterGroupImpl;
 import org.onap.policy.common.parameters.annotations.Min;
 @Getter
 public class PdpParameters extends ParameterGroupImpl {
 
+    /**
+     * Default maximum message age, in milliseconds, that should be examined. Any message
+     * older than this is discarded.
+     */
+    public static final long DEFAULT_MAX_AGE_MS = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
+
+
     @Min(1)
     private long heartBeatMs;
 
+    @Min(1)
+    private long maxMessageAgeMs =  DEFAULT_MAX_AGE_MS;
+
     private PdpUpdateParameters updateParameters;
     private PdpStateChangeParameters stateChangeParameters;
 
 
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
             this.papParameterGroup = papParameterGroup;
             this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
             this.reqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES);
-            this.pdpHeartbeatListener = new PdpHeartbeatListener();
+            this.pdpHeartbeatListener = new PdpHeartbeatListener(papParameterGroup.getPdpParameters());
 
         } catch (final RuntimeException e) {
             throw new PolicyPapRuntimeException(e);
 
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
-
 import org.junit.Test;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
 import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.pap.main.parameters.PdpParameters;
 import org.onap.policy.pap.main.rest.e2e.End2EndBase;
 
 /**
     @Test
     public void testPdpHeartbeatListener() throws CoderException, PfModelException {
         addGroups("PdpGroups.json");
-        pdpHeartbeatListener = new PdpHeartbeatListener();
+        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters());
 
         // Testing pdp registration success case
         final PdpStatus status1 = new PdpStatus();
         pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status7);
         verifyPdpGroup(DEFAULT_GROUP, 2);
 
+        // Testing old message for pdp_1 - should have no effect
+        final PdpStatus status7b = new PdpStatus();
+        status7b.setTimestampMs(System.currentTimeMillis() - PdpParameters.DEFAULT_MAX_AGE_MS - 1);
+        status7b.setName(PDP_NAME);
+        status7b.setState(PdpState.TERMINATED);
+        status7b.setPdpGroup(DEFAULT_GROUP);
+        status7b.setPdpType(APEX_TYPE);
+        status7b.setPdpSubgroup(APEX_TYPE);
+        status7b.setHealthy(PdpHealthStatus.HEALTHY);
+        final List<ToscaPolicyIdentifier> idents7b =
+                Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+        status7b.setPolicies(idents7b);
+        pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status7b);
+        verifyPdpGroup(DEFAULT_GROUP, 2);
+
         // Testing pdp termination case for pdp_1
         final PdpStatus status8 = new PdpStatus();
         status8.setName(PDP_NAME);
     @Test
     public void testPdpStatistics() throws CoderException, PfModelException, ParseException {
         addGroups("PdpGroups.json");
-        pdpHeartbeatListener = new PdpHeartbeatListener();
+        pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters());
         timeStamp = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01");
 
         // init default pdp group
 
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
         assertEquals(5, state.getMaxWaitMs());
 
         assertEquals(6L, params.getHeartBeatMs());
+
+        assertEquals(20000L, params.getMaxMessageAgeMs());
+
+        // check default value
+        assertEquals(600000L, new PdpParameters().getMaxMessageAgeMs());
     }
 
     @Test
         assertTrue(result.getResult().contains(
                         "field 'heartBeatMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"')));
 
+        // invalid max message age
+        json2 = json.replaceFirst(": 20000", ": 0");
+        result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
+        assertFalse(result.isValid());
+        assertTrue(result.getResult().contains(
+                        "field 'maxMessageAgeMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"')));
+
         // no update params
         json2 = testData.nullifyField(json, "updateParameters");
         result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
 
             "maxRetryCount": 1,
             "maxWaitMs": 5
         },
-        "heartBeatMs": 6
+        "heartBeatMs": 6,
+        "maxMessageAgeMs": 20000
     },
     "databaseProviderParameters": {
         "name": "PolicyModelsProviderParameters",