cirrocumulus 0.6.3 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -22
- data/lib/cirrocumulus.rb +8 -2
- data/lib/cirrocumulus/{message.rb → agents/message.rb} +0 -0
- data/lib/cirrocumulus/channels.rb +129 -0
- data/lib/cirrocumulus/channels/jabber.rb +168 -0
- data/lib/cirrocumulus/environment.rb +46 -0
- data/lib/cirrocumulus/facts.rb +135 -0
- data/lib/cirrocumulus/identifier.rb +84 -0
- data/lib/cirrocumulus/ontology.rb +333 -49
- data/lib/cirrocumulus/pattern_matching.rb +175 -0
- data/lib/cirrocumulus/remote_console.rb +29 -0
- data/lib/cirrocumulus/rule_queue.rb +69 -0
- data/lib/cirrocumulus/rules/engine.rb +7 -5
- data/lib/cirrocumulus/rules/fact.rb +22 -0
- data/lib/cirrocumulus/rules/pattern_matcher.rb +19 -0
- data/lib/cirrocumulus/rules/run_queue.rb +1 -0
- data/lib/cirrocumulus/saga.rb +44 -25
- data/lib/console.rb +96 -0
- metadata +79 -72
- data/.document +0 -5
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/cirrocumulus.iml +0 -87
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.idea/workspace.xml +0 -614
- data/Gemfile +0 -18
- data/Gemfile.lock +0 -43
- data/Rakefile +0 -37
- data/VERSION +0 -1
- data/cirrocumulus.gemspec +0 -106
- data/lib/.gitignore +0 -5
- data/lib/cirrocumulus/agent_wrapper.rb +0 -67
- data/lib/cirrocumulus/jabber_bus.rb +0 -140
- data/lib/cirrocumulus/rule_engine.rb +0 -2
- data/lib/cirrocumulus/rule_server.rb +0 -49
- data/test/Gemfile +0 -3
- data/test/Gemfile.lock +0 -27
- data/test/helper.rb +0 -18
- data/test/test.rb +0 -85
- data/test/test2.rb +0 -30
- data/test/test_cirrocumulus.rb +0 -7
data/Gemfile
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem "activesupport", "~> 2.3.11"
|
4
|
-
gem "log4r", "~> 1.1.9"
|
5
|
-
gem "systemu"
|
6
|
-
gem "xmpp4r", "~> 0.5"
|
7
|
-
gem "xmpp4r-simple", :git => 'git://github.com/blaine/xmpp4r-simple.git'
|
8
|
-
gem "eventmachine"
|
9
|
-
gem "deil_sexpistol", :require => "sexpistol"
|
10
|
-
gem 'guid'
|
11
|
-
|
12
|
-
group :development do
|
13
|
-
#gem "shoulda", ">= 0"
|
14
|
-
gem "rdoc", "~> 3.12"
|
15
|
-
gem "bundler", "~> 1.0.0"
|
16
|
-
gem "jeweler", "~> 1.8.3"
|
17
|
-
#gem "simplecov", ">= 0"
|
18
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/blaine/xmpp4r-simple.git
|
3
|
-
revision: 92e2cd0002ec3a9a38506527e1a3a2d622408626
|
4
|
-
specs:
|
5
|
-
xmpp4r-simple (0.8.8)
|
6
|
-
xmpp4r (>= 0.3.2)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activesupport (2.3.14)
|
12
|
-
deil_sexpistol (0.0.8)
|
13
|
-
eventmachine (0.12.10)
|
14
|
-
git (1.2.5)
|
15
|
-
guid (0.1.1)
|
16
|
-
jeweler (1.8.3)
|
17
|
-
bundler (~> 1.0)
|
18
|
-
git (>= 1.2.5)
|
19
|
-
rake
|
20
|
-
rdoc
|
21
|
-
json (1.6.5)
|
22
|
-
log4r (1.1.10)
|
23
|
-
rake (0.9.2.2)
|
24
|
-
rdoc (3.12)
|
25
|
-
json (~> 1.4)
|
26
|
-
systemu (2.4.2)
|
27
|
-
xmpp4r (0.5)
|
28
|
-
|
29
|
-
PLATFORMS
|
30
|
-
ruby
|
31
|
-
|
32
|
-
DEPENDENCIES
|
33
|
-
activesupport (~> 2.3.11)
|
34
|
-
bundler (~> 1.0.0)
|
35
|
-
deil_sexpistol
|
36
|
-
eventmachine
|
37
|
-
guid
|
38
|
-
jeweler (~> 1.8.3)
|
39
|
-
log4r (~> 1.1.9)
|
40
|
-
rdoc (~> 3.12)
|
41
|
-
systemu
|
42
|
-
xmpp4r (~> 0.5)
|
43
|
-
xmpp4r-simple!
|
data/Rakefile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "cirrocumulus"
|
18
|
-
gem.homepage = "http://github.com/deil/cirrocumulus"
|
19
|
-
gem.license = "GPL-2"
|
20
|
-
gem.summary = "Agent-based infrastructure management system"
|
21
|
-
gem.description = "Engine for building your own agents, providing you base functionality for loading ontologies, communicating with other agents and parsing FIPA-ACL messages"
|
22
|
-
gem.email = "deil@mneko.net"
|
23
|
-
gem.authors = ["Anton Kosyakin"]
|
24
|
-
gem.required_ruby_version = '>= 1.9.2'
|
25
|
-
# dependencies defined in Gemfile
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rdoc/task'
|
30
|
-
Rake::RDocTask.new do |rdoc|
|
31
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
-
|
33
|
-
rdoc.rdoc_dir = 'rdoc'
|
34
|
-
rdoc.title = "cirrocumulus #{version}"
|
35
|
-
rdoc.rdoc_files.include('README*')
|
36
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.6.3
|
data/cirrocumulus.gemspec
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = "cirrocumulus"
|
8
|
-
s.version = "0.6.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Anton Kosyakin"]
|
12
|
-
s.date = "2012-05-23"
|
13
|
-
s.description = "Engine for building your own agents, providing you base functionality for loading ontologies, communicating with other agents and parsing FIPA-ACL messages"
|
14
|
-
s.email = "deil@mneko.net"
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".idea/.name",
|
22
|
-
".idea/.rakeTasks",
|
23
|
-
".idea/cirrocumulus.iml",
|
24
|
-
".idea/encodings.xml",
|
25
|
-
".idea/misc.xml",
|
26
|
-
".idea/modules.xml",
|
27
|
-
".idea/scopes/scope_settings.xml",
|
28
|
-
".idea/vcs.xml",
|
29
|
-
".idea/workspace.xml",
|
30
|
-
"Gemfile",
|
31
|
-
"Gemfile.lock",
|
32
|
-
"LICENSE.txt",
|
33
|
-
"README.rdoc",
|
34
|
-
"Rakefile",
|
35
|
-
"VERSION",
|
36
|
-
"cirrocumulus.gemspec",
|
37
|
-
"lib/.gitignore",
|
38
|
-
"lib/cirrocumulus.rb",
|
39
|
-
"lib/cirrocumulus/agent.rb",
|
40
|
-
"lib/cirrocumulus/agent_wrapper.rb",
|
41
|
-
"lib/cirrocumulus/jabber_bus.rb",
|
42
|
-
"lib/cirrocumulus/logger.rb",
|
43
|
-
"lib/cirrocumulus/message.rb",
|
44
|
-
"lib/cirrocumulus/ontology.rb",
|
45
|
-
"lib/cirrocumulus/rule_engine.rb",
|
46
|
-
"lib/cirrocumulus/rule_server.rb",
|
47
|
-
"lib/cirrocumulus/rules/engine.rb",
|
48
|
-
"lib/cirrocumulus/rules/run_queue.rb",
|
49
|
-
"lib/cirrocumulus/saga.rb",
|
50
|
-
"test/Gemfile",
|
51
|
-
"test/Gemfile.lock",
|
52
|
-
"test/helper.rb",
|
53
|
-
"test/test.rb",
|
54
|
-
"test/test2.rb",
|
55
|
-
"test/test_cirrocumulus.rb"
|
56
|
-
]
|
57
|
-
s.homepage = "http://github.com/deil/cirrocumulus"
|
58
|
-
s.licenses = ["GPL-2"]
|
59
|
-
s.require_paths = ["lib"]
|
60
|
-
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
61
|
-
s.rubygems_version = "1.8.10"
|
62
|
-
s.summary = "Agent-based infrastructure management system"
|
63
|
-
|
64
|
-
if s.respond_to? :specification_version then
|
65
|
-
s.specification_version = 3
|
66
|
-
|
67
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
|
-
s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.11"])
|
69
|
-
s.add_runtime_dependency(%q<log4r>, ["~> 1.1.9"])
|
70
|
-
s.add_runtime_dependency(%q<systemu>, [">= 0"])
|
71
|
-
s.add_runtime_dependency(%q<xmpp4r>, ["~> 0.5"])
|
72
|
-
s.add_runtime_dependency(%q<xmpp4r-simple>, [">= 0"])
|
73
|
-
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
74
|
-
s.add_runtime_dependency(%q<deil_sexpistol>, [">= 0"])
|
75
|
-
s.add_runtime_dependency(%q<guid>, [">= 0"])
|
76
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
77
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
78
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
79
|
-
else
|
80
|
-
s.add_dependency(%q<activesupport>, ["~> 2.3.11"])
|
81
|
-
s.add_dependency(%q<log4r>, ["~> 1.1.9"])
|
82
|
-
s.add_dependency(%q<systemu>, [">= 0"])
|
83
|
-
s.add_dependency(%q<xmpp4r>, ["~> 0.5"])
|
84
|
-
s.add_dependency(%q<xmpp4r-simple>, [">= 0"])
|
85
|
-
s.add_dependency(%q<eventmachine>, [">= 0"])
|
86
|
-
s.add_dependency(%q<deil_sexpistol>, [">= 0"])
|
87
|
-
s.add_dependency(%q<guid>, [">= 0"])
|
88
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
89
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
90
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
91
|
-
end
|
92
|
-
else
|
93
|
-
s.add_dependency(%q<activesupport>, ["~> 2.3.11"])
|
94
|
-
s.add_dependency(%q<log4r>, ["~> 1.1.9"])
|
95
|
-
s.add_dependency(%q<systemu>, [">= 0"])
|
96
|
-
s.add_dependency(%q<xmpp4r>, ["~> 0.5"])
|
97
|
-
s.add_dependency(%q<xmpp4r-simple>, [">= 0"])
|
98
|
-
s.add_dependency(%q<eventmachine>, [">= 0"])
|
99
|
-
s.add_dependency(%q<deil_sexpistol>, [">= 0"])
|
100
|
-
s.add_dependency(%q<guid>, [">= 0"])
|
101
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
102
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
103
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
data/lib/.gitignore
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
unless Kernel.respond_to?(:require_relative)
|
2
|
-
module Kernel
|
3
|
-
def require_relative(path)
|
4
|
-
require File.join(File.dirname(caller[0]), path.to_str)
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'yaml'
|
10
|
-
require 'cirrocumulus'
|
11
|
-
require 'cirrocumulus/logger'
|
12
|
-
require 'cirrocumulus/ontology'
|
13
|
-
require 'cirrocumulus/agent'
|
14
|
-
|
15
|
-
class String
|
16
|
-
def underscore
|
17
|
-
self.gsub(/::/, '/').
|
18
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
19
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
20
|
-
tr("-", "_").
|
21
|
-
downcase
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
ontologies_file_name = nil
|
26
|
-
|
27
|
-
ARGV.each_with_index do |arg, i|
|
28
|
-
if arg == '-c'
|
29
|
-
ontologies_file_name = ARGV[i + 1]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
if ontologies_file_name.nil?
|
34
|
-
puts "Please supply config file name"
|
35
|
-
exit(0)
|
36
|
-
end
|
37
|
-
|
38
|
-
puts "Loading configuration.."
|
39
|
-
agent_config = YAML.load_file(ontologies_file_name)
|
40
|
-
ontologies = agent_config['ontologies']
|
41
|
-
ontologies.each do |ontology_name|
|
42
|
-
puts "Will load ontology %s" % ontology_name
|
43
|
-
require File.join(AGENT_ROOT, 'ontologies', ontology_name.underscore)
|
44
|
-
end
|
45
|
-
|
46
|
-
=begin
|
47
|
-
kb_name = agent_config['kb']
|
48
|
-
kb = if kb_name
|
49
|
-
puts "Will load knowledge base %s" % kb_name
|
50
|
-
require File.join(AGENT_ROOT, 'ontologies/xen/', kb_name.underscore) # TODO
|
51
|
-
eval("#{kb_name}.new()")
|
52
|
-
else
|
53
|
-
Kb.new
|
54
|
-
end
|
55
|
-
=end
|
56
|
-
|
57
|
-
begin
|
58
|
-
a = Agent::Base.new
|
59
|
-
a.load_ontologies(agent_config['ontologies'])
|
60
|
-
a.start
|
61
|
-
rescue Exception => e
|
62
|
-
puts 'Got an error:'
|
63
|
-
puts e
|
64
|
-
puts e.backtrace
|
65
|
-
end
|
66
|
-
|
67
|
-
puts "\nBye-bye."
|
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'xmpp4r'
|
2
|
-
require 'xmpp4r-simple'
|
3
|
-
require 'guid'
|
4
|
-
require 'sexpistol'
|
5
|
-
require_relative 'message'
|
6
|
-
|
7
|
-
class JabberBus
|
8
|
-
attr_reader :jid
|
9
|
-
|
10
|
-
def initialize(jid)
|
11
|
-
@jid = jid
|
12
|
-
@send_queue = Queue.new
|
13
|
-
|
14
|
-
Log4r::Logger['bus'].info 'will use Jabber for agent communications'
|
15
|
-
end
|
16
|
-
|
17
|
-
def connected?
|
18
|
-
@jabber && @jabber.connected?
|
19
|
-
end
|
20
|
-
|
21
|
-
def connect
|
22
|
-
Log4r::Logger['bus'].info "logging to #{JABBER_SERVER} as #{jid}"
|
23
|
-
|
24
|
-
begin
|
25
|
-
full_jid = jid + "@" + JABBER_SERVER
|
26
|
-
@jabber = Jabber::Simple.new(full_jid, JABBER_DEFAULT_PASSWORD)
|
27
|
-
rescue Errno::ECONNREFUSED => ex
|
28
|
-
Log4r::Logger['bus'].warn 'connection refused' and return false
|
29
|
-
rescue Jabber::ClientAuthenticationFailure => ex
|
30
|
-
Log4r::Logger['bus'].warn 'got Jabber::ClientAuthenticationFailure'
|
31
|
-
Log4r::Logger['bus'].info 'using default password to register new account'
|
32
|
-
|
33
|
-
client = Jabber::Client.new(full_jid)
|
34
|
-
client.connect()
|
35
|
-
client.register(JABBER_DEFAULT_PASSWORD) #, {'username' => full_jid, 'password' => JABBER_DEFAULT_PASSWORD})
|
36
|
-
client.close()
|
37
|
-
@jabber = Jabber::Simple.new(full_jid, JABBER_DEFAULT_PASSWORD)
|
38
|
-
end
|
39
|
-
|
40
|
-
if connected?
|
41
|
-
Log4r::Logger['bus'].info 'joining ' + JABBER_CONFERENCE
|
42
|
-
@jabber.send!("<presence to='#{JABBER_CONFERENCE}/#{@jid}' />")
|
43
|
-
true
|
44
|
-
else
|
45
|
-
false
|
46
|
-
end
|
47
|
-
rescue
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
def start(agent)
|
52
|
-
thrd = Thread.new do
|
53
|
-
s = Sexpistol.new
|
54
|
-
while true do
|
55
|
-
begin
|
56
|
-
if connected?
|
57
|
-
@jabber.received_messages do |message|
|
58
|
-
# <fipa-message ontology="cirrocumulus-cloud" act="inform" receiver="sapco-cloud"><content>q</content></fipa-message>
|
59
|
-
next unless message.x('jabber:x:delay').nil?
|
60
|
-
|
61
|
-
begin
|
62
|
-
xml = Hash.from_xml(message.body)['fipa_message']
|
63
|
-
content_raw = xml['content']
|
64
|
-
content = s.parse_string(content_raw)
|
65
|
-
acl = Cirrocumulus::Message.new(message.from.resource, xml['act'], content)
|
66
|
-
acl.receiver = xml['receiver']
|
67
|
-
acl.ontology = xml['ontology']
|
68
|
-
acl.reply_with = xml['reply_with']
|
69
|
-
acl.in_reply_to = xml['in_reply_to']
|
70
|
-
acl.conversation_id = xml['conversation_id']
|
71
|
-
flatten_message_content(acl)
|
72
|
-
|
73
|
-
#Log4r::Logger['bus'].debug(acl.inspect)
|
74
|
-
agent.process_incoming_message(acl)
|
75
|
-
rescue Exception => ex
|
76
|
-
p ex
|
77
|
-
p ex.backtrace
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
while true do
|
82
|
-
message = @send_queue.pop(true) rescue nil
|
83
|
-
break if message.nil?
|
84
|
-
|
85
|
-
send_message_actual(message)
|
86
|
-
end
|
87
|
-
else
|
88
|
-
sleep 5 unless connect
|
89
|
-
end
|
90
|
-
|
91
|
-
sleep 0.5
|
92
|
-
rescue Exception => ex
|
93
|
-
puts ex.to_s
|
94
|
-
puts ex.backtrace.to_s
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def send_message(message)
|
101
|
-
@send_queue << message
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def flatten_message_content(message)
|
107
|
-
if !message.content.is_a?(Array)
|
108
|
-
message.content = [message.content]
|
109
|
-
else
|
110
|
-
while message.content.is_a?(Array) && message.content.size == 1 && message.content.first.is_a?(Array)
|
111
|
-
message.content = message.content.first
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def send_message_actual(message)
|
117
|
-
message_content = message.content if message.content.is_a?(String)
|
118
|
-
message_content = Sexpistol.new.to_sexp(message.content) if message.content.is_a?(Array)
|
119
|
-
|
120
|
-
text = '<fipa-message ontology="%s"' % message.ontology
|
121
|
-
text += ' receiver="%s"' % message.receiver if message.receiver
|
122
|
-
text += ' act="%s"' % message.act
|
123
|
-
text += ' reply-with="%s"' % message.reply_with if message.reply_with
|
124
|
-
text += ' in-reply-to="%s"' % message.in_reply_to if message.in_reply_to
|
125
|
-
text += ' conversation-id="%s"' % message.conversation_id if message.conversation_id
|
126
|
-
text += '><content>%s</content></fipa-message>' % message_content
|
127
|
-
@jabber.send!('<message type="groupchat" to="%s" id="%s"><body>%s</body></message>' % [
|
128
|
-
JABBER_CONFERENCE,
|
129
|
-
Guid.new.to_s.gsub('-', ''),
|
130
|
-
text.gsub('&', '&').gsub('<', '<').gsub('>', '>').gsub('"', '"')
|
131
|
-
])
|
132
|
-
|
133
|
-
true
|
134
|
-
rescue Exception => ex
|
135
|
-
puts ex.to_s
|
136
|
-
puts ex.backtrace.to_s
|
137
|
-
false
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'eventmachine'
|
2
|
-
require 'sexpistol'
|
3
|
-
require 'log4r'
|
4
|
-
|
5
|
-
module RuleEngine
|
6
|
-
class Server < EventMachine::Connection
|
7
|
-
def self.run
|
8
|
-
l = Log4r::Logger.new('kb')
|
9
|
-
o = Log4r::StdoutOutputter.new('console')
|
10
|
-
l.outputters << o
|
11
|
-
|
12
|
-
EventMachine.run do
|
13
|
-
Signal.trap("INT") { EventMachine.stop }
|
14
|
-
Signal.trap("TERM") { EventMachine.stop }
|
15
|
-
|
16
|
-
EventMachine.start_server('127.0.0.1', 2812, self)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :engine
|
21
|
-
|
22
|
-
def initialize()
|
23
|
-
@engine = Test.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def receive_data(data)
|
27
|
-
s = Sexpistol.new
|
28
|
-
sexp = s.parse_string(data)
|
29
|
-
if sexp.first == :assert
|
30
|
-
engine.assert get_fact(sexp)
|
31
|
-
elsif sexp.first == :retract
|
32
|
-
engine.retract get_fact(sexp)
|
33
|
-
elsif sexp.first == :query
|
34
|
-
send_data engine.query(get_fact(sexp))
|
35
|
-
else
|
36
|
-
puts sexp.inspect
|
37
|
-
end
|
38
|
-
rescue Exception => ex
|
39
|
-
puts ex.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
protected
|
43
|
-
|
44
|
-
def get_fact(sexp)
|
45
|
-
sexp[1]
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|