eventoverse 0.0.2r

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /target
19
+ /classes
20
+ /checkouts
21
+ pom.xml
22
+ *.jar
23
+ *.class
24
+ .lein-deps-sum
25
+ .lein-failures
26
+ .lein-plugins
27
+ *~
28
+ .\#*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use jruby-1.6.7.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zweikopf.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Oleksandr Petrov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Eventoverse Client
2
+
3
+ # Copyright
4
+
5
+ Copyright (C) 2011-2012 Alex Petrov, Stylefruits GmbH
6
+
7
+ Distributed under the Ruby License.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run the specs and features.'
6
+ task :default => 'spec:all'
7
+
8
+ namespace :spec do
9
+ desc "Run all specs"
10
+ RSpec::Core::RakeTask.new('all') do |t|
11
+ t.pattern = 'spec/{**/*_spec.rb}'
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/eventoverse/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Oleksandr Petrov"]
6
+ gem.email = ["oleksandr.petrov@gmail.com"]
7
+ gem.description = %q{Eventoverse client}
8
+ gem.summary = %q{Its good, try it out!}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "eventoverse"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Eventoverse::VERSION
17
+
18
+ gem.add_development_dependency "rake"
19
+ gem.add_development_dependency "rspec"
20
+
21
+ if RUBY_PLATFORM == 'java'
22
+ gem.add_runtime_dependency('hot_bunnies')
23
+ else
24
+ gem.add_runtime_dependency('bunny', "0.8.0")
25
+ end
26
+
27
+ gem.add_runtime_dependency('multi_json')
28
+ gem.add_runtime_dependency('json')
29
+ end
@@ -0,0 +1,52 @@
1
+ require 'monitor'
2
+ require 'hot_bunnies'
3
+ require 'multi_json'
4
+
5
+ module Eventoverse
6
+ class AmqpReporterJRuby < BaseReporter
7
+
8
+ #
9
+ # API
10
+ #
11
+
12
+ def backend_publish_message(payload)
13
+ body = MultiJson.encode(payload)
14
+ exchange.publish(body, :routing_key => "", :persistent => true)
15
+ end # publish_message
16
+
17
+ #
18
+ # Implementation
19
+ #
20
+
21
+ private
22
+
23
+ def initialize
24
+ @monitor = Monitor.new
25
+ end # initialize
26
+
27
+ def connection
28
+ return @connection unless @connection.nil?
29
+ @monitor.synchronize do
30
+ return @connection unless @connection.nil?
31
+ @connection = HotBunnies.connect(:host => Config.get_in(Eventoverse.config, [:amqp, :host]),
32
+ :vhost => Config.get_in(Eventoverse.config, [:amqp, :vhost]),
33
+ :username => Config.get_in(Eventoverse.config, [:amqp, :username]),
34
+ :password => Config.get_in(Eventoverse.config, [:amqp, :password]))
35
+ end
36
+ end # connection
37
+
38
+ def channel
39
+ return @channel unless @channel.nil?
40
+ @monitor.synchronize do
41
+ return @channel unless @channel.nil?
42
+ @channel = connection.create_channel
43
+ end
44
+ end # channel
45
+
46
+ def exchange
47
+ channel.exchange("events", :type => :fanout, :durable => true, :auto_delete => false)
48
+ end # exchange
49
+
50
+ end # Eventoverse
51
+
52
+ end
@@ -0,0 +1,55 @@
1
+ require 'monitor'
2
+ require 'bunny'
3
+ require 'multi_json'
4
+
5
+ module Eventoverse
6
+ class AmqpReporterMri < BaseReporter
7
+
8
+ #
9
+ # API
10
+ #
11
+
12
+ def backend_publish_message(payload)
13
+ body = MultiJson.encode(payload)
14
+ exchange.publish(body, :routing_key => "", :persistent => true)
15
+ end # publish_message
16
+
17
+ #
18
+ # Implementation
19
+ #
20
+
21
+ private
22
+
23
+ def initialize
24
+ @monitor = Monitor.new
25
+ end # initialize
26
+
27
+ def connection
28
+ return @connection unless @connection.nil?
29
+ @monitor.synchronize do
30
+ return @connection unless @connection.nil?
31
+ @connection = Bunny.new(:host => Config.get_in(Eventoverse.config, [:host]),
32
+ :vhost => Config.get_in(Eventoverse.config, [:amqp, :vhost]),
33
+ :user => Config.get_in(Eventoverse.config, [:amqp, :username]),
34
+ :pass => Config.get_in(Eventoverse.config, [:amqp, :password]))
35
+ @connection.start
36
+ @connection
37
+ end
38
+ end # connection
39
+
40
+ def channel
41
+ return @channel unless @channel.nil?
42
+ @monitor.synchronize do
43
+ return @channel unless @channel.nil?
44
+ @channel = connection.create_channel
45
+ @channel
46
+ end
47
+ end # channel
48
+
49
+ def exchange
50
+ # Bunny itself will handle keeping single instance of exchange in memory
51
+ connection.exchange('events', :type => :fanout, :durable => true, :auto_delete => false)
52
+ end # exchange
53
+
54
+ end # Eventoverse
55
+ end
@@ -0,0 +1,51 @@
1
+ require 'singleton'
2
+ require 'monitor'
3
+ require 'time'
4
+
5
+ module Eventoverse
6
+ class BaseReporter
7
+
8
+ #
9
+ # Behavior
10
+ #
11
+
12
+ include Singleton
13
+
14
+ #
15
+ # API
16
+ #
17
+
18
+ def publish_message(event_type, attributes = {}, tags = [])
19
+ payload = {:environment => Config.get_in(Eventoverse.config, [:env]),
20
+ :application => Config.get_in(Eventoverse.config, [:application_name]),
21
+ :hostname => Socket.gethostname,
22
+ :tags => tags,
23
+ :emitted_at => Time.now.to_i,
24
+ :type => event_type || "exception"}
25
+
26
+ payload.merge!(:additional_info => attributes) unless attributes.nil?
27
+
28
+ backend_publish_message(payload)
29
+ rescue Exception => e
30
+ puts "#{Time.now}: Can't publish the message (\n\tType: #{event_type}\n\tBody: #{payload.inspect}). \n\tDetails:#{e.inspect} \n\tBacktrace: #{e.backtrace}"
31
+ end # publish_message
32
+
33
+ def self.publish_message(*args)
34
+ self.instance.publish_message(args)
35
+ end # self.publish_message(*args)
36
+
37
+ def publish_exception(exception, additional_info = {})
38
+ backtrace = exception.backtrace
39
+ backtrace_first_line = backtrace.first || ""
40
+ md5_digest = Digest::MD5.hexdigest(backtrace_first_line)
41
+ self.publish_message("exception", additional_info.merge({:backtrace_first_line => backtrace_first_line,
42
+ :message => exception.message,
43
+ :backtrace => backtrace.join("\n").slice(0..7000),
44
+ :md5_digest => md5_digest }))
45
+ rescue Exception => e
46
+ puts "#{Time.now}: Can't publish exception, because of #{e.message} \n #{e.backtrace.join}"
47
+ end
48
+
49
+
50
+ end # BaseReporter
51
+ end # Event_Type
@@ -0,0 +1,28 @@
1
+ module Eventoverse
2
+ module Config
3
+ # Returns value from hash based on the path
4
+ #
5
+ # @param hash [Hash] - hash to retrieve values from
6
+ # @param path [Array] - non-empty array representing recursive path
7
+ #
8
+ # @returns [Object] - an object located within an array on the given path
9
+ #
10
+ # Examples:
11
+ #
12
+ # get_in({:a => {:b => {:c => 2}}}, [:a, :b, :c]) # => 2
13
+ # get_in({:a => {:b => {:c => 2}}}, [:a, :e, :c]) # => nil
14
+ # get_in({:a => {:b => {:c => 2}}}, [:a, :b]) # => {:c=>2}
15
+ #
16
+ def self.get_in(hash, path)
17
+ raise "Path should be an array!" unless path.is_a?(Array)
18
+ raise "Path should not be empty!" if path.empty?
19
+
20
+ res = hash.fetch(path.shift, nil)
21
+ if path.empty? || res.nil?
22
+ res
23
+ else
24
+ get_in(res, path)
25
+ end
26
+ end # get_in(hash)
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ require 'monitor'
2
+ require 'multi_json'
3
+ require 'socket'
4
+
5
+ module Eventoverse
6
+ class UdpReporter < BaseReporter
7
+
8
+ #
9
+ # API
10
+ #
11
+
12
+ def backend_publish_message(payload)
13
+ body = MultiJson.encode(payload)
14
+
15
+ connection.send(body.to_s, 0)
16
+ end # publish_message
17
+
18
+ private
19
+
20
+ def initialize
21
+ @monitor = Monitor.new
22
+ end
23
+
24
+ def connection
25
+ return @connection unless @connection.nil?
26
+ @monitor.synchronize do
27
+ return @connection unless @connection.nil?
28
+ @connection = UDPSocket.new
29
+ @connection.connect(Config.get_in(Eventoverse.config, [:host]),
30
+ Config.get_in(Eventoverse.config, [:udp, :port]))
31
+ @connection
32
+ end
33
+ end # connection
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,3 @@
1
+ module Eventoverse
2
+ VERSION = "0.0.2r"
3
+ end
@@ -0,0 +1,39 @@
1
+ require "eventoverse/version"
2
+ require "eventoverse/config"
3
+
4
+ require "eventoverse/base_reporter"
5
+
6
+ module Eventoverse
7
+
8
+ def self.amqp
9
+ if RUBY_PLATFORM == 'java'
10
+ require "eventoverse/amqp_reporter_jruby"
11
+ AmqpReporterJRuby.instance
12
+ else
13
+ require "eventoverse/amqp_reporter_mri"
14
+ AmqpReporterMri.instance
15
+ end
16
+ end
17
+
18
+ def self.udp
19
+ require "eventoverse/udp_reporter"
20
+ UdpReporter.instance
21
+ end
22
+
23
+ def self.set_reporter!(reporter)
24
+ @repoter = repoter
25
+ end
26
+
27
+ def self.reporter
28
+ @repoter || self.udp
29
+ end
30
+
31
+ def self.configure!(config)
32
+ @config = config
33
+ end
34
+
35
+ def self.config
36
+ @config
37
+ end
38
+
39
+ end
@@ -0,0 +1,18 @@
1
+ require 'eventoverse'
2
+
3
+ Eventoverse.configure!({:env => "development",
4
+ :application_name => "sf_plus",
5
+ :host => "localhost",
6
+ :udp => {:port => 3333},
7
+ :amqp => { :vhost => "eventoverse.development"},
8
+ :username => "eventoverse",
9
+ :password => "eventoverse_password"})
10
+
11
+
12
+ begin
13
+ raise "Just a false alarm, mostly"
14
+ rescue Exception => e
15
+ Eventoverse.amqp.publish_exception(e)
16
+ end
17
+
18
+ # Eventoverse.amqp.publish_message("exception", {:first => 1, :second => 2, :third => 3}, :tags => [:first, :second])
@@ -0,0 +1,12 @@
1
+ require 'eventoverse'
2
+
3
+ Eventoverse.configure!({:env => "development",
4
+ :application_name => "sf_plus",
5
+ :host => "localhost",
6
+ :udp => {:port => 3333},
7
+ :vhost => "eventoverse.development",
8
+ :username => "eventoverse",
9
+ :password => "eventoverse_password"})
10
+
11
+
12
+ Eventoverse.udp.publish_message("exception", {:first => 1, :second => 2, :third => 3}, :tags => [:first, :second])
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eventoverse
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1976151110
5
+ prerelease: 5
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ - r
11
+ version: 0.0.2r
12
+ platform: ruby
13
+ authors:
14
+ - Oleksandr Petrov
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2013-01-14 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: bunny
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ hash: 63
58
+ segments:
59
+ - 0
60
+ - 8
61
+ - 0
62
+ version: 0.8.0
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: multi_json
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: json
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :runtime
92
+ version_requirements: *id005
93
+ description: Eventoverse client
94
+ email:
95
+ - oleksandr.petrov@gmail.com
96
+ executables: []
97
+
98
+ extensions: []
99
+
100
+ extra_rdoc_files: []
101
+
102
+ files:
103
+ - .gitignore
104
+ - .rspec
105
+ - .rvmrc
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - eventoverse_client.gemspec
111
+ - lib/eventoverse.rb
112
+ - lib/eventoverse/amqp_reporter_jruby.rb
113
+ - lib/eventoverse/amqp_reporter_mri.rb
114
+ - lib/eventoverse/base_reporter.rb
115
+ - lib/eventoverse/config.rb
116
+ - lib/eventoverse/udp_reporter.rb
117
+ - lib/eventoverse/version.rb
118
+ - script/dispatch_amqp_mri.rb
119
+ - script/dispatch_udp.rb
120
+ homepage: ""
121
+ licenses: []
122
+
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">"
141
+ - !ruby/object:Gem::Version
142
+ hash: 25
143
+ segments:
144
+ - 1
145
+ - 3
146
+ - 1
147
+ version: 1.3.1
148
+ requirements: []
149
+
150
+ rubyforge_project:
151
+ rubygems_version: 1.8.24
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Its good, try it out!
155
+ test_files: []
156
+