Class: Droonga::WatchHandler

Inherits:
HandlerPlugin show all
Defined in:
lib/droonga/plugin/handler/watch.rb

Instance Method Summary collapse

Methods inherited from HandlerPlugin

#emit, #envelope, #post, #prefer_synchronous?

Methods included from PluginRegisterable

#command, extended, #inherited, #method_name, #processable?, #repository

Methods inherited from Plugin

#process, #processable?, #shutdown, #start

Constructor Details

#initialize(*args) ⇒ WatchHandler

Returns a new instance of WatchHandler.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/droonga/plugin/handler/watch.rb', line 27

def initialize(*args)
  super

  # XXX just workaround. This must be re-written.
  # When secondary and later processes opens the database,
  # creation processes of tables by the first process is
  # not finished yet. Then secondary and others tries to
  # create tables and raises errors. To avoid such a problem,
  # the creation processes of tables is disabled on workers.
  if $0 !~ /\AServer/
    ensure_schema_created
  else
    until @context["Keyword"]
      sleep 0.1
    end
    sleep 1
  end

  @watcher = Watcher.new(@context)
  @sweeper = Sweeper.new(@context)
end

Instance Method Details

#feed(request) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/droonga/plugin/handler/watch.rb', line 75

def feed(request)
  @watcher.feed(:targets => request["targets"]) do |route, subscribers|
    message = request # return request itself
    envelope["to"] = subscribers
    post(message, "to" => route, "type" => "watch.notification")
  end
end

#subscribe(request) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/droonga/plugin/handler/watch.rb', line 50

def subscribe(request)
  subscriber, condition, query, route = parse_request(request)
  normalized_request = {
    :subscriber => subscriber,
    :condition  => condition,
    :query      => query,
    :route      => route,
  }
  @watcher.subscribe(normalized_request)
  emit([true])
end

#sweep(request) ⇒ Object



84
85
86
# File 'lib/droonga/plugin/handler/watch.rb', line 84

def sweep(request)
  @sweeper.sweep_expired_subscribers
end

#unsubscribe(request) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/droonga/plugin/handler/watch.rb', line 63

def unsubscribe(request)
  subscriber, condition, query, route = parse_request(request)
  normalized_request = {
    :subscriber => subscriber,
    :condition  => condition,
    :query      => query,
  }
  @watcher.unsubscribe(normalized_request)
  emit([true])
end