Spaces:
Sleeping
Sleeping
Download src/classes/core/ServiceRegistry.ts from lamsaoganh/teamta: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/spaces/lamsaoganh/teamta/resolve/main/src/classes/core/ServiceRegistry.ts
- Command line
-
hf download hf://spaces/lamsaoganh/teamta/src/classes/core/ServiceRegistry.ts
-
curl -L -o ServiceRegistry.ts https://huggingface.co/spaces/lamsaoganh/teamta/resolve/main/src/classes/core/ServiceRegistry.ts
2.45 kB
| /** | |
| * 📝 SERVICE REGISTRY | |
| * | |
| * Central registry để quản lý tất cả services trong Snake worker. | |
| * Implement Registry Pattern để decouple service management khỏi business logic. | |
| * | |
| * Features: | |
| * - Dynamic service registration/unregistration | |
| * - Type-safe service configuration | |
| * - Helper methods để extract services, allocators, typeConfigs | |
| */ | |
| import { IServiceRegistry, IServiceConfig } from '../../interfaces/core/IServiceRegistry'; | |
| export class ServiceRegistry implements IServiceRegistry { | |
| private services: Map<string, IServiceConfig> = new Map(); | |
| /** | |
| * Đăng ký một service mới vào registry | |
| */ | |
| registerService(config: IServiceConfig): void { | |
| if (this.services.has(config.messageType)) { | |
| console.warn(`⚠️ Service ${config.messageType} already registered, overriding...`); | |
| } | |
| this.services.set(config.messageType, config); | |
| console.log(`✅ Registered service: ${config.messageType}`); | |
| } | |
| /** | |
| * Hủy đăng ký một service khỏi registry | |
| */ | |
| unregisterService(messageType: string): void { | |
| if (this.services.has(messageType)) { | |
| this.services.delete(messageType); | |
| console.log(`❌ Unregistered service: ${messageType}`); | |
| } else { | |
| console.warn(`⚠️ Service ${messageType} not found for unregistration`); | |
| } | |
| } | |
| /** | |
| * Lấy service config theo messageType | |
| */ | |
| getService(messageType: string): IServiceConfig | undefined { | |
| return this.services.get(messageType); | |
| } | |
| /** | |
| * Lấy tất cả service configs | |
| */ | |
| getAllServices(): IServiceConfig[] { | |
| return Array.from(this.services.values()); | |
| } | |
| /** | |
| * Lấy typeConfigs cho worker registration với Noah API | |
| */ | |
| getTypeConfigs(): Array<{ messageType: string; min: number; max: number; priority: number; }> { | |
| return this.getAllServices().map(service => service.typeConfig); | |
| } | |
| /** | |
| * Lấy danh sách service instances cho MessageRunner | |
| */ | |
| getServicesArray(): any[] { | |
| return this.getAllServices().map(config => config.service); | |
| } | |
| /** | |
| * Lấy danh sách allocators cho ResourceAllocator | |
| */ | |
| getAllocators(): any[] { | |
| return this.getAllServices().map(config => config.allocator); | |
| } | |
| } |