Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / onap / msb / apiroute / wrapper / consulextend / expose / ConsulIndexFilter.java
1 package org.onap.msb.apiroute.wrapper.consulextend.expose;
2
3 import java.math.BigInteger;
4 import java.util.concurrent.atomic.AtomicReference;
5
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8
9 import com.orbitz.consul.model.ConsulResponse;
10
11 public class ConsulIndexFilter<T> implements WatchTask.Filter<T> {
12
13         private final static Logger LOGGER = LoggerFactory
14                         .getLogger(ConsulIndexFilter.class);
15
16         private final AtomicReference<BigInteger> latestIndex = new AtomicReference<BigInteger>(
17                         null);
18
19         @Override
20         public boolean filter(final ConsulResponse<T> object) {
21                 // TODO Auto-generated method stub
22                 return isChanged(object);
23         }
24
25         private boolean isChanged(final ConsulResponse<T> consulResponse) {
26
27                 if (consulResponse != null && consulResponse.getIndex() != null
28                                 && !consulResponse.getIndex().equals(latestIndex.get())) {
29                         
30                         if(LOGGER.isDebugEnabled()){
31                                 //第一次不打印
32                                 if (latestIndex.get()!=null) {
33                                         LOGGER.debug("consul index compare:new-"
34                                                         + consulResponse.getIndex() + "  old-"
35                                                         + latestIndex.get());
36                                 }
37                                 
38                         }
39
40                         this.latestIndex.set(consulResponse.getIndex());
41                         return true;
42                 }
43
44                 return false;
45         }
46         
47         
48 }