/**
* ServiceRegistry - Tracks services and their connection states
*
* This is a thin wrapper around GatewayIdentity for now,
* but will be extended with health checking, connection pooling, etc.
*/
export class ServiceRegistry {
constructor(gatewayIdentity) {
this.identity = gatewayIdentity
}
/**
* Register a service
*/
async register(serviceConfig) {
return await this.identity.registerService(serviceConfig)
}
/**
* Lookup service by virtual IP
*/
lookup(virtualIP) {
return this.identity.lookup(virtualIP)
}
/**
* List all services
*/
listServices() {
return this.identity.listServices()
}
/**
* Get service by name
*/
getByName(name) {
return this.identity.getServiceByName(name)
}
/**
* Update connection for a service
*/
updateConnection(virtualIP, connection) {
this.identity.updateConnection(virtualIP, connection)
}
/**
* Remove connection from service
*/
removeConnection(virtualIP, connection) {
this.identity.removeConnection(virtualIP, connection)
}
/**
* Check if service has active connections
*/
isOnline(virtualIP) {
const service = this.lookup(virtualIP)
return service && service.connections.length > 0
}
/**
* Get service stats
*/
getStats() {
const services = this.listServices()
return {
total: services.length,
online: services.filter(s => s.connections.length > 0).length,
offline: services.filter(s => s.connections.length === 0).length,
totalConnections: services.reduce((sum, s) => sum + s.connections.length, 0)
}
}
/**
* Export service mappings
*/
exportMappings() {
return this.identity.exportMappings()
}
}