Package de.craftsblock.craftsnet.api
Class RouteRegistry
java.lang.Object
de.craftsblock.craftsnet.api.RouteRegistry
The RouteRegistry class manages the registration and unregistration of
RequestHandler (routes) and SocketHandler (websockets).
It stores and maps the registered routes and sockets based on their patterns, allowing for efficient handling of incoming requests.- Since:
- 1.0.0-SNAPSHOT
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents the mapping of a registered endpoint handler.static interfaceA universal interface for mappings.static final recordThe ShareMapping class represents the mapping of a registered shared endpoint. -
Constructor Summary
ConstructorsConstructorDescriptionRouteRegistry(CraftsNet craftsNet) Constructs a new instance of the RouteRegistry -
Method Summary
Modifier and TypeMethodDescriptionbooleancanShareAccept(String url, HttpMethod method) Checks if a URL corresponding share is able to accept a specific http method.Retrieves the instance ofCraftsNetbound to the registry.getEndpoints(Class<? extends Server> server) Gets an immutable copy of the registered endpoints for the specific server type in the registry.Gets the route mappings associated with a specific request information.Gets an immutable copy of the registered routes in the registry.ConcurrentHashMap<Class<? extends Server>,ConcurrentHashMap<Pattern, ConcurrentLinkedQueue<RouteRegistry.EndpointMapping>>> Retrieves all registered server mappings.Gets the mapping for the share associated with the given URL.getShareFolder(String url) Gets the shared folder associated with the given URL.getSharePattern(String url) Gets the pattern associated with the shared folder that matches the given URL.Returns an immutable copy of the shared folders and patterns.getSocket(WebSocketClient client) Gets the socket mapping associated with a specific URL and domain.Gets an immutable copy of the registered socket handlers in the registry.booleanhasRouteMappings(Request request) Checks if there are any registered route mappings for a givenRequest.booleanChecks if the registry has any registered route handlers or shares.booleanChecks if the registry has any registered shares.booleanhasSocketMappings(WebSocketClient client) Checks if there are any registered websocket mappings for a givenWebSocketClient.booleanChecks if the registry has any registered socket handlers.booleanisRegistered(Handler handler) Checks if the givenHandleris registered.booleanisRegistered(Class<? extends Handler> type) Checks if the given class representation of theHandleris registered.booleanChecks if a URL corresponds to a shared folder by verifying if both a shared folder and its pattern exist for the URL.voidRegisters an endpoint handler (RequestHandlerand orSocketHandler) by inspecting its annotated methods and adding it to the registry.voidShares a folder for a specified path.voidShares a folder for a specified path.voidShares a folder for a specified path.voidShares a folder for a specified path.voidunregister(Handler handler) Unregisters an endpoint handler (route or websocket) from the registry.
-
Constructor Details
-
RouteRegistry
Constructs a new instance of the RouteRegistry- Parameters:
craftsNet- The CraftsNet instance which instantiates this route registry
-
-
Method Details
-
register
Registers an endpoint handler (RequestHandlerand orSocketHandler) by inspecting its annotated methods and adding it to the registry.- Parameters:
handler- The Handler to be registered.
-
isRegistered
Checks if the givenHandleris registered. This class is a wrapper forisRegistered(Class). -
isRegistered
Checks if the given class representation of theHandleris registered. -
unregister
Unregisters an endpoint handler (route or websocket) from the registry.- Parameters:
handler- The RequestHandler to be unregistered.
-
getRoutes
@NotNull public @NotNull Map<Pattern,ConcurrentLinkedQueue<RouteRegistry.EndpointMapping>> getRoutes()Gets an immutable copy of the registered routes in the registry.- Returns:
- A ConcurrentHashMap containing the registered routes.
-
getRoute
@Nullable public @Nullable EnumMap<ProcessPriority.Priority,List<RouteRegistry.EndpointMapping>> getRoute(Request request) Gets the route mappings associated with a specific request information.- Parameters:
request- The http request for which a routes should be found.- Returns:
- A list of RouteMapping objects associated with the URL and HTTP method, or null if no mappings are found.
-
hasRouteMappings
Checks if there are any registered route mappings for a givenRequest.- Parameters:
request- TheRequestto check.- Returns:
trueif a route mapping exists, otherwisefalse.- Since:
- 3.3.3-SNAPSHOT
-
getSockets
@NotNull public @NotNull Map<Pattern,ConcurrentLinkedQueue<RouteRegistry.EndpointMapping>> getSockets()Gets an immutable copy of the registered socket handlers in the registry.- Returns:
- A ConcurrentHashMap containing the registered socket handlers.
-
getSocket
@Nullable public @Nullable EnumMap<ProcessPriority.Priority,List<RouteRegistry.EndpointMapping>> getSocket(WebSocketClient client) Gets the socket mapping associated with a specific URL and domain.- Parameters:
client- The client for which the socket mapping is sought.- Returns:
- A list of SocketMapping objects associated with the URL, or null if no mapping is found.
-
hasSocketMappings
Checks if there are any registered websocket mappings for a givenWebSocketClient.- Parameters:
client- TheWebSocketClientto check.- Returns:
trueif a websocket mapping exists, otherwisefalse.- Since:
- 3.3.3-SNAPSHOT
-
getEndpoints
@NotNull public @NotNull Map<Pattern,ConcurrentLinkedQueue<RouteRegistry.EndpointMapping>> getEndpoints(Class<? extends Server> server) Gets an immutable copy of the registered endpoints for the specific server type in the registry.- Parameters:
server- TheServerfrom which the endpoints should be loaded.- Returns:
- A
ConcurrentHashMapcontaining the registered endpoints. - Since:
- 3.3.3-SNAPSHOT
-
hasWebsockets
public boolean hasWebsockets()Checks if the registry has any registered socket handlers.- Returns:
- true if the registry has registered socket handlers, false otherwise.
-
hasRoutes
public boolean hasRoutes()Checks if the registry has any registered route handlers or shares.- Returns:
- true if the registry has registered route handlers or shares, false otherwise.
-
getServerMappings
@Internal public ConcurrentHashMap<Class<? extends Server>,ConcurrentHashMap<Pattern, getServerMappings()ConcurrentLinkedQueue<RouteRegistry.EndpointMapping>>> Retrieves all registered server mappings.- Returns:
- A map which contains all registered endpoint mappings sorted per server.
- Since:
- 3.2.1-SNAPSHOT
-
getCraftsNet
Retrieves the instance ofCraftsNetbound to the registry.- Returns:
- The instance of
CraftsNetbound to the registry. - Since:
- 3.2.1-SNAPSHOT
-