Class: ConfigResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb

Class Method Summary collapse

Class Method Details

.build_connection_data(host_value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/javonet-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 15

def self.build_connection_data(host_value)
  if host_value.nil? || host_value.strip.empty?
    return nil  # In-memory connection
  end
  hv = host_value.strip
  lower = hv.downcase

  if lower == "inmemory" || lower == "in-memory"
    return nil  # In-memory connection
  end

  if lower.start_with?("ws://") || lower.start_with?("wss://")
    return WsConnectionData.new(hv)
  end

  if lower.start_with?("tcp://")
    begin
      return ConfigResolver.parse_tcp(hv[6..-1])
    rescue
      return nil  # In-memory connection
    end
  end

  colon = hv.index(":")
  if colon && colon > 0 && colon < hv.length - 1
    port_part = hv[colon + 1..-1]
    slash = port_part.index("/")
    if slash && slash >= 0
      port_part = port_part[0...slash]
    end
    begin
      port = Integer(port_part)
      host_only = hv[0...colon]
      if !host_only.strip.empty?
        begin
          return TcpConnectionData.new(host_only, port)
        rescue
          return nil  # In-memory connection
        end
      end
    rescue
      # Continue to return in-memory
    end
  end

  nil  # In-memory connection
end

.parse_tcp(address) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/javonet-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 63

def self.parse_tcp(address)
  slash = address.index("/")
  host_port = slash && slash >= 0 ? address[0...slash] : address
  colon = host_port.rindex(":")
  if !colon || colon <= 0 || colon >= host_port.length - 1
    raise "Invalid tcp:// format."
  end
  host = host_port[0...colon]
  port_str = host_port[colon + 1..-1]
  begin
    port = Integer(port_str)
  rescue
    raise "Invalid port in tcp:// address."
  end
  TcpConnectionData.new(host, port)
end

.try_parse_runtime(runtime) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/javonet-ruby-sdk/sdk/configuration/config_resolvers/config_resolver.rb', line 7

def self.try_parse_runtime(runtime)
  if runtime.nil? || runtime.strip.empty?
    raise "Runtime string cannot be null or whitespace."
  end
  runtime = runtime.strip.downcase
  RuntimeNameHandler.get_runtime(runtime)
end