amqp-processing 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.textile +40 -0
- data/Rakefile +31 -0
- data/amqp-processing.gemspec +28 -0
- data/amqp-processing.jpg +0 -0
- data/bin/amqpp +41 -0
- data/lib/amqp-processing.rb +2 -0
- data/lib/amqp-processing/client.rb +97 -0
- data/lib/amqp-processing/logging.rb +17 -0
- data/lib/amqp-processing/version.rb +3 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jay McGavren
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
h1. AMQP-Processing
|
2
|
+
|
3
|
+
Ruby-Processing, Internet-enabled.
|
4
|
+
|
5
|
+
!https://github.com/jaymcgavren/amqp-processing/raw/master/amqp-processing.jpg(OS X, Windows, and Linux machines, all displaying the same sketch via amqp-processing)!
|
6
|
+
|
7
|
+
|
8
|
+
h1. Installation
|
9
|
+
|
10
|
+
<pre>
|
11
|
+
gem install amqp-processing
|
12
|
+
</pre>
|
13
|
+
|
14
|
+
|
15
|
+
h1. Connecting to a Server
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
$ amqpp <server_address> <port>
|
19
|
+
</pre>
|
20
|
+
|
21
|
+
When the prompt appears, call Processing::App methods on the proxy object stored in $client. The call will be duplicated on all clients currently connected to the server.
|
22
|
+
|
23
|
+
<pre>
|
24
|
+
>> $client.stroke 100, 255, 50, 128
|
25
|
+
=> nil
|
26
|
+
>> $client.oval 100, 100, 300, 200
|
27
|
+
=> nil
|
28
|
+
</pre>
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
h1. Resources
|
33
|
+
|
34
|
+
"Ruby-Processing Documentation":http://github.com/jashkenas/ruby-processing/wiki
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
h1. Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2010 Jay McGavren. Released under the MIT license. See the LICENSE file for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
# require 'spec/rake/spectask'
|
5
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
6
|
+
# spec.libs << 'lib' << 'spec'
|
7
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
11
|
+
# spec.libs << 'lib' << 'spec'
|
12
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
13
|
+
# spec.rcov = true
|
14
|
+
# end
|
15
|
+
|
16
|
+
task :default => :spec
|
17
|
+
|
18
|
+
require 'rake/rdoctask'
|
19
|
+
Rake::RDocTask.new do |rdoc|
|
20
|
+
if File.exist?('VERSION')
|
21
|
+
version = File.read('VERSION')
|
22
|
+
else
|
23
|
+
version = ""
|
24
|
+
end
|
25
|
+
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = "amqp-processing #{version}"
|
28
|
+
rdoc.rdoc_files.include('README*')
|
29
|
+
rdoc.rdoc_files.include('LICENSE*')
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "amqp-processing/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "amqp-processing"
|
7
|
+
s.version = AMQPProcessing::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jay McGavren"]
|
10
|
+
s.email = ["jay@mcgavren.com"]
|
11
|
+
s.homepage = "http://github.com/jaymcgavren/amqp-processing"
|
12
|
+
s.summary = %q{A server that allows multiple users to view and program a shared Ruby-Processing sketch.}
|
13
|
+
s.description = %q{A server that allows multiple users to view and program a shared Ruby-Processing sketch.}
|
14
|
+
s.extra_rdoc_files = ["README.textile", "LICENSE"]
|
15
|
+
|
16
|
+
s.rubyforge_project = "amqp-processing"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_development_dependency 'rspec'
|
24
|
+
s.add_development_dependency 'fuubar'
|
25
|
+
s.add_dependency 'ruby-processing'
|
26
|
+
s.add_dependency 'amqp'
|
27
|
+
|
28
|
+
end
|
data/amqp-processing.jpg
ADDED
Binary file
|
data/bin/amqpp
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
address, port = ARGV
|
4
|
+
address ||= 'localhost'
|
5
|
+
port ||= 5672
|
6
|
+
|
7
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
require 'rubygems'
|
9
|
+
require 'ruby-processing'
|
10
|
+
require 'amqp-processing/client'
|
11
|
+
java_import 'java.awt.event.WindowEvent'
|
12
|
+
java_import 'java.awt.event.KeyEvent'
|
13
|
+
require 'logger'
|
14
|
+
|
15
|
+
Processing::SKETCH_PATH = ""
|
16
|
+
|
17
|
+
class Sketch < Processing::App
|
18
|
+
def initialize(options = {})
|
19
|
+
@address = options[:address]
|
20
|
+
@port = options[:port]
|
21
|
+
super
|
22
|
+
end
|
23
|
+
def setup
|
24
|
+
$client = AMQPProcessing::Client.new
|
25
|
+
$client.app = self
|
26
|
+
$client.logger = Logger.new(STDOUT)
|
27
|
+
$client.connect(:host => @address, :port => @port)
|
28
|
+
background 0
|
29
|
+
end
|
30
|
+
def draw
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
sketch = Sketch.new(:address => address, :port => port, :width => 1280, :height => 1000, :title => '', :full_screen => false)
|
35
|
+
|
36
|
+
|
37
|
+
ARGV.clear #IRB will load arguments as files unless we clear this.
|
38
|
+
|
39
|
+
require 'irb'
|
40
|
+
IRB.setup(__FILE__)
|
41
|
+
IRB.start
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'mq'
|
2
|
+
require 'amqp-processing/logging'
|
3
|
+
|
4
|
+
module AMQPProcessing
|
5
|
+
|
6
|
+
|
7
|
+
class Client
|
8
|
+
|
9
|
+
include Logging
|
10
|
+
|
11
|
+
#A Processing::App which will receive all method calls made on peer Client objects.
|
12
|
+
attr_reader :app
|
13
|
+
def app=(value)
|
14
|
+
@app = value
|
15
|
+
undef_insecure_methods(@app)
|
16
|
+
end
|
17
|
+
|
18
|
+
#The server connection Thread, set by the connect method.
|
19
|
+
attr_reader :thread
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@client_id = rand(100000000).to_i
|
23
|
+
@call_fanout = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def connect(options = {})
|
27
|
+
Thread.abort_on_exception = true
|
28
|
+
@thread = Thread.new do
|
29
|
+
AMQP.start(options) do
|
30
|
+
@call_fanout = MQ.fanout('calls')
|
31
|
+
@call_queue = MQ.queue("amqp-processing.#{@client_id}", :auto_delete => true)
|
32
|
+
@call_queue.bind(@call_fanout, :key => "amqp-processing.*").subscribe do |message|
|
33
|
+
call = Marshal.load(message)
|
34
|
+
sender_id, name, arguments = call.shift, call.shift, *call
|
35
|
+
if sender_id == @client_id
|
36
|
+
log.debug "sender_id #{sender_id} == @client_id #{@client_id}, ignoring"
|
37
|
+
else
|
38
|
+
log.debug "received from #{sender_id}: #{name}, #{arguments.inspect}"
|
39
|
+
@app.__send__(name, *arguments)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_missing(name, *arguments)
|
47
|
+
return_value = @app.__send__(name, *arguments)
|
48
|
+
log.debug "sending as #{@client_id}: #{name}, #{arguments.inspect}"
|
49
|
+
while @call_fanout == nil
|
50
|
+
log.debug "Not yet connected to publishing queue, sleeping"
|
51
|
+
sleep 1
|
52
|
+
end
|
53
|
+
@call_fanout.publish(Marshal.dump([@client_id, name, arguments]))
|
54
|
+
return_value
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def undef_insecure_methods(object)
|
60
|
+
class << object
|
61
|
+
%w{
|
62
|
+
clone
|
63
|
+
define_singleton_method
|
64
|
+
display
|
65
|
+
dup
|
66
|
+
extend
|
67
|
+
freeze
|
68
|
+
instance_eval
|
69
|
+
instance_exec
|
70
|
+
instance_variable_defined?
|
71
|
+
instance_variable_get
|
72
|
+
instance_variable_set
|
73
|
+
instance_variables
|
74
|
+
public_send
|
75
|
+
remove_instance_variable
|
76
|
+
save
|
77
|
+
send
|
78
|
+
tap
|
79
|
+
library_loaded?
|
80
|
+
load_java_library
|
81
|
+
load_libraries
|
82
|
+
load_library
|
83
|
+
load_ruby_library
|
84
|
+
}.each do |method|
|
85
|
+
if method_defined?(method.to_sym)
|
86
|
+
undef_method(method.to_sym)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module AMQPProcessing
|
4
|
+
|
5
|
+
module Logging
|
6
|
+
|
7
|
+
attr_accessor :logger
|
8
|
+
|
9
|
+
#Returns the assigned logger, or creates a new Logger with no output stream.
|
10
|
+
def log
|
11
|
+
@logger ||= Logger.new(nil)
|
12
|
+
@logger
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amqp-processing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jay McGavren
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-13 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: fuubar
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: ruby-processing
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: amqp
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id004
|
68
|
+
description: A server that allows multiple users to view and program a shared Ruby-Processing sketch.
|
69
|
+
email:
|
70
|
+
- jay@mcgavren.com
|
71
|
+
executables:
|
72
|
+
- amqpp
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- README.textile
|
77
|
+
- LICENSE
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.textile
|
83
|
+
- Rakefile
|
84
|
+
- amqp-processing.gemspec
|
85
|
+
- amqp-processing.jpg
|
86
|
+
- bin/amqpp
|
87
|
+
- lib/amqp-processing.rb
|
88
|
+
- lib/amqp-processing/client.rb
|
89
|
+
- lib/amqp-processing/logging.rb
|
90
|
+
- lib/amqp-processing/version.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/jaymcgavren/amqp-processing
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project: amqp-processing
|
117
|
+
rubygems_version: 1.3.6
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: A server that allows multiple users to view and program a shared Ruby-Processing sketch.
|
121
|
+
test_files: []
|
122
|
+
|