1 /*******************************************************************************
2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16 package org.onap.msb.apiroute.wrapper.consulextend.expose;
18 import java.math.BigInteger;
19 import java.util.concurrent.atomic.AtomicReference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.orbitz.consul.model.ConsulResponse;
26 public class ConsulIndexFilter<T> implements WatchTask.Filter<T> {
28 private final static Logger LOGGER = LoggerFactory
29 .getLogger(ConsulIndexFilter.class);
31 private final AtomicReference<BigInteger> latestIndex = new AtomicReference<BigInteger>(
35 public boolean filter(final ConsulResponse<T> object) {
36 // TODO Auto-generated method stub
37 return isChanged(object);
40 private boolean isChanged(final ConsulResponse<T> consulResponse) {
42 if (consulResponse != null && consulResponse.getIndex() != null
43 && !consulResponse.getIndex().equals(latestIndex.get())) {
45 if(LOGGER.isDebugEnabled()){
47 if (latestIndex.get()!=null) {
48 LOGGER.debug("consul index compare:new-"
49 + consulResponse.getIndex() + " old-"
55 this.latestIndex.set(consulResponse.getIndex());