com.google.guava
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java
index b9af724a..a83df33c 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,9 @@
package com.flipkart.ranger.core.finder;
-import com.flipkart.ranger.core.finder.signals.ScheduledRegistryUpdateSignal;
+import com.flipkart.ranger.core.finder.nodeselector.RandomServiceNodeSelector;
+import com.flipkart.ranger.core.finder.serviceregistry.ServiceRegistryUpdater;
+import com.flipkart.ranger.core.finder.serviceregistry.signal.ScheduledRegistryUpdateSignal;
import com.flipkart.ranger.core.model.*;
import com.flipkart.ranger.core.signals.Signal;
import com.google.common.base.Preconditions;
@@ -31,20 +33,22 @@
import java.util.function.Consumer;
@Slf4j
+@SuppressWarnings("unchecked")
public abstract class BaseServiceFinderBuilder
<
T,
R extends ServiceRegistry,
- F extends ServiceFinder,
- B extends BaseServiceFinderBuilder,
- D extends Deserializer> {
+ F extends ServiceFinder,
+ B extends BaseServiceFinderBuilder,
+ D extends Deserializer,
+ C extends Criteria> {
protected String namespace;
protected String serviceName;
protected int nodeRefreshIntervalMs;
protected boolean disablePushUpdaters;
protected D deserializer;
- protected ShardSelector shardSelector;
+ protected ShardSelector shardSelector;
protected ServiceNodeSelector nodeSelector = new RandomServiceNodeSelector<>();
protected final List> additionalRefreshSignals = new ArrayList<>();
protected final List> startSignalHandlers = Lists.newArrayList();
@@ -65,7 +69,7 @@ public B withDeserializer(D deserializer) {
return (B)this;
}
- public B withShardSelector(ShardSelector shardSelector) {
+ public B withShardSelector(ShardSelector shardSelector) {
this.shardSelector = shardSelector;
return (B)this;
}
@@ -150,7 +154,7 @@ protected F buildFinder() {
log.debug("Added additional signal handlers");
}
- val updater = new ServiceRegistryUpdater(registry, nodeDataSource, signalGenerators, deserializer);
+ val updater = new ServiceRegistryUpdater<>(registry, nodeDataSource, signalGenerators, deserializer);
finder.getStartSignal()
.registerConsumers(startSignalHandlers)
.registerConsumer(x -> nodeDataSource.start())
@@ -173,7 +177,7 @@ protected List> implementationSpecificRefreshSignals(Service service,
protected abstract F buildFinder(
Service service,
- ShardSelector shardSelector,
+ ShardSelector shardSelector,
ServiceNodeSelector nodeSelector);
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java
index d6004f9f..0ab7ab8a 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,11 +16,8 @@
package com.flipkart.ranger.core.finder;
-import com.flipkart.ranger.core.model.ServiceNode;
-import com.flipkart.ranger.core.model.ServiceRegistry;
-import com.flipkart.ranger.core.model.ShardSelector;
+import com.flipkart.ranger.core.model.*;
import com.flipkart.ranger.core.signals.ExternalTriggeredSignal;
-import com.flipkart.ranger.core.model.ServiceNodeSelector;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -28,10 +25,10 @@
import java.util.List;
@Slf4j
-public abstract class ServiceFinder> {
+public abstract class ServiceFinder, ServiceRegistryType extends ServiceRegistry> {
@Getter
private final ServiceRegistryType serviceRegistry;
- private final ShardSelector shardSelector;
+ private final ShardSelector shardSelector;
private final ServiceNodeSelector nodeSelector;
@Getter
private final ExternalTriggeredSignal startSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList());
@@ -40,14 +37,14 @@ public abstract class ServiceFinder shardSelector,
+ ShardSelector shardSelector,
ServiceNodeSelector nodeSelector) {
this.serviceRegistry = serviceRegistry;
this.shardSelector = shardSelector;
this.nodeSelector = nodeSelector;
}
- public ServiceNode get(T criteria) {
+ public ServiceNode get(C criteria) {
List> nodes = shardSelector.nodes(criteria, serviceRegistry);
if (null == nodes || nodes.isEmpty()) {
return null;
@@ -55,7 +52,7 @@ public ServiceNode get(T criteria) {
return nodeSelector.select(nodes);
}
- public List> getAll(T criteria) {
+ public List> getAll(C criteria) {
return shardSelector.nodes(criteria, serviceRegistry);
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java
similarity index 70%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java
index 5c0405c3..44e66eb5 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,15 +14,16 @@
* limitations under the License.
*/
-package com.flipkart.ranger.core.finder.sharded;
+package com.flipkart.ranger.core.finder;
-import com.flipkart.ranger.core.model.ShardSelector;
-import com.flipkart.ranger.core.finder.ServiceFinder;
+import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry;
+import com.flipkart.ranger.core.model.Criteria;
import com.flipkart.ranger.core.model.ServiceNodeSelector;
+import com.flipkart.ranger.core.model.ShardSelector;
-public class SimpleShardedServiceFinder extends ServiceFinder> {
+public class SimpleShardedServiceFinder> extends ServiceFinder> {
public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry,
- ShardSelector> shardSelector,
+ ShardSelector> shardSelector,
ServiceNodeSelector nodeSelector) {
super(serviceRegistry, shardSelector, nodeSelector);
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java
similarity index 63%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java
index 25a2a596..a6aafb65 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,27 +14,25 @@
* limitations under the License.
*/
-package com.flipkart.ranger.core.finder.sharded;
+package com.flipkart.ranger.core.finder;
-import com.flipkart.ranger.core.finder.BaseServiceFinderBuilder;
-import com.flipkart.ranger.core.model.Deserializer;
-import com.flipkart.ranger.core.model.Service;
-import com.flipkart.ranger.core.model.ServiceNodeSelector;
-import com.flipkart.ranger.core.model.ShardSelector;
+import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry;
+import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector;
+import com.flipkart.ranger.core.model.*;
-public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer>
- extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D> {
+public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, C extends Criteria>
+ extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, C> {
@Override
- protected SimpleShardedServiceFinder buildFinder(
+ protected SimpleShardedServiceFinder buildFinder(
Service service,
- ShardSelector> shardSelector,
- ServiceNodeSelector nodeSelector) {
+ ShardSelector> shardSelector,
+ ServiceNodeSelector nodeSelector
+ ) {
if (null == shardSelector) {
shardSelector = new MatchingShardSelector<>();
}
final MapBasedServiceRegistry serviceRegistry = new MapBasedServiceRegistry<>(service);
return new SimpleShardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector);
}
-
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java
similarity index 57%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterFinder.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java
index be55c096..783a7a1c 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterFinder.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java
@@ -1,12 +1,12 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
- *
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -14,16 +14,17 @@
* limitations under the License.
*/
-package com.flipkart.ranger.core.finder.unsharded;
+package com.flipkart.ranger.core.finder;
-import com.flipkart.ranger.core.finder.ServiceFinder;
+import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry;
+import com.flipkart.ranger.core.model.Criteria;
import com.flipkart.ranger.core.model.ServiceNodeSelector;
import com.flipkart.ranger.core.model.ShardSelector;
-public class UnshardedClusterFinder extends ServiceFinder {
- public UnshardedClusterFinder(UnshardedClusterServiceRegistry serviceRegistry,
- ShardSelector shardSelector,
- ServiceNodeSelector nodeSelector) {
+public class SimpleUnshardedServiceFinder> extends ServiceFinder> {
+ public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry,
+ ShardSelector> shardSelector,
+ ServiceNodeSelector nodeSelector) {
super(serviceRegistry, shardSelector, nodeSelector);
}
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java
new file mode 100644
index 00000000..7917b705
--- /dev/null
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package com.flipkart.ranger.core.finder;
+
+import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry;
+import com.flipkart.ranger.core.finder.shardselector.ListShardSelector;
+import com.flipkart.ranger.core.model.*;
+
+public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, C extends Criteria>
+ extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, C> {
+
+ @Override
+ protected SimpleUnshardedServiceFinder buildFinder(
+ Service service,
+ ShardSelector> shardSelector,
+ ServiceNodeSelector nodeSelector
+ ) {
+ if (null == shardSelector) {
+ shardSelector = new ListShardSelector<>();
+ }
+ final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service);
+ return new SimpleUnshardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector);
+ }
+}
\ No newline at end of file
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RandomServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java
similarity index 94%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/RandomServiceNodeSelector.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java
index 3dc91885..6db1c034 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RandomServiceNodeSelector.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.flipkart.ranger.core.finder;
+package com.flipkart.ranger.core.finder.nodeselector;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.model.ServiceNodeSelector;
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RoundRobinServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java
similarity index 95%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/RoundRobinServiceNodeSelector.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java
index 62ae215d..99b81d14 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RoundRobinServiceNodeSelector.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.flipkart.ranger.core.finder;
+package com.flipkart.ranger.core.finder.nodeselector;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.model.ServiceNodeSelector;
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java
similarity index 67%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterServiceRegistry.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java
index d5fe01af..c0e7f0ab 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterServiceRegistry.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,31 +13,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.flipkart.ranger.core.finder.unsharded;
+package com.flipkart.ranger.core.finder.serviceregistry;
import com.flipkart.ranger.core.model.Service;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.model.ServiceRegistry;
import com.google.common.collect.ImmutableList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
-public class UnshardedClusterServiceRegistry extends ServiceRegistry {
- private AtomicReference>> nodes
+public class ListBasedServiceRegistry extends ServiceRegistry {
+ private final AtomicReference>> nodes
= new AtomicReference<>();
- public UnshardedClusterServiceRegistry(Service service) {
+ public ListBasedServiceRegistry(Service service) {
super(service);
}
- public List> nodes() {
- return nodes.get();
+ public List> nodeList() {
+ List> nodes = this.nodes.get();
+ return null == nodes ? Collections.emptyList() : nodes;
}
@Override
- public void updateNodes(List> serviceNodes) {
+ public void updateNodes(List> serviceNodes) {
nodes.set(ImmutableList.copyOf(serviceNodes));
}
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java
similarity index 76%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java
index 116b411e..afaf6fb3 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java
@@ -1,20 +1,19 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
- *
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
-
-package com.flipkart.ranger.core.finder.sharded;
+package com.flipkart.ranger.core.finder.serviceregistry;
import com.flipkart.ranger.core.model.Service;
import com.flipkart.ranger.core.model.ServiceNode;
@@ -23,14 +22,15 @@
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ListMultimap;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
public class MapBasedServiceRegistry extends ServiceRegistry {
- private AtomicReference>> nodes = new AtomicReference<>();
+ private final AtomicReference>> nodes = new AtomicReference<>();
- public MapBasedServiceRegistry(
- Service service) {
+ public MapBasedServiceRegistry(Service service) {
super(service);
}
@@ -39,6 +39,12 @@ public ListMultimap> nodes() {
return null == nodeList ? ImmutableListMultimap.of() : nodeList;
}
+ @Override
+ public List> nodeList() {
+ final ListMultimap> nodeList = nodes.get();
+ return null == nodeList ? Collections.emptyList() : new ArrayList<>(nodeList.values());
+ }
+
@Override
public void updateNodes(List> nodes) {
ListMultimap> serviceNodes = ArrayListMultimap.create();
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java
similarity index 89%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java
index c348036f..5a5a2634 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java
@@ -1,20 +1,19 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
- *
+ *
* 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
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/
-
-package com.flipkart.ranger.core.finder;
+package com.flipkart.ranger.core.finder.serviceregistry;
import com.flipkart.ranger.core.model.Deserializer;
import com.flipkart.ranger.core.model.NodeDataSource;
@@ -44,13 +43,13 @@ public class ServiceRegistryUpdater> {
private final NodeDataSource nodeDataSource;
private final D deserializer;
- private Lock checkLock = new ReentrantLock();
- private Condition checkCondition = checkLock.newCondition();
+ private final Lock checkLock = new ReentrantLock();
+ private final Condition checkCondition = checkLock.newCondition();
private boolean checkForUpdate = false;
private Future queryThreadFuture;
- private ExecutorService executorService = Executors.newFixedThreadPool(1);
- private AtomicBoolean initialRefreshCompleted = new AtomicBoolean(false);
+ private final ExecutorService executorService = Executors.newFixedThreadPool(1);
+ private final AtomicBoolean initialRefreshCompleted = new AtomicBoolean(false);
public ServiceRegistryUpdater(
ServiceRegistry serviceRegistry,
@@ -126,7 +125,7 @@ private Void queryExecutor() {
}
}
- private void updateRegistry() {
+ private void updateRegistry() throws InterruptedException {
log.debug("Checking for updates on data source for service: {}",
serviceRegistry.getService().getServiceName());
if(!nodeDataSource.isActive()) {
@@ -134,11 +133,11 @@ private void updateRegistry() {
serviceRegistry.getService().getServiceName());
return;
}
- val nodes = nodeDataSource.refresh(deserializer).orElse(null);
- if (null != nodes) {
- log.debug("Updating nodelist of size: {} for [{}]", nodes.size(),
+ val nodeList = nodeDataSource.refresh(deserializer);
+ if (nodeList.isPresent()) {
+ log.debug("Updating nodelist of size: {} for [{}]", nodeList.get().size(),
serviceRegistry.getService().getServiceName());
- serviceRegistry.updateNodes(nodes);
+ serviceRegistry.updateNodes(nodeList.get());
initialRefreshCompleted.compareAndSet(false, true);
}
else {
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java
new file mode 100644
index 00000000..c728f923
--- /dev/null
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package com.flipkart.ranger.core.finder.serviceregistry.signal;
+
+import com.flipkart.ranger.core.model.Service;
+import com.flipkart.ranger.core.signals.ScheduledSignal;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Collections;
+
+/**
+ *
+ */
+@Slf4j
+public class ScheduledRegistryUpdateSignal extends ScheduledSignal {
+
+ public ScheduledRegistryUpdateSignal(
+ Service service,
+ long refreshIntervalMillis) {
+ super(service, () -> null, Collections.emptyList(), refreshIntervalMillis);
+ }
+
+}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java
new file mode 100644
index 00000000..d72fa6ae
--- /dev/null
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package com.flipkart.ranger.core.finder.shardselector;
+
+import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry;
+import com.flipkart.ranger.core.model.Criteria;
+import com.flipkart.ranger.core.model.ServiceNode;
+import com.flipkart.ranger.core.model.ShardSelector;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ListShardSelector> implements ShardSelector> {
+
+ @Override
+ public List> nodes(C criteria, ListBasedServiceRegistry serviceRegistry) {
+ if(null == criteria){
+ return serviceRegistry.nodeList();
+ }
+ return serviceRegistry.nodeList().stream().filter(node -> criteria.apply(node.getNodeData())).collect(Collectors.toList());
+ }
+
+
+}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java
new file mode 100644
index 00000000..f94b2363
--- /dev/null
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+
+package com.flipkart.ranger.core.finder.shardselector;
+
+import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry;
+import com.flipkart.ranger.core.model.Criteria;
+import com.flipkart.ranger.core.model.ServiceNode;
+import com.flipkart.ranger.core.model.ShardSelector;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class MatchingShardSelector> implements ShardSelector> {
+
+ @Override
+ public List> nodes(C criteria, MapBasedServiceRegistry serviceRegistry) {
+ if(null == criteria) return serviceRegistry.nodeList();
+ return serviceRegistry.nodes()
+ .entries()
+ .stream()
+ .filter(e -> criteria.apply(e.getKey()))
+ .map(Map.Entry::getValue)
+ .collect(Collectors.toList());
+ }
+}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java
similarity index 62%
rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java
rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java
index 5dc212ae..41d3c8fa 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package com.flipkart.ranger.core.finder.shardselector;
-package com.flipkart.ranger.core.finder.sharded;
-
-import com.flipkart.ranger.core.model.ShardSelector;
+import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry;
+import com.flipkart.ranger.core.model.Criteria;
import com.flipkart.ranger.core.model.ServiceNode;
+import com.flipkart.ranger.core.model.ShardSelector;
import java.util.List;
-public class MatchingShardSelector implements ShardSelector> {
-
+public class NoopShardSelector> implements ShardSelector> {
@Override
- public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) {
- return serviceRegistry.nodes().get(criteria);
+ public List> nodes(C criteria, ListBasedServiceRegistry serviceRegistry) {
+ return serviceRegistry.nodeList();
}
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/signals/ScheduledRegistryUpdateSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/signals/ScheduledRegistryUpdateSignal.java
deleted file mode 100644
index 63ae6289..00000000
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/signals/ScheduledRegistryUpdateSignal.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.flipkart.ranger.core.finder.signals;
-
-import com.flipkart.ranger.core.model.Service;
-import com.flipkart.ranger.core.signals.ScheduledSignal;
-import lombok.extern.slf4j.Slf4j;
-
-import java.util.Collections;
-
-/**
- *
- */
-@Slf4j
-public class ScheduledRegistryUpdateSignal extends ScheduledSignal {
-
- public ScheduledRegistryUpdateSignal(
- Service service,
- long refreshIntervalMillis) {
- super(service, () -> null, Collections.emptyList(), refreshIntervalMillis);
- }
-
-}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java
deleted file mode 100644
index b9af94aa..00000000
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright 2015 Flipkart Internet Pvt. Ltd.
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * 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.
- */
-
-package com.flipkart.ranger.core.finder.unsharded;
-
-import com.flipkart.ranger.core.model.Deserializer;
-import com.flipkart.ranger.core.model.Service;
-import com.flipkart.ranger.core.model.ShardSelector;
-import com.flipkart.ranger.core.finder.BaseServiceFinderBuilder;
-import com.flipkart.ranger.core.model.ServiceNodeSelector;
-
-public abstract class UnshardedFinderBuilder, D extends Deserializer>
- extends BaseServiceFinderBuilder {
-
- @Override
- protected UnshardedClusterFinder buildFinder(
- Service service,
- ShardSelector shardSelector,
- ServiceNodeSelector nodeSelector) {
- final UnshardedClusterServiceRegistry unshardedClusterServiceRegistry
- = new UnshardedClusterServiceRegistry(service);
- return new UnshardedClusterFinder(unshardedClusterServiceRegistry, new NoOpShardSelector(), nodeSelector);
- }
-}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java
index 7a014377..dc579606 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
package com.flipkart.ranger.core.finderhub;
import com.flipkart.ranger.core.model.Service;
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java
index 5c89b2ca..d8b9c52e 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java
@@ -1,13 +1,30 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
package com.flipkart.ranger.core.finderhub;
import com.flipkart.ranger.core.finder.ServiceFinder;
+import com.flipkart.ranger.core.model.Criteria;
import com.flipkart.ranger.core.model.Service;
import com.flipkart.ranger.core.model.ServiceRegistry;
/**
*
*/
-public interface ServiceFinderFactory> {
+public interface ServiceFinderFactory, R extends ServiceRegistry> {
+
+ ServiceFinder buildFinder(final Service service);
- ServiceFinder buildFinder(final Service service);
}
diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java
index aceeb761..d47298dc 100644
--- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java
+++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java
@@ -1,6 +1,22 @@
+/*
+ * Copyright 2015 Flipkart Internet Pvt. Ltd.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
package com.flipkart.ranger.core.finderhub;
import com.flipkart.ranger.core.finder.ServiceFinder;
+import com.flipkart.ranger.core.model.Criteria;
import com.flipkart.ranger.core.model.Service;
import com.flipkart.ranger.core.model.ServiceRegistry;
import com.flipkart.ranger.core.signals.ExternalTriggeredSignal;
@@ -26,12 +42,12 @@
*
*/
@Slf4j
-public class ServiceFinderHub> {
- private final AtomicReference