Class: UpdateProcessor

Inherits:
Closeable show all
Defined in:
lib/ff/ruby/server/sdk/api/update_processor.rb

Instance Method Summary collapse

Instance Method Details

#closeObject



76
77
78
79
80
81
# File 'lib/ff/ruby/server/sdk/api/update_processor.rb', line 76

def close

  @logger.info "Closing UpdateProcessor"

  stop
end

#init(connector, repository, callback, logger) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ff/ruby/server/sdk/api/update_processor.rb', line 7

def init(

  connector,
  repository,
  callback,
  logger
)

  @connector = connector
  @repository = repository
  @updater = callback
  @executor = Concurrent::FixedThreadPool.new(20)

  if logger != nil

    @logger = logger
  else

    @logger = Logger.new(STDOUT)
  end
end

#startObject



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
# File 'lib/ff/ruby/server/sdk/api/update_processor.rb', line 29

def start

  @logger.debug "Starting updater (EventSource)"

  if @updater != nil

    unless @updater.kind_of?(Updater)

      raise "The 'callback' parameter must be of '" + Updater.to_s + "' data type"
    end
  end

  if @connector != nil

    unless @connector.kind_of?(Connector)

      raise "The 'connector' must be of '" + Connector.to_s + "' data type"
    end

    @executor.post do

      @stream = @connector.stream(@updater)
      @stream.start
    end
  end
end

#stopObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ff/ruby/server/sdk/api/update_processor.rb', line 56

def stop

  @logger.info "Stopping updater (EventSource)"

  if @stream != nil

    @stream.stop
  end

  @executor.shutdown
  @executor.wait_for_termination(3)

  if @executor.shuttingdown?

    @executor.kill
  end

  @logger.info "Updater stopped (EventSource)"
end

#update(message) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ff/ruby/server/sdk/api/update_processor.rb', line 83

def update(message)

  if message["domain"] == "flag"

    @executor.post do

      process_flag(message)
    end

    return
  end

  if message["domain"] == "target-segment"

    @executor.post do

      process_segment(message)
    end
  end
end