Class: Qswarm::Agent

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/qswarm/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger, logger

Constructor Details

#initialize(swarm, name, args, &block) ⇒ Agent

Returns a new instance of Agent.



10
11
12
13
14
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
# File 'lib/qswarm/agent.rb', line 10

def initialize(swarm, name, args, &block)
  @swarm              = swarm
  @name               = name.to_s
  @brokers            = {}
  @listeners          = []
  @args               = args

  unless args.nil?
    case args.delete :type
    when :esper
      require 'java'

      require 'esper-4.5.0/esper-4.5.0.jar'
      require 'esper-4.5.0/esper/lib/commons-logging-1.1.1.jar'
      require 'esper-4.5.0/esper/lib/antlr-runtime-3.2.jar'
      require 'esper-4.5.0/esper/lib/cglib-nodep-2.2.jar'
      require 'esper-4.5.0/esper/lib/log4j-1.2.16.jar'

      include_class 'com.espertech.esper.client.EPRuntime'
      include_class 'com.espertech.esper.client.EPServiceProviderManager'
      include_class 'com.espertech.esper.client.EPServiceProvider'
      include_class 'com.espertech.esper.client.EPStatement'

      include_class 'com.espertech.esper.client.UpdateListener'
      include_class 'com.espertech.esper.client.EventBean'
      include_class 'org.apache.commons.logging.Log'
      include_class 'org.apache.commons.logging.LogFactory'
    end
  end

  self.instance_eval(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/qswarm/agent.rb', line 8

def name
  @name
end

#swarmObject (readonly)

Returns the value of attribute swarm.



8
9
10
# File 'lib/qswarm/agent.rb', line 8

def swarm
  @swarm
end

Instance Method Details

#bindObject



57
58
59
# File 'lib/qswarm/agent.rb', line 57

def bind
  logger.info "Binding to exchange"
end

#broker(name, &block) ⇒ Object



48
49
50
51
# File 'lib/qswarm/agent.rb', line 48

def broker(name, &block)
  logger.info "Registering broker: #{name}"
  @brokers[name] = Qswarm::Broker.new(name, &block)
end

#get_broker(name) ⇒ Object



53
54
55
# File 'lib/qswarm/agent.rb', line 53

def get_broker(name)
  @brokers[name] || @swarm.get_broker(name)
end

#listen(name, args = nil, &block) ⇒ Object



43
44
45
46
# File 'lib/qswarm/agent.rb', line 43

def listen(name, args = nil, &block)
  logger.info "Registering listener: #{name}"
  @listeners << Qswarm::Listener.new(self, name, args, &block)
end

#runObject



61
62
63
# File 'lib/qswarm/agent.rb', line 61

def run
  @listeners.map { |l| l.run }
end