Class WebSocketExtensionRegistry

java.lang.Object
de.craftsblock.craftsnet.api.websocket.extensions.WebSocketExtensionRegistry

public class WebSocketExtensionRegistry extends Object
Registry for managing WebSocket extensions. This class allows for the registration, unregistration, and lookup of WebSocket extensions by their protocol names. It is designed to be thread-safe, using a concurrent hash map to store the extensions.
Since:
3.0.6-SNAPSHOT
  • Constructor Details

    • WebSocketExtensionRegistry

      public WebSocketExtensionRegistry()
      Constructs a new WebSocket extension registry and registers the default extensions.
  • Method Details

    • register

      public void register(WebSocketExtension extension)
      Registers a new WebSocket extension. If an extension with the same protocol name already exists, it will be replaced.
      Parameters:
      extension - the WebSocket extension to be registered. Must not be null.
    • unregister

      public void unregister(WebSocketExtension extension)
      Unregisters a WebSocket extension by its instance. This method calls unregister(String) with the protocol name of the given extension.
      Parameters:
      extension - the WebSocket extension to be unregistered. Must not be null.
    • unregister

      public void unregister(String protocolName)
      Unregisters a WebSocket extension by its protocol name. If no extension with the given protocol name is registered, this method does nothing.
      Parameters:
      protocolName - the protocol name of the WebSocket extension to be unregistered. Must not be null.
    • hasExtension

      public boolean hasExtension(WebSocketExtension extension)
      Checks if a WebSocket extension is registered by its instance. This method calls hasExtension(String) with the protocol name of the given extension.
      Parameters:
      extension - the WebSocket extension to check. Must not be null.
      Returns:
      true if the extension is registered, false otherwise.
    • hasExtension

      public boolean hasExtension(String protocolName)
      Checks if a WebSocket extension is registered by its protocol name.
      Parameters:
      protocolName - the protocol name of the WebSocket extension to check. Must not be null.
      Returns:
      true if the extension is registered, false otherwise.
    • getExtensionByName

      public WebSocketExtension getExtensionByName(String protocolName)
      Retrieves a WebSocket extension by its protocol name.
      Parameters:
      protocolName - the protocol name of the WebSocket extension to retrieve. Must not be null.
      Returns:
      the WebSocket extension associated with the given protocol name, or null if no such extension is registered.
    • getExtensions

      public ConcurrentLinkedQueue<WebSocketExtension> getExtensions()
      Retrieves all registered WebSocket extensions.
      Returns:
      a concurrent linked queue containing all registered WebSocket extensions.