Class: Takagi::Server::Registry

Inherits:
Object
  • Object
show all
Extended by:
Registry::Base
Defined in:
lib/takagi/server/registry.rb

Overview

Registry for CoAP server implementations

Allows registering different protocol implementations (UDP, TCP, DTLS, QUIC, etc.) without modifying core code. Follows the Open/Closed Principle.

Uses Registry::Base for thread-safe storage and consistent API.

Examples:

Registering a server

Takagi::Server::Registry.register(:udp, Server::Udp)
Takagi::Server::Registry.register(:tcp, Server::Tcp)

Building a server

server = Takagi::Server::Registry.build(:tcp, port: 5683, worker_threads: 4)

Adding a custom protocol

class MyCustomServer
  def initialize(port:, **options)
    # ...
  end
end
Takagi::Server::Registry.register(:custom, MyCustomServer)

Defined Under Namespace

Classes: ProtocolNotFoundError

Class Method Summary collapse

Methods included from Registry::Base

[], clear!, count, each, empty?, entries, extended, get, keys, metadata_for, register, registered?, unregister

Class Method Details

.build(protocol, **options) ⇒ Object

Build a server instance for the given protocol

Examples:

server = Registry.build(:tcp, port: 5683, worker_threads: 4)

Parameters:

  • protocol (Symbol)

    Protocol identifier

  • options (Hash)

    Options to pass to server constructor

Returns:

  • (Object)

    Server instance

Raises:



55
56
57
58
59
60
# File 'lib/takagi/server/registry.rb', line 55

def build(protocol, **options)
  klass = get(protocol.to_sym)
  klass.new(**options)
rescue Takagi::Registry::Base::NotFoundError => e
  raise ProtocolNotFoundError, "Unknown protocol: #{protocol}"
end

.protocolsArray<Symbol>

Get all registered protocols

Returns:

  • (Array<Symbol>)

    List of protocol identifiers



65
66
67
# File 'lib/takagi/server/registry.rb', line 65

def protocols
  keys
end

.register(protocol, klass, **metadata) ⇒ Object

Register a server implementation for a protocol

Examples:

Registry.register(:udp, Server::Udp, rfc: 'RFC 7252')
Registry.register(:tcp, Server::Tcp, rfc: 'RFC 8323')

Parameters:

  • protocol (Symbol)

    Protocol identifier (:udp, :tcp, :dtls, etc.)

  • klass (Class)

    Server class that responds to .new

  • metadata (Hash)

    Optional metadata (description, rfc, etc.)



42
43
44
# File 'lib/takagi/server/registry.rb', line 42

def register(protocol, klass, **)
  super(protocol.to_sym, klass, **)
end