Class: Rox::Server::RoxServer

Inherits:
Object
  • Object
show all
Defined in:
lib/rox/server/rox_server.rb

Class Method Summary collapse

Class Method Details

.add_custom_properties(property_factory) ⇒ Object



49
50
51
52
53
# File 'lib/rox/server/rox_server.rb', line 49

def add_custom_properties(property_factory)
  property_factory.all_properties.each do |property|
    @core.add_custom_property_if_not_exists(property)
  end
end

.context=(context) ⇒ Object



67
68
69
# File 'lib/rox/server/rox_server.rb', line 67

def context=(context)
  @core.context = context
end

.dump_stateObject



117
118
119
# File 'lib/rox/server/rox_server.rb', line 117

def dump_state
  @core.dump_state
end

.dynamic_apiObject



113
114
115
# File 'lib/rox/server/rox_server.rb', line 113

def dynamic_api
  @core.dynamic_api(Rox::Server::ServerEntitiesProvider.new)
end

.fetchObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/rox/server/rox_server.rb', line 71

def fetch
  Thread.new do
    Thread.current.report_on_exception = false if Thread.current.respond_to?(:report_on_exception)
    begin
      @core.fetch.join
    rescue StandardError => e
      Rox::Core::Logging.logger.error('Failed in Rox.fetch', e)
    end
  end
end

.register(rox_container) ⇒ Object



55
56
57
# File 'lib/rox/server/rox_server.rb', line 55

def register(rox_container)
  @core.register(rox_container)
end

.register_with_namespace(namespace, rox_container) ⇒ Object



59
60
61
# File 'lib/rox/server/rox_server.rb', line 59

def register_with_namespace(namespace, rox_container)
  @core.register_with_namespace(namespace, rox_container)
end

.set_custom_boolean_property(name, value = nil, &block) ⇒ Object



87
88
89
90
# File 'lib/rox/server/rox_server.rb', line 87

def set_custom_boolean_property(name, value = nil, &block)
  @core.add_custom_property(Rox::Core::CustomProperty.new(name, Rox::Core::CustomPropertyType::BOOL, value,
                                                          &block))
end

.set_custom_datetime_property(name, value = nil, &block) ⇒ Object



107
108
109
110
111
# File 'lib/rox/server/rox_server.rb', line 107

def set_custom_datetime_property(name, value = nil, &block)
  @core.add_custom_property(
    Rox::Core::CustomProperty.new(name, Rox::Core::CustomPropertyType::DATETIME, value, &block)
  )
end

.set_custom_float_property(name, value = nil, &block) ⇒ Object



97
98
99
100
# File 'lib/rox/server/rox_server.rb', line 97

def set_custom_float_property(name, value = nil, &block)
  @core.add_custom_property(Rox::Core::CustomProperty.new(name, Rox::Core::CustomPropertyType::FLOAT, value,
                                                          &block))
end

.set_custom_int_property(name, value = nil, &block) ⇒ Object



92
93
94
95
# File 'lib/rox/server/rox_server.rb', line 92

def set_custom_int_property(name, value = nil, &block)
  @core.add_custom_property(Rox::Core::CustomProperty.new(name, Rox::Core::CustomPropertyType::INT, value,
                                                          &block))
end

.set_custom_semver_property(name, value = nil, &block) ⇒ Object



102
103
104
105
# File 'lib/rox/server/rox_server.rb', line 102

def set_custom_semver_property(name, value = nil, &block)
  @core.add_custom_property(Rox::Core::CustomProperty.new(name, Rox::Core::CustomPropertyType::SEMVER, value,
                                                          &block))
end

.set_custom_string_property(name, value = nil, &block) ⇒ Object



82
83
84
85
# File 'lib/rox/server/rox_server.rb', line 82

def set_custom_string_property(name, value = nil, &block)
  @core.add_custom_property(Rox::Core::CustomProperty.new(name, Rox::Core::CustomPropertyType::STRING, value,
                                                          &block))
end

.setup(api_key, rox_options = nil) ⇒ Object



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
# File 'lib/rox/server/rox_server.rb', line 16

def setup(api_key, rox_options = nil)
  # @core.setup calls validate_api_key internally anyway, but it will happen in another thread
  # because of the report_on_exception code below (which might effect older [maybe not supported Ruby versions])
  # decided to call it explicity here too (to keep the current behavor)
  # anyway, this also short circuit the initialization (no need for the initialization and Thread.new)
  # and only costs us calling the validation twice instead of once
  @core.validate_api_key(api_key)

  rox_options = if rox_options.nil?
                  Rox::Server::RoxOptions.new(disable_signature_verification: @core.is_cbp?(api_key))
                else
                  rox_options = rox_options.clone_with_options({
                    disable_signature_verification: @core.is_cbp?(api_key) || rox_options.disable_signature_verification
                  })
                end
  sdk_settings = Rox::Server::SdkSettings.new(api_key, rox_options.dev_mode_key)
  server_properties = Rox::Server::ServerProperties.new(sdk_settings, rox_options)

  RoxServer.add_custom_properties(Rox::Core::PropertyFactory.new(server_properties))

  @@thread = Thread.new do
    Thread.current.report_on_exception = false if Thread.current.respond_to?(:report_on_exception)
    @core.setup(sdk_settings, server_properties).join
  end
end

.shutdownObject



42
43
44
45
46
47
# File 'lib/rox/server/rox_server.rb', line 42

def shutdown
  return if !defined?(@@thread) || @@thread.nil?

  Thread.kill(@@thread)
  @core.shutdown
end

.use_userspace_unhandled_error_handler(&handler) ⇒ Object



63
64
65
# File 'lib/rox/server/rox_server.rb', line 63

def use_userspace_unhandled_error_handler(&handler)
  @core.userspace_unhandled_error_handler = handler
end