Remove FluentFuture from DOM RPC contracts
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / DOMRpcRouter.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.dom.broker;
9
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.collect.ClassToInstanceMap;
15 import com.google.common.collect.Collections2;
16 import com.google.common.collect.ImmutableClassToInstanceMap;
17 import com.google.common.collect.ImmutableList;
18 import com.google.common.collect.ImmutableList.Builder;
19 import com.google.common.collect.ImmutableSet;
20 import com.google.common.collect.MapDifference;
21 import com.google.common.collect.MapDifference.ValueDifference;
22 import com.google.common.collect.Maps;
23 import com.google.common.collect.Sets;
24 import com.google.common.util.concurrent.Futures;
25 import com.google.common.util.concurrent.ListenableFuture;
26 import com.google.common.util.concurrent.ThreadFactoryBuilder;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Map.Entry;
34 import java.util.Optional;
35 import java.util.Set;
36 import java.util.concurrent.ExecutorService;
37 import java.util.concurrent.Executors;
38 import java.util.concurrent.ThreadFactory;
39 import javax.annotation.concurrent.GuardedBy;
40 import org.eclipse.jdt.annotation.NonNullByDefault;
41 import org.opendaylight.mdsal.dom.api.DOMActionAvailabilityExtension;
42 import org.opendaylight.mdsal.dom.api.DOMActionAvailabilityExtension.AvailabilityListener;
43 import org.opendaylight.mdsal.dom.api.DOMActionImplementation;
44 import org.opendaylight.mdsal.dom.api.DOMActionInstance;
45 import org.opendaylight.mdsal.dom.api.DOMActionNotAvailableException;
46 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
47 import org.opendaylight.mdsal.dom.api.DOMActionProviderServiceExtension;
48 import org.opendaylight.mdsal.dom.api.DOMActionResult;
49 import org.opendaylight.mdsal.dom.api.DOMActionService;
50 import org.opendaylight.mdsal.dom.api.DOMActionServiceExtension;
51 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
52 import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
53 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
54 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
55 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
56 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
57 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
58 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
59 import org.opendaylight.mdsal.dom.api.DOMRpcService;
60 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
61 import org.opendaylight.mdsal.dom.spi.AbstractDOMRpcImplementationRegistration;
62 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
63 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
64 import org.opendaylight.yangtools.concepts.AbstractRegistration;
65 import org.opendaylight.yangtools.concepts.ListenerRegistration;
66 import org.opendaylight.yangtools.concepts.ObjectRegistration;
67 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
68 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
69 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
70 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
71 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
72 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
73 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
76
77 public final class DOMRpcRouter extends AbstractRegistration implements SchemaContextListener {
78     private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder().setNameFormat(
79             "DOMRpcRouter-listener-%s").setDaemon(true).build();
80
81     private final ExecutorService listenerNotifier = Executors.newSingleThreadExecutor(THREAD_FACTORY);
82     private final DOMActionProviderService actionProviderService = new ActionProviderServiceFacade();
83     private final DOMActionService actionService = new ActionServiceFacade();
84     private final DOMRpcProviderService rpcProviderService = new RpcProviderServiceFacade();
85     private final DOMRpcService rpcService = new RpcServiceFacade();
86
87     @GuardedBy("this")
88     private Collection<Registration<?>> listeners = Collections.emptyList();
89
90     @GuardedBy("this")
91     private Collection<ActionRegistration<?>> actionListeners = Collections.emptyList();
92
93     private volatile DOMRpcRoutingTable routingTable = DOMRpcRoutingTable.EMPTY;
94
95     private volatile DOMActionRoutingTable actionRoutingTable = DOMActionRoutingTable.EMPTY;
96
97     private ListenerRegistration<?> listenerRegistration;
98
99     public static DOMRpcRouter newInstance(final DOMSchemaService schemaService) {
100         final DOMRpcRouter rpcRouter = new DOMRpcRouter();
101         rpcRouter.listenerRegistration = schemaService.registerSchemaContextListener(rpcRouter);
102         return rpcRouter;
103     }
104
105     public DOMActionService getActionService() {
106         return actionService;
107     }
108
109     public DOMActionProviderService getActionProviderService() {
110         return actionProviderService;
111     }
112
113     public DOMRpcService getRpcService() {
114         return rpcService;
115     }
116
117     public DOMRpcProviderService getRpcProviderService() {
118         return rpcProviderService;
119     }
120
121     private synchronized void removeRpcImplementation(final DOMRpcImplementation implementation,
122             final Set<DOMRpcIdentifier> rpcs) {
123         final DOMRpcRoutingTable oldTable = routingTable;
124         final DOMRpcRoutingTable newTable = (DOMRpcRoutingTable) oldTable.remove(implementation, rpcs);
125         routingTable = newTable;
126
127         listenerNotifier.execute(() -> notifyRemoved(newTable, implementation));
128     }
129
130     private synchronized void removeActionImplementation(final DOMActionImplementation implementation,
131             final Set<DOMActionInstance> actions) {
132         final DOMActionRoutingTable oldTable = actionRoutingTable;
133         final DOMActionRoutingTable newTable = (DOMActionRoutingTable) oldTable.remove(implementation, actions);
134         actionRoutingTable = newTable;
135
136         listenerNotifier.execute(() -> notifyActionChanged(newTable, implementation));
137     }
138
139     private synchronized void removeListener(final ListenerRegistration<? extends DOMRpcAvailabilityListener> reg) {
140         listeners = ImmutableList.copyOf(Collections2.filter(listeners, input -> !reg.equals(input)));
141     }
142
143     private synchronized void removeActionListener(final ListenerRegistration<? extends AvailabilityListener> reg) {
144         actionListeners = ImmutableList.copyOf(Collections2.filter(actionListeners, input -> !reg.equals(input)));
145     }
146
147     private synchronized void notifyAdded(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
148         for (Registration<?> l : listeners) {
149             l.addRpc(newTable, impl);
150         }
151     }
152
153     private synchronized void notifyRemoved(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
154         for (Registration<?> l : listeners) {
155             l.removeRpc(newTable, impl);
156         }
157     }
158
159     private synchronized void notifyActionChanged(final DOMActionRoutingTable newTable,
160             final DOMActionImplementation impl) {
161         for (ActionRegistration<?> l : actionListeners) {
162             l.actionChanged(newTable, impl);
163         }
164     }
165
166     @Override
167     public synchronized void onGlobalContextUpdated(final SchemaContext context) {
168         final DOMRpcRoutingTable oldTable = routingTable;
169         final DOMRpcRoutingTable newTable = (DOMRpcRoutingTable) oldTable.setSchemaContext(context);
170         routingTable = newTable;
171
172         final DOMActionRoutingTable oldActionTable = actionRoutingTable;
173         final DOMActionRoutingTable newActionTable = (DOMActionRoutingTable) oldActionTable.setSchemaContext(context);
174         actionRoutingTable = newActionTable;
175     }
176
177     @Override
178     protected void removeRegistration() {
179         if (listenerRegistration != null) {
180             listenerRegistration.close();
181             listenerRegistration = null;
182         }
183         listenerNotifier.shutdown();
184     }
185
186     @VisibleForTesting
187     synchronized Collection<?> listeners() {
188         return listeners;
189     }
190
191     @VisibleForTesting
192     DOMRpcRoutingTable routingTable() {
193         return routingTable;
194     }
195
196     private static final class Registration<T extends DOMRpcAvailabilityListener>
197         extends AbstractListenerRegistration<T> {
198
199         private Map<SchemaPath, Set<YangInstanceIdentifier>> prevRpcs;
200         private DOMRpcRouter router;
201
202         Registration(final DOMRpcRouter router, final T listener,
203                 final Map<SchemaPath, Set<YangInstanceIdentifier>> rpcs) {
204             super(listener);
205             this.router = requireNonNull(router);
206             this.prevRpcs = requireNonNull(rpcs);
207         }
208
209         @Override
210         protected void removeRegistration() {
211             router.removeListener(this);
212             router = null;
213         }
214
215         void initialTable() {
216             final Collection<DOMRpcIdentifier> added = new ArrayList<>();
217             for (Entry<SchemaPath, Set<YangInstanceIdentifier>> e : prevRpcs.entrySet()) {
218                 added.addAll(Collections2.transform(e.getValue(), i -> DOMRpcIdentifier.create(e.getKey(), i)));
219             }
220             if (!added.isEmpty()) {
221                 getInstance().onRpcAvailable(added);
222             }
223         }
224
225         void addRpc(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
226             final T l = getInstance();
227             if (!l.acceptsImplementation(impl)) {
228                 return;
229             }
230
231             final Map<SchemaPath, Set<YangInstanceIdentifier>> rpcs = verifyNotNull(newTable.getOperations(l));
232             final MapDifference<SchemaPath, Set<YangInstanceIdentifier>> diff = Maps.difference(prevRpcs, rpcs);
233
234             final Collection<DOMRpcIdentifier> added = new ArrayList<>();
235             for (Entry<SchemaPath, Set<YangInstanceIdentifier>> e : diff.entriesOnlyOnRight().entrySet()) {
236                 added.addAll(Collections2.transform(e.getValue(), i -> DOMRpcIdentifier.create(e.getKey(), i)));
237             }
238             for (Entry<SchemaPath, ValueDifference<Set<YangInstanceIdentifier>>> e :
239                     diff.entriesDiffering().entrySet()) {
240                 for (YangInstanceIdentifier i : Sets.difference(e.getValue().rightValue(), e.getValue().leftValue())) {
241                     added.add(DOMRpcIdentifier.create(e.getKey(), i));
242                 }
243             }
244
245             prevRpcs = rpcs;
246             if (!added.isEmpty()) {
247                 l.onRpcAvailable(added);
248             }
249         }
250
251         void removeRpc(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
252             final T l = getInstance();
253             if (!l.acceptsImplementation(impl)) {
254                 return;
255             }
256
257             final Map<SchemaPath, Set<YangInstanceIdentifier>> rpcs = verifyNotNull(newTable.getOperations(l));
258             final MapDifference<SchemaPath, Set<YangInstanceIdentifier>> diff = Maps.difference(prevRpcs, rpcs);
259
260             final Collection<DOMRpcIdentifier> removed = new ArrayList<>();
261             for (Entry<SchemaPath, Set<YangInstanceIdentifier>> e : diff.entriesOnlyOnLeft().entrySet()) {
262                 removed.addAll(Collections2.transform(e.getValue(), i -> DOMRpcIdentifier.create(e.getKey(), i)));
263             }
264             for (Entry<SchemaPath, ValueDifference<Set<YangInstanceIdentifier>>> e :
265                     diff.entriesDiffering().entrySet()) {
266                 for (YangInstanceIdentifier i : Sets.difference(e.getValue().leftValue(), e.getValue().rightValue())) {
267                     removed.add(DOMRpcIdentifier.create(e.getKey(), i));
268                 }
269             }
270
271             prevRpcs = rpcs;
272             if (!removed.isEmpty()) {
273                 l.onRpcUnavailable(removed);
274             }
275         }
276     }
277
278     private static final class ActionRegistration<T extends AvailabilityListener>
279         extends AbstractListenerRegistration<T> {
280
281         private Map<SchemaPath, Set<DOMDataTreeIdentifier>> prevActions;
282         private DOMRpcRouter router;
283
284         ActionRegistration(final DOMRpcRouter router, final T listener,
285                 final Map<SchemaPath, Set<DOMDataTreeIdentifier>> actions) {
286             super(listener);
287             this.router = requireNonNull(router);
288             this.prevActions = requireNonNull(actions);
289         }
290
291         @Override
292         protected void removeRegistration() {
293             router.removeActionListener(this);
294             router = null;
295         }
296
297         void initialTable() {
298             final Collection<DOMActionInstance> added = new ArrayList<>();
299             for (Entry<SchemaPath, Set<DOMDataTreeIdentifier>> e : prevActions.entrySet()) {
300                 added.addAll(Collections2.transform(e.getValue(), i -> DOMActionInstance.of(e.getKey(), i)));
301             }
302             if (!added.isEmpty()) {
303                 getInstance().onActionsChanged(ImmutableSet.of(), ImmutableSet.copyOf(added));
304             }
305         }
306
307         void actionChanged(final DOMActionRoutingTable newTable, final DOMActionImplementation impl) {
308             final T l = getInstance();
309             if (!l.acceptsImplementation(impl)) {
310                 return;
311             }
312
313             final Map<SchemaPath, Set<DOMDataTreeIdentifier>> actions = verifyNotNull(newTable.getOperations(l));
314             final MapDifference<SchemaPath, Set<DOMDataTreeIdentifier>> diff = Maps.difference(prevActions, actions);
315
316             final Set<DOMActionInstance> removed = new HashSet<>();
317             final Set<DOMActionInstance> added = new HashSet<>();
318
319             for (Entry<SchemaPath, Set<DOMDataTreeIdentifier>> e : diff.entriesOnlyOnLeft().entrySet()) {
320                 removed.addAll(Collections2.transform(e.getValue(), i -> DOMActionInstance.of(e.getKey(), i)));
321             }
322
323             for (Entry<SchemaPath, Set<DOMDataTreeIdentifier>> e : diff.entriesOnlyOnRight().entrySet()) {
324                 added.addAll(Collections2.transform(e.getValue(), i -> DOMActionInstance.of(e.getKey(), i)));
325             }
326
327             for (Entry<SchemaPath, ValueDifference<Set<DOMDataTreeIdentifier>>> e :
328                 diff.entriesDiffering().entrySet()) {
329                 for (DOMDataTreeIdentifier i : Sets.difference(e.getValue().leftValue(), e.getValue().rightValue())) {
330                     removed.add(DOMActionInstance.of(e.getKey(), i));
331                 }
332
333                 for (DOMDataTreeIdentifier i : Sets.difference(e.getValue().rightValue(), e.getValue().leftValue())) {
334                     added.add(DOMActionInstance.of(e.getKey(), i));
335                 }
336             }
337
338             prevActions = actions;
339             if (!removed.isEmpty() || !added.isEmpty()) {
340                 l.onActionsChanged(removed, added);
341             }
342         }
343     }
344
345     @NonNullByDefault
346     private final class ActionAvailabilityFacade implements DOMActionAvailabilityExtension {
347         @Override
348         public <T extends AvailabilityListener> ListenerRegistration<T> registerAvailabilityListener(final T listener) {
349             synchronized (DOMRpcRouter.this) {
350                 final ActionRegistration<T> ret = new ActionRegistration<>(DOMRpcRouter.this,
351                     listener, actionRoutingTable.getOperations(listener));
352                 final Builder<ActionRegistration<?>> b = ImmutableList.builder();
353                 b.addAll(actionListeners);
354                 b.add(ret);
355                 actionListeners = b.build();
356
357                 listenerNotifier.execute(ret::initialTable);
358                 return ret;
359             }
360         }
361     }
362
363     @NonNullByDefault
364     private final class ActionServiceFacade implements DOMActionService {
365         private final ClassToInstanceMap<DOMActionServiceExtension> extensions = ImmutableClassToInstanceMap.of(
366             DOMActionAvailabilityExtension.class, new ActionAvailabilityFacade());
367
368         @Override
369         public ClassToInstanceMap<DOMActionServiceExtension> getExtensions() {
370             return extensions;
371         }
372
373         @Override
374         public ListenableFuture<? extends DOMActionResult> invokeAction(final SchemaPath type,
375                 final DOMDataTreeIdentifier path, final ContainerNode input) {
376             final DOMActionRoutingTableEntry entry = (DOMActionRoutingTableEntry) actionRoutingTable.getEntry(type);
377             if (entry == null) {
378                 return Futures.immediateFailedFuture(
379                     new DOMActionNotAvailableException("No implementation of Action %s available", type));
380             }
381
382             return OperationInvocation.invoke(entry, type, path, input);
383         }
384     }
385
386     @NonNullByDefault
387     private final class ActionProviderServiceFacade implements DOMActionProviderService {
388         @Override
389         public ClassToInstanceMap<DOMActionProviderServiceExtension> getExtensions() {
390             return ImmutableClassToInstanceMap.of();
391         }
392
393         @Override
394         public <T extends DOMActionImplementation> ObjectRegistration<T> registerActionImplementation(
395             final T implementation, final Set<DOMActionInstance> instances) {
396
397             synchronized (DOMRpcRouter.this) {
398                 final DOMActionRoutingTable oldTable = actionRoutingTable;
399                 final DOMActionRoutingTable newTable = (DOMActionRoutingTable) oldTable.add(implementation, instances);
400                 actionRoutingTable = newTable;
401
402                 listenerNotifier.execute(() -> notifyActionChanged(newTable, implementation));
403             }
404
405             return new AbstractObjectRegistration<T>(implementation) {
406                 @Override
407                 protected void removeRegistration() {
408                     removeActionImplementation(getInstance(), instances);
409                 }
410             };
411         }
412     }
413
414     private final class RpcServiceFacade implements DOMRpcService {
415         @Override
416         public ListenableFuture<DOMRpcResult> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
417             final AbstractDOMRpcRoutingTableEntry entry = (AbstractDOMRpcRoutingTableEntry) routingTable.getEntry(type);
418             if (entry == null) {
419                 return Futures.immediateFailedFuture(
420                     new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", type));
421             }
422
423             return OperationInvocation.invoke(entry, input);
424         }
425
426         @Override
427         public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T listener) {
428             synchronized (DOMRpcRouter.this) {
429                 final Registration<T> ret = new Registration<>(DOMRpcRouter.this, listener,
430                     routingTable.getOperations(listener));
431                 final Builder<Registration<?>> b = ImmutableList.builder();
432                 b.addAll(listeners);
433                 b.add(ret);
434                 listeners = b.build();
435
436                 listenerNotifier.execute(ret::initialTable);
437                 return ret;
438             }
439         }
440     }
441
442     private final class RpcProviderServiceFacade implements DOMRpcProviderService {
443         @Override
444         public <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(
445             final T implementation, final DOMRpcIdentifier... rpcs) {
446             return registerRpcImplementation(implementation, ImmutableSet.copyOf(rpcs));
447         }
448
449         @Override
450         public <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(
451             final T implementation, final Set<DOMRpcIdentifier> rpcs) {
452
453             synchronized (DOMRpcRouter.this) {
454                 final DOMRpcRoutingTable oldTable = routingTable;
455                 final DOMRpcRoutingTable newTable = (DOMRpcRoutingTable) oldTable.add(implementation, rpcs);
456                 routingTable = newTable;
457
458                 listenerNotifier.execute(() -> notifyAdded(newTable, implementation));
459             }
460
461             return new AbstractDOMRpcImplementationRegistration<T>(implementation) {
462                 @Override
463                 protected void removeRegistration() {
464                     removeRpcImplementation(getInstance(), rpcs);
465                 }
466             };
467         }
468     }
469
470     static final class OperationInvocation {
471         private static final Logger LOG = LoggerFactory.getLogger(OperationInvocation.class);
472
473         static ListenableFuture<? extends DOMActionResult> invoke(final DOMActionRoutingTableEntry entry,
474                 final SchemaPath type, final DOMDataTreeIdentifier path, final ContainerNode input) {
475             return entry.getImplementations(path).get(0).invokeAction(type, path, input);
476         }
477
478         static ListenableFuture<DOMRpcResult> invoke(final AbstractDOMRpcRoutingTableEntry entry,
479                 final NormalizedNode<?, ?> input) {
480             if (entry instanceof UnknownDOMRpcRoutingTableEntry) {
481                 return Futures.immediateFailedFuture(
482                     new DOMRpcImplementationNotAvailableException("SchemaPath %s is not resolved to an RPC",
483                         entry.getType()));
484             } else if (entry instanceof RoutedDOMRpcRoutingTableEntry) {
485                 return invokeRoutedRpc((RoutedDOMRpcRoutingTableEntry) entry, input);
486             } else if (entry instanceof GlobalDOMRpcRoutingTableEntry) {
487                 return invokeGlobalRpc((GlobalDOMRpcRoutingTableEntry) entry, input);
488             }
489
490             return Futures.immediateFailedFuture(
491                 new DOMRpcImplementationNotAvailableException("Unsupported RPC entry."));
492         }
493
494         private static ListenableFuture<DOMRpcResult> invokeRoutedRpc(final RoutedDOMRpcRoutingTableEntry entry,
495                 final NormalizedNode<?, ?> input) {
496             final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input,
497                 entry.getRpcId().getContextReference());
498
499             // Routing key is present, attempt to deliver as a routed RPC
500             if (maybeKey.isPresent()) {
501                 final NormalizedNode<?, ?> key = maybeKey.get();
502                 final Object value = key.getValue();
503                 if (value instanceof YangInstanceIdentifier) {
504                     final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;
505
506                     // Find a DOMRpcImplementation for a specific iid
507                     final List<DOMRpcImplementation> specificImpls = entry.getImplementations(iid);
508                     if (specificImpls != null) {
509                         return specificImpls.get(0)
510                             .invokeRpc(DOMRpcIdentifier.create(entry.getType(), iid), input);
511                     }
512
513                     LOG.debug("No implementation for context {} found will now look for wildcard id", iid);
514
515                     // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
516                     // implementation this way
517                     final List<DOMRpcImplementation> mayBeRemoteImpls =
518                         entry.getImplementations(YangInstanceIdentifier.EMPTY);
519
520                     if (mayBeRemoteImpls != null) {
521                         return mayBeRemoteImpls.get(0)
522                             .invokeRpc(DOMRpcIdentifier.create(entry.getType(), iid), input);
523                     }
524
525                 } else {
526                     LOG.warn("Ignoring wrong context value {}", value);
527                 }
528             }
529
530             final List<DOMRpcImplementation> impls = entry.getImplementations(null);
531             if (impls != null) {
532                 return impls.get(0).invokeRpc(entry.getRpcId(), input);
533             }
534
535             return Futures.immediateFailedFuture(
536                 new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available",
537                     entry.getType()));
538         }
539
540         private static ListenableFuture<DOMRpcResult> invokeGlobalRpc(final GlobalDOMRpcRoutingTableEntry entry,
541                 final NormalizedNode<?, ?> input) {
542             return entry.getImplementations(YangInstanceIdentifier.EMPTY).get(0).invokeRpc(entry.getRpcId(), input);
543         }
544     }
545 }