Top Level Namespace

Defined Under Namespace

Modules: ClusterFuncs, Crypt, Crypto, EventAPI, Linalg, PCA, Protocol, Secure, Simple, SimpleMarshal, Spec, TreetopTestGrammar Classes: AbstractNetwork, AccessViolationException, AppConfig, Application, Appswarm, Array, AssertionFailed, BreakingMutex, Certificate, CertificateGetter, Class, ClientTCPSocketPackagedPipe, Configuration, Dir, FalseClass, File, GlobalRouting, GlobalService, GlobalServiceID, HTTPApp, HTTPAppSettings, HTTPController, HTTPProvider, HTTPProviderException, HTTPSTunnelServer, HTTPTunnelClient, Hash, Information, LocalRouting, MDir, MyCertificate, NetService, NetworkNode, NetworkTestBed, Node, Nodes, OpenNetwork, Package, Parser, Permissions, PublicAPI, ServerTCPSocketPackagedPipe, Service, SimpleMarshalParser, String, Symbol, TemplateController, TestBed, TestLogger, Thread, Tracer, TreetopTestGrammarParser, TrueClass, WaitingPrioQueue, WaitingQueue, WebrickLogger, Whiteboard

Constant Summary collapse

FRAG =
0.1
MYMAX =
1000000

Instance Method Summary collapse

Instance Method Details

#applicationDirObject



59
60
61
# File 'lib/appswarm/package.rb', line 59

def applicationDir
  File.expand_path("../../../apps",__FILE__)
end

#asBaseDirObject



7
8
9
# File 'lib/appswarm/tools.rb', line 7

def asBaseDir
  File.expand_path('../..',__FILE__)
end

#assert(&b) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/appswarm/tools.rb', line 83

def assert(&b)
  unless b.call
    dcaller=caller[0]
    file,line,func=dcaller.split(":")
    content=assertReadLine(file,line.to_i)
    s="Assertion failed #{content} in #{file}:#{line}"
    body=caller.join("\n")
    glog(s+"\n"+body)
    puts s
    raise AssertionFailed.new   
  end
end

#assertReadLine(file, line) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/appswarm/tools.rb', line 97

def assertReadLine(file,line)
  f=File.open(file,"r")
  all=f.read
  lines=all.split("\n")
  l=lines[line-1]
  f.close
  l
end

#checkThreads(time) ⇒ Object

checks if there are still some threads running in between test cases



21
22
23
24
25
26
27
28
29
# File 'lib/appswarm/features_helper.rb', line 21

def checkThreads(time)
  if Thread.list.select{|t|t.stacktrace?}.length>1
    puts "checkThreads may fail"
    Thread.current.printOthers
  end

  "#{Thread.list.select{|t|t.alive?}.select{|t|t.stacktrace?}.length} #{time}".should == "1 #{time}"
  TestBed.testbeds.length.should == 0
end

#decode(str) ⇒ Object



5
6
7
# File 'lib/appswarm/tools/http_tunnel_common.rb', line 5

def decode(str)
  return Marshal.load(str.unpack("m")[0])
end

#dir(path, &p) ⇒ Object



37
38
39
40
41
# File 'lib/appswarm/dir_tool.rb', line 37

def dir(path,&p)
  d=MDir.new(path)
  d.instance_eval(&p)
  d.gather
end

#encode(str) ⇒ Object



1
2
3
# File 'lib/appswarm/tools/http_tunnel_common.rb', line 1

def encode(str)
  return [Marshal.dump(str)].pack("m")
end

#getClass(name) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/appswarm/tools.rb', line 212

def getClass(name)
  #pp "TRY GETCLASS #{name}"
  $CLASS_CACHE||={}

  unless $CLASS_CACHE.key?(name)
    c=nil
    begin
      ObjectSpace.each_object{|o|
        c=o if o.to_s==name and o.is_a?(Class)
      }
    rescue
      c=instance_eval(name)
    end

    $CLASS_CACHE[name]=c
  end
  $CLASS_CACHE[name]  
end

#getFromGlobalProxy(proxy, url, post = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/appswarm/proxy_testing.rb', line 3

def getFromGlobalProxy(proxy,url,post=nil)

  proxy_addr = '127.0.0.1'
  proxy_port = proxy.port
  result=nil
  puts "TRYING PROXY #{proxy_addr} #{proxy_port}"
  origurl=url.dup
  url=URI.parse(url)
   
  origurl.gsub!(/http:\/\/[^\/]*/,'')
   
  Net::HTTP::Proxy(proxy_addr, proxy_port).start(url.host,url.port) {|http|
    puts "HTTP OPENED"
    begin
      #pp url.path.
      #path=url
      if post
        req = Net::HTTP::Post.new(origurl)
        #     req.basic_auth 'jack', 'pass'
        #     req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
        pp "POST",post
        req.set_form_data(post,";")
        #req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
        pp "POSTREQ",req.body
        #pp req
        #result=http.requestpost(req)
        result=http.request_post(origurl,post.map{|k,v|k+"="+v}.join(";"))

      else
        result=http.get(origurl)
      end
      pp "RESULT:",result,result.body
    rescue Object=>e
      pp e,e.backtrace
    end
    #     pp "PROXY_RESULT:",result
    #     pp result.body
  }
  result
end

#glog(*s) ⇒ Object



273
274
275
# File 'lib/appswarm/tools.rb', line 273

def glog(*s)
  #puts "GLOBAL LOG #{caller[0]} #{Time.now} "+(s.map{|x|x.to_s}.join("; "))
end

#hexDist(hash1, hash2) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/appswarm/tools.rb', line 259

def hexDist(hash1,hash2)
  assert{hash1.length==hash2.length}
  dist=0
  (0...hash1.length).each{|i|
     current=(hash1[i]^hash2[i])
     dist*=256
     dist+=current
     #r+=c
  }
  dist
  
end

#kernelObject



6
7
8
# File 'lib/appswarm/cross_spectool.rb', line 6

def kernel
  $MY_KERNEL
end

#killOtherThreads!Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/appswarm/test_bed.rb', line 149

def killOtherThreads!
  # kill eveything that's aroudn
  if Thread.list.length>1
    (Thread.list-[Thread.current]).select{|x|x.alive?}.each{|t|
      log "KILLING #{t} #{t.stacktrace}"
      t.kill!
      log "KILLED #{t} #{t.crashtrace}"

    }
  end
end

#loadApp(cluster, name) ⇒ Object



63
64
65
66
67
# File 'lib/appswarm/package.rb', line 63

def loadApp(cluster,name)
  filename=File.join(applicationDir,name,name+".rb")
  cluster.log "LOADING #{filename}"
  require filename
end

#loadApps(cluster) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/appswarm/package.rb', line 70

def loadApps(cluster)
  allApps=[]
  Dir[File.join(applicationDir,'*')].each{|dir|
    if File.directory?(dir)
      $:<<dir
      name=File.split(dir)[1]
      loadApp(cluster,name)
      app=nil
      begin
        app=eval(name.camelCase+"App")
      rescue
      end
      allApps<<app
    end
  }
  allApps.select{|a|a}
end

#measureTime(depth = 1, &block) ⇒ Object



277
278
279
280
281
282
283
# File 'lib/appswarm/tools.rb', line 277

def measureTime(depth=1,&block)
  startTime=Time.now
  r=block.call
  endTime=Time.now
  glog caller[0...depth],"TIME:",(endTime-startTime)
  r
end

#parser(name, &block) ⇒ Object



163
164
165
# File 'lib/appswarm/tools/parser/parser_lib.rb', line 163

def parser(name,&block)
  Parser.new(name,&block)
end

#publicAPIObject



32
33
34
# File 'lib/appswarm/public_api.rb', line 32

def publicAPI
  PublicAPI.new(self)
end

#sleepDebug(time) ⇒ Object



139
140
141
142
143
144
145
146
# File 'lib/appswarm/test_bed.rb', line 139

def sleepDebug(time)
  t=0
  while t<time
    puts "Waiting in #{caller[0]} #{t} of #{time}"
    sleep FRAG
    t+=FRAG
  end
end

#use_template(category, name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/appswarm/http/http_controller.rb', line 4

def use_template(category,name)
  begin
  case category
    when :web
      path=File.join(asBaseDir,"templates","web",name.to_s)
      $:<<path

      cntrlPath=File.join(path,"controllers")
      controllerFiles=Dir[File.join(cntrlPath,"*")]
      controllerFiles.each{|f|load f}
  end
  rescue Object=>e
    log "Error:",e,e.backtrace
  end
end