Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > EventMachine: dynamic "client" connections

Reply
Thread Tools

EventMachine: dynamic "client" connections

 
 
Paul Danos
Guest
Posts: n/a
 
      11-18-2009
Thanks for reading this and thanks in advance if you provide any help!

I'm new to Ruby. Trying to write a distributed file system consisting
of a Metadata Server (MS), Object Servers (OS), and clients. I'm able
to bring up a MS and an OS that registers with the MS. What I'm having
trouble with is sending a request from a client to the MS, which should
then send that request to the appropriate OS in order to serve the
client. The requests are simple download, upload, and delete commands.
This is what I would like to have happen (for example, an upload):
1. client sends the upload command to the MS (?)
2. MS finds a an OS with available space to upload to (I have this
working)
3. MS sends the client's request and IP to the OS (?)
4. OS contacts the client (?)
5. client uploads file to OS (I figured out how to stream files)

So I need a way to dynamically create a connection to a variable IP and
send a variable message across it in order to do numbers 1, 3 & 4. I've
tried working with EventMachine in classes and modules, but cannot
figure out how to pass variables to it dynamically.

Here is an example of one of my many attempts at this:

################################################## ####

class SendCommand < EM::Connection
attr_accessor :cmd, :file

def post_init
puts "Sending: #{@cmd} #{@file}"
send_data("#{@cmd} #{@file}")
end
end


class ConnectToMS

def initialize(cmd, file)
@cmd = cmd
@file = file
end

def connect_to_ms
host = '127.0.0.1'
port = 6666
EM.run do
EM.connect(host, port, SendCommand) do |con|
con.cmd = @cmd
con.file = @file
end
puts "Sending command: #{@cmd} File: #{@file}"
end
end

end


################################################## ####

Then I would call it like this:

c = ConnectToMS.new("UPLOAD","file_name")
c.connect_to_ms
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Tony Arcieri
Guest
Posts: n/a
 
      11-18-2009
[Note: parts of this message were removed to make it a legal post.]

Neat project, sounds kinda like Tahoe (which is written in Python)

http://allmydata.org/trac/tahoe

If I'm reading your problem correctly, I actually ran into this myself way
back in the day and contributed the patch to fix it!

EM.connect(host, port, SendCommand, arg1, arg2)

[etc for as many args as you want]

These arguments will get passed along to initialize

On Tue, Nov 17, 2009 at 5:06 PM, Paul Danos <(E-Mail Removed)> wrote:

> Thanks for reading this and thanks in advance if you provide any help!
>
> I'm new to Ruby. Trying to write a distributed file system consisting
> of a Metadata Server (MS), Object Servers (OS), and clients. I'm able
> to bring up a MS and an OS that registers with the MS. What I'm having
> trouble with is sending a request from a client to the MS, which should
> then send that request to the appropriate OS in order to serve the
> client. The requests are simple download, upload, and delete commands.
> This is what I would like to have happen (for example, an upload):
> 1. client sends the upload command to the MS (?)
> 2. MS finds a an OS with available space to upload to (I have this
> working)
> 3. MS sends the client's request and IP to the OS (?)
> 4. OS contacts the client (?)
> 5. client uploads file to OS (I figured out how to stream files)
>
> So I need a way to dynamically create a connection to a variable IP and
> send a variable message across it in order to do numbers 1, 3 & 4. I've
> tried working with EventMachine in classes and modules, but cannot
> figure out how to pass variables to it dynamically.
>
> Here is an example of one of my many attempts at this:
>
> ################################################## ####
>
> class SendCommand < EM::Connection
> attr_accessor :cmd, :file
>
> def post_init
> puts "Sending: #{@cmd} #{@file}"
> send_data("#{@cmd} #{@file}")
> end
> end
>
>
> class ConnectToMS
>
> def initialize(cmd, file)
> @cmd = cmd
> @file = file
> end
>
> def connect_to_ms
> host = '127.0.0.1'
> port = 6666
> EM.run do
> EM.connect(host, port, SendCommand) do |con|
> con.cmd = @cmd
> con.file = @file
> end
> puts "Sending command: #{@cmd} File: #{@file}"
> end
> end
>
> end
>
>
> ################################################## ####
>
> Then I would call it like this:
>
> c = ConnectToMS.new("UPLOAD","file_name")
> c.connect_to_ms
> --
> Posted via http://www.ruby-forum.com/.
>
>



--
Tony Arcieri
Medioh/Nagravision

 
Reply With Quote
 
 
 
 
Paul Danos
Guest
Posts: n/a
 
      11-18-2009
Wow. I knew it was going to be a simple solution. Thank you so much,
Tony!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PIX/FWSM: allow inbound connections to dynamic NAT address? marc.luethi@bluemail.ch Cisco 7 11-26-2007 12:06 PM
Lingering Idle Oracle Connections? Persistent connections? jobs ASP .Net 2 11-16-2007 03:37 AM
Multiple site-to-site VPN plus two dynamic VPN connections one to different VLAN Joey Cisco 0 04-25-2007 03:19 AM
How do I prevent multiple connections when drawing dynamic images? Ken Varn ASP .Net 3 06-11-2004 12:50 PM
Does Pix or cisco router support dynamic-to-dynamic IPSec VPN? c Cisco 2 01-13-2004 01:53 AM



Advertisments