blob: 2962fd3a3ec15b05e6a3ef703a1588f8ab0c05c8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package com.yahoo.search.dispatch;
import ai.vespa.cloud.SystemInfo;
import com.yahoo.component.ComponentId;
import com.yahoo.component.annotation.Inject;
import com.yahoo.config.subscription.ConfigSubscriber;
import com.yahoo.container.QrConfig;
import com.yahoo.container.handler.VipStatus;
import com.yahoo.vespa.config.search.DispatchConfig;
import com.yahoo.vespa.config.search.DispatchNodesConfig;
import com.yahoo.yolean.UncheckedInterruptedException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
* @author jonmv
*/
public class ReconfigurableDispatcher extends Dispatcher {
private final ConfigSubscriber subscriber;
@Inject
public ReconfigurableDispatcher(ComponentId clusterId, DispatchConfig dispatchConfig, SystemInfo systemInfo, VipStatus vipStatus) {
super(clusterId, dispatchConfig, new DispatchNodesConfig.Builder().build(), vipStatus);
this.subscriber = new ConfigSubscriber();
CountDownLatch configured = new CountDownLatch(1);
this.subscriber.subscribe(config -> { updateWithNewConfig(config); configured.countDown(); },
DispatchNodesConfig.class, configId(clusterId, systemInfo));
try {
if ( ! configured.await(1, TimeUnit.MINUTES))
throw new IllegalStateException("timed out waiting for initial dispatch nodes config for " + clusterId.getName());
}
catch (InterruptedException e) {
throw new UncheckedInterruptedException("interrupted waiting for initial dispatch nodes config for " + clusterId.getName(), e);
}
}
@Override
public void deconstruct() {
subscriber.close();
super.deconstruct();
}
private static String configId(ComponentId clusterId, SystemInfo systemInfo) {
return systemInfo.clusterName() + "/component/" + clusterId.getName();
}
}
|