cirrocumulus 0.1.4 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.3
data/cirrocumulus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cirrocumulus}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anton Kosyakin"]
12
- s.date = %q{2011-09-14}
12
+ s.date = %q{2011-09-16}
13
13
  s.description = %q{Engine for building your own agents, providing you base functionality for loading ontologies, communicating with other agents and parsing FIPA-ACL messages}
14
14
  s.email = %q{deil@mneko.net}
15
15
  s.extra_rdoc_files = [
@@ -45,13 +45,10 @@ class Cirrocumulus
45
45
 
46
46
  def initialize(suffix, generate_jid = true)
47
47
  Log4r::Logger['cirrocumulus'].info 'platform: ' + Cirrocumulus::platform
48
- _, hostname = systemu 'hostname'
49
- hostname.strip!
50
- @jid = generate_jid ? "#{hostname}-#{suffix}" : suffix
51
- Log4r::Logger['cirrocumulus'].info "logging as " + @jid
52
- connect()
48
+ @suffix = suffix
49
+ @generate_jid = generate_jid
53
50
  end
54
-
51
+
55
52
  def send(message)
56
53
  msg = "<fipa-message ontology=\"#{message.ontology}\""
57
54
  msg += " receiver=\"#{message.receiver}\"" if message.receiver
@@ -85,6 +82,17 @@ class Cirrocumulus
85
82
  end
86
83
 
87
84
  def run(agent, kb, sniff = false)
85
+ suffix = agent.default_ontology ? agent.default_ontology.gsub('cirrocumulus-', '') : @suffix
86
+ @jid = if @generate_jid
87
+ _, hostname = systemu 'hostname'
88
+ hostname.strip!
89
+ "%s-%s" % [hostname, suffix]
90
+ else
91
+ suffix
92
+ end
93
+ Log4r::Logger['cirrocumulus'].info "logging as " + @jid
94
+ connect()
95
+
88
96
  Log4r::Logger['cirrocumulus'].info("entering main loop")
89
97
  agent.restore_state()
90
98
 
@@ -155,6 +155,10 @@ module Agent
155
155
  end
156
156
  end
157
157
 
158
+ def default_ontology
159
+ self.ontologies.size == 1 ? self.ontologies.first.name : nil
160
+ end
161
+
158
162
  def handles_ontology?(ontology_name)
159
163
  self.ontologies.any? {|ontology| ontology.name == ontology_name}
160
164
  end
@@ -182,7 +186,7 @@ module Agent
182
186
 
183
187
  def handle_message(message, kb)
184
188
  @network_map.handle_message(message, @cm)
185
- self.ontologies.each {|ontology| ontology.handle_message(message, kb) if message.ontology == ontology.name}
189
+ self.ontologies.each {|ontology| ontology.handle_incoming_message(message, kb) if message.ontology == ontology.name}
186
190
  rescue Exception => e
187
191
  Log4r::Logger['agent'].warn "failed to handle incoming message: %s" % e.to_s
188
192
  puts e.backtrace.to_s
@@ -6,6 +6,8 @@ module Ontology
6
6
  def initialize(name, agent)
7
7
  @name = name
8
8
  @agent = agent
9
+ @sagas = []
10
+ @saga_idx = 0
9
11
  end
10
12
 
11
13
  def restore_state()
@@ -13,14 +15,38 @@ module Ontology
13
15
  end
14
16
 
15
17
  def tick()
18
+ @sagas.each do |saga|
19
+ next if saga.is_finished?
20
+ saga.timeout -= 1 if saga.timeout > 0
21
+ saga.handle(nil) if saga.timeout == 0
22
+ end
23
+
24
+ handle_tick()
16
25
  end
17
26
 
18
- def handle_message(message, kb)
19
- puts "call to dummy Ontology::Base.handle_message()"
27
+ def handle_incoming_message(message, kb)
28
+ was_processed = false
29
+ @sagas.each do |saga|
30
+ next if saga.is_finished?
31
+
32
+ if saga.id == message.in_reply_to
33
+ was_processed = true
34
+ saga.handle(message)
35
+ end
36
+ end
37
+
38
+ handle_message(message, kb) if !was_processed
20
39
  end
21
40
 
22
41
  protected
23
42
 
43
+ def handle_tick()
44
+ end
45
+
46
+ def handle_message(message, kb)
47
+ puts "call to dummy Ontology::Base.handle_message()"
48
+ end
49
+
24
50
  def logger
25
51
  Log4r::Logger['agent']
26
52
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirrocumulus
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anton Kosyakin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-14 00:00:00 +04:00
18
+ date: 2011-09-16 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency