2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 * Provides a mechanism for applications to do an inline Host Discovery as opposed
11 * to a delayed discovery
13 package org.opendaylight.controller.hosttracker.internal;
16 * This Class provides methods to discover Host through a blocking call
17 * mechanism. Applications can make use of these methods if they don't
18 * find a host in HostTracker's database and want to discover the host
19 * in the same thread without being called by a callback function.
21 import java.util.concurrent.Callable;
22 import java.util.concurrent.CountDownLatch;
24 import org.opendaylight.controller.hosttracker.IHostId;
25 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
31 public class HostTrackerCallable implements Callable<HostNodeConnector> {
33 //host id which could be ip or a combination of ip + mac based on the scheme chosen.
35 HostTracker hostTracker;
36 protected CountDownLatch latch;
38 public HostTrackerCallable(HostTracker tracker, IHostId inet) {
40 hostTracker = tracker;
41 latch = new CountDownLatch(1);
45 public HostNodeConnector call() throws Exception {
46 HostNodeConnector h = hostTracker.hostFind(trackedHost);
49 hostTracker.setCallableOnPendingARP(trackedHost, this);
50 Thread.sleep(2000); // wait 2sec to see if the host responds
51 return hostTracker.hostQuery(trackedHost);
54 public void wakeup() {
55 this.latch.countDown();