ing
This commit is contained in:
parent
9589b92095
commit
348cb63eac
|
@ -15,7 +15,9 @@ var RPCServlet rpc.Servlet
|
||||||
var discoverer *discovery
|
var discoverer *discovery
|
||||||
|
|
||||||
func DiscoveryInit() {
|
func DiscoveryInit() {
|
||||||
discoverer = &discovery{}
|
discoverer = &discovery{
|
||||||
|
_isRunning: false,
|
||||||
|
}
|
||||||
discoverer.start()
|
discoverer.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,19 +27,45 @@ func DiscoveryDestroy() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiscoverZone(probeService *oopcs.ProbeService, requesterID string, dz *discoveryM.DiscoveryZone) {
|
func DiscoverZone(probeService *oopcs.ProbeService, requesterID string, dz *discoveryM.DiscoveryZone) {
|
||||||
|
if !discoverer.canRunOrNot() {
|
||||||
|
logging.Logger().Warnf("Discovery: Discovery is running already")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
discoverer.discoverZone(probeService, requesterID, dz)
|
discoverer.discoverZone(probeService, requesterID, dz)
|
||||||
|
|
||||||
|
discoverer.stopWg.Wait()
|
||||||
|
discoverer.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiscoverHost(probeService *oopcs.ProbeService, requesterID string, zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) {
|
func DiscoverHost(probeService *oopcs.ProbeService, requesterID string, zone *discoveryM.Zone, dh *discoveryM.DiscoveryHost) {
|
||||||
|
if !discoverer.canRunOrNot() {
|
||||||
|
logging.Logger().Warnf("Discovery: Discovery is running already")
|
||||||
|
return
|
||||||
|
}
|
||||||
discoverer.discoverHost(probeService, requesterID, zone, dh)
|
discoverer.discoverHost(probeService, requesterID, zone, dh)
|
||||||
|
discoverer.stopWg.Wait()
|
||||||
|
discoverer.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiscoverPort(probeService *oopcs.ProbeService, requesterID string, host *discoveryM.Host, dp *discoveryM.DiscoveryPort) {
|
func DiscoverPort(probeService *oopcs.ProbeService, requesterID string, host *discoveryM.Host, dp *discoveryM.DiscoveryPort) {
|
||||||
|
if !discoverer.canRunOrNot() {
|
||||||
|
logging.Logger().Warnf("Discovery: Discovery is running already")
|
||||||
|
return
|
||||||
|
}
|
||||||
discoverer.discoverPort(probeService, requesterID, host, dp)
|
discoverer.discoverPort(probeService, requesterID, host, dp)
|
||||||
|
discoverer.stopWg.Wait()
|
||||||
|
discoverer.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiscoverService(probeService *oopcs.ProbeService, requesterID string, port *discoveryM.Port, ds *discoveryM.DiscoveryService) {
|
func DiscoverService(probeService *oopcs.ProbeService, requesterID string, port *discoveryM.Port, ds *discoveryM.DiscoveryService) {
|
||||||
|
if !discoverer.canRunOrNot() {
|
||||||
|
logging.Logger().Warnf("Discovery: Discovery is running already")
|
||||||
|
return
|
||||||
|
}
|
||||||
discoverer.discoverService(probeService, requesterID, port, ds)
|
discoverer.discoverService(probeService, requesterID, port, ds)
|
||||||
|
discoverer.stopWg.Wait()
|
||||||
|
discoverer.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Stop() {
|
func Stop() {
|
||||||
|
@ -50,6 +78,28 @@ type discovery struct {
|
||||||
|
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
stopWg sync.WaitGroup
|
stopWg sync.WaitGroup
|
||||||
|
|
||||||
|
_isRunning bool
|
||||||
|
_statusMtx sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *discovery) canRunOrNot() bool {
|
||||||
|
d._statusMtx.Lock()
|
||||||
|
defer d._statusMtx.Unlock()
|
||||||
|
|
||||||
|
if d._isRunning {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
d._isRunning = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *discovery) complete() {
|
||||||
|
d._statusMtx.Lock()
|
||||||
|
defer d._statusMtx.Unlock()
|
||||||
|
|
||||||
|
d._isRunning = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *discovery) start() {
|
func (d *discovery) start() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user