blob: 8e8463621cd096244752b30bc9709794c2747daf (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.service.monitor
import com.yahoo.jrt.slobrok.api.Mirror.Entry
import com.yahoo.jrt.slobrok.api.{Mirror, SlobrokList}
import com.yahoo.jrt.{Transport, Supervisor}
import com.yahoo.vespa.service.monitor.SlobrokMonitor._
import scala.collection.convert.wrapAsJava._
/**
* @author bakksjo
*/
class SlobrokMonitor {
private val supervisor: Supervisor = new Supervisor(new Transport())
private val slobrokList = new SlobrokList()
private val mirror = new Mirror(supervisor, slobrokList)
def setSlobrokConnectionSpecs(slobrokConnectionSpecs: Traversable[String]): Unit = {
val slobrokConnectionSpecsJavaList: java.util.List[String] = slobrokConnectionSpecs.toList
slobrokList.setup(slobrokConnectionSpecsJavaList.toArray(new Array[java.lang.String](0)))
}
def getRegisteredServices(): Map[SlobrokServiceName, SlobrokServiceSpec] = {
if (!mirror.ready()) {
return Map()
}
val mirrorEntries: Array[Entry] = mirror.lookup("**")
mirrorEntries.map { mirrorEntry =>
(SlobrokServiceName(mirrorEntry.getName), SlobrokServiceSpec(mirrorEntry.getSpec))
}.toMap
}
def isRegistered(serviceName: SlobrokServiceName): Boolean = {
mirror.lookup(serviceName.s).length != 0
}
def shutdown(): Unit = {
mirror.shutdown()
}
}
object SlobrokMonitor {
case class SlobrokServiceName(s: String)
case class SlobrokServiceSpec(s: String)
}
|