Class DefaultResourceRegistry
java.lang.Object
dev.tachyonmcp.core.server.features.resources.DefaultResourceRegistry
- All Implemented Interfaces:
Resources
Registry for resources, templates, and subscriptions.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultResourceRegistry(ServerEngine server, ResourcesConfig config) Creates a resource registry bound to the given server (for broadcasting subscription notifications). -
Method Summary
Modifier and TypeMethodDescriptionLists registered resource descriptors in ascending name order.Finds a registered resource by name.Finds a registered resource descriptor by URI.findTemplate(String name) Finds a registered resource template by name.booleanisEmpty()Determines whether the registry contains no resources.booleanisSubscribed(String uri, String sessionId) Returns whether the given session is subscribed to the resource URI.Lists registered resources in name order using cursor-based pagination.list(int limit, @Nullable String cursor, Predicate<ResourceDescriptor> filter) voidNotifies all subscribed sessions that a resource has been updated.voidregister(ResourceDescriptor descriptor, ResourceFn fn) Registers a resource descriptor and its handler.registerAsync(ResourceDescriptor descriptor, AsyncResourceFn fn) Registers a resource descriptor with an asynchronous function.registerTemplate(ResourceTemplateDescriptor descriptor, ResourceFn fn) Registers a resource template with its handler.registerTemplateAsync(ResourceTemplateDescriptor descriptor, AsyncResourceFn fn) Registers a resource template with an asynchronous function.Lists registered resource template descriptors in name order.booleanunregister(String name) Removes the resource registered under the specified name.booleanunregisterByUri(String uri) Removes the registered resource with the specified uri.booleanunregisterTemplate(String name) Removes a registered resource template by name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.tachyonmcp.api.server.features.resources.Resources
register, registerAsync, registerTemplate, registerTemplateAsync
-
Constructor Details
-
DefaultResourceRegistry
Creates a resource registry bound to the given server (for broadcasting subscription notifications).
-
-
Method Details
-
onChange
-
register
Registers a resource descriptor and its handler.If resource support is disabled, the descriptor is not registered. Registering a resource with an existing name replaces the previous resource and updates URI mappings accordingly. A URI is unique across resources: registering a URI already owned by a different name is rejected.
- Specified by:
registerin interfaceResources- Parameters:
descriptor- the resource descriptor to registerfn- the resource function- Returns:
- this registry
- Throws:
IllegalArgumentException- if the URI is already registered under a different name
-
registerAsync
Description copied from interface:ResourcesRegisters a resource descriptor with an asynchronous function.- Specified by:
registerAsyncin interfaceResources- Parameters:
descriptor- the resource descriptorfn- the asynchronous resource function- Returns:
- this resource registry for method chaining
-
unregister
Removes the resource registered under the specified name.- Specified by:
unregisterin interfaceResources- Parameters:
name- the resource name- Returns:
trueif a resource was removed,falseif no resource was registered under the name
-
unregisterByUri
Description copied from interface:ResourcesRemoves the registered resource with the specified uri.- Specified by:
unregisterByUriin interfaceResources- Parameters:
uri- resource URI- Returns:
- true if resource was unregistered
-
find
Finds a registered resource by name. -
findByUri
Description copied from interface:ResourcesFinds a registered resource descriptor by URI. -
descriptors
Lists registered resource descriptors in ascending name order.- Specified by:
descriptorsin interfaceResources- Returns:
- the registered resource descriptors
-
list
Lists registered resources in name order using cursor-based pagination.- Parameters:
limit- the maximum number of resources to include; the configured page size is used when this value is not positivecursor- the cursor identifying the starting position, ornullto start from the beginning- Returns:
- the paginated resources and the cursor for the next page
-
list
public PaginatedResult<ResourceDescriptor> list(int limit, @Nullable String cursor, Predicate<ResourceDescriptor> filter) -
registerTemplate
Registers a resource template with its handler.If resource support is disabled, the template is not registered. An exception is thrown when a template with the same name already exists.
- Specified by:
registerTemplatein interfaceResources- Parameters:
descriptor- the resource template descriptorfn- the resource function- Returns:
- this registry
- Throws:
IllegalArgumentException- if a template with the same name is already registered
-
registerTemplateAsync
Description copied from interface:ResourcesRegisters a resource template with an asynchronous function.- Specified by:
registerTemplateAsyncin interfaceResources- Parameters:
descriptor- the resource template descriptor to registerfn- the asynchronous function for the resource template- Returns:
- this resource registry
-
unregisterTemplate
Removes a registered resource template by name.- Specified by:
unregisterTemplatein interfaceResources- Parameters:
name- the name of the template to remove- Returns:
trueif a template was removed,falseotherwise
-
findTemplate
Finds a registered resource template by name.- Specified by:
findTemplatein interfaceResources- Parameters:
name- the template name- Returns:
- the matching resource template descriptor, or an empty optional if no template is registered with that name
-
templateDescriptors
Lists registered resource template descriptors in name order.- Specified by:
templateDescriptorsin interfaceResources- Returns:
- the registered resource template descriptors sorted by name
-
isEmpty
public boolean isEmpty()Determines whether the registry contains no resources.- Returns:
trueif the registry contains no resources,falseotherwise
-
isSubscribed
Returns whether the given session is subscribed to the resource URI. -
notifyResourceUpdated
Notifies all subscribed sessions that a resource has been updated.- Specified by:
notifyResourceUpdatedin interfaceResources- Parameters:
uri- the URI of the resource that changed
-