Sha256: 8f90e662ff56ac67f4e81c35da70bc639489dfa669a4c4c6b7f37f9666e0b301

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

require "norikra/client/version"

require 'msgpack-rpc-over-http'

module Norikra
  class Client
    RPC_DEFAULT_PORT = 26571
    TIMEOUT_OPTIONS = [:connect_timeout, :send_timeout, :receive_timeout]

    def initialize(host='localhost', port=RPC_DEFAULT_PORT, opts={})
      @client = MessagePack::RPCOverHTTP::Client.new("http://#{host}:#{port}/")

      @client.connect_timeout = opts[:connect_timeout] if opts.has_key?(:connect_timeout) && @client.respond_to?('connect_timeout='.to_sym)
      @client.send_timeout    = opts[:send_timeout]    if opts.has_key?(:send_timeout)    && @client.respond_to?('send_timeout='.to_sym)
      @client.receive_timeout = opts[:receive_timeout] if opts.has_key?(:receive_timeout) && @client.respond_to?('receive_timeout='.to_sym)
    end

    def targets
      @client.call(:targets)
    end

    def open(target, fields=nil)
      @client.call(:open, target, fields)
    end

    def close(target)
      @client.call(:close, target)
    end

    def queries
      @client.call(:queries)
    end

    def register(query_name, query_expression)
      @client.call(:register, query_name, query_expression)
    end

    def deregister(query_name)
      @client.call(:deregister, query_name)
    end

    def fields(target)
      @client.call(:fields, target)
    end

    def reserve(target, field, type)
      @client.call(:reserve, target, field, type)
    end

    def send(target, events)
      @client.call(:send, target, events)
    end

    # [ [time, event], ... ]
    def event(query_name)
      @client.call(:event, query_name)
    end

    # {'query_name' => [ [time, event], ... ]}
    def sweep
      @client.call(:sweep)
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
norikra-client-0.0.4 lib/norikra/client.rb
norikra-client-jruby-0.0.3-java lib/norikra/client.rb
norikra-client-0.0.3 lib/norikra/client.rb
norikra-client-jruby-0.0.2-java lib/norikra/client.rb
norikra-client-0.0.2 lib/norikra/client.rb