Permalink
Browse files

Extracted gen_token to util class.

  • Loading branch information...
1 parent fb2ca84 commit aaf7f768ab7f88b58c843fe9953d30dd64f5ec02 Samuel Tesla committed May 20, 2009
Showing with 22 additions and 15 deletions.
  1. +2 −0 lib/pelvis.rb
  2. +2 −15 lib/pelvis/agent.rb
  3. +18 −0 lib/pelvis/util.rb
View
@@ -5,6 +5,8 @@
$:.unshift File.dirname(__FILE__)
+require 'pelvis/util'
+
require 'pelvis/logging'
require 'pelvis/callbacks'
View
@@ -17,15 +17,15 @@ def start
end
def initial_job
- @initial_job ||= Job.create(gen_token, :init, "/init")
+ @initial_job ||= Job.create(Util.gen_token, :init, "/init")
end
def request(scope, operation, args, options, parent = nil)
# TODO: Shift this to the local protocol
# serialize/unserialize attrs to wipe out symbols etc, makes locally dispatched same as remote
args = JSON.parse(args.to_json).to_mash
delegate = options.delete(:delegate)
- job = Job.create(gen_token, scope, operation, args, options, parent || initial_job)
+ job = Job.create(Util.gen_token, scope, operation, args, options, parent || initial_job)
o = Outcall.start(self, job)
if delegate
@@ -122,19 +122,6 @@ def operations_for(job)
operations
end
- def gen_token
- values = [
- rand(0x0010000),
- rand(0x0010000),
- rand(0x0010000),
- rand(0x0010000),
- rand(0x0010000),
- rand(0x1000000),
- rand(0x1000000),
- ]
- "%04x%04x%04x%04x%04x%06x%06x" % values
- end
-
def inspect
"#<#{self.class} protocol=#{@protocol.inspect} actors=#{@actors.inspect}>"
end
View
@@ -0,0 +1,18 @@
+module Pelvis
+ module Util
+ class << self
+ def gen_token
+ values = [
+ rand(0x0010000),
+ rand(0x0010000),
+ rand(0x0010000),
+ rand(0x0010000),
+ rand(0x0010000),
+ rand(0x1000000),
+ rand(0x1000000),
+ ]
+ "%04x%04x%04x%04x%04x%06x%06x" % values
+ end
+ end
+ end
+end

0 comments on commit aaf7f76

Please sign in to comment.