Sha256: 8ede69f1a65aa35ef73b4481399401e7aeb3082d2ba2c585d8a86dccbbf1ce14

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

class GlobalApplication<Application
  requires :fullNetworkNode
  requires :directoryService
  
  def initialize(cluster,options,name=nil)
    super(cluster,options)
    
    # register
    @api=[]
    @name=name
    @offers=[]
    
    
  end
  
  def offer(atName)
    @offers<<atName
    getApp(:directoryService).set([:appNodes,atName],[@networkNode.me])
  end
  protected :offer
  
  def run
    log "SETTING APPNODES"
    @networkNode=getApp(:fullNetworkNode)
    assert { @networkNode }
    
    # FIXME: 1) add only and 2) use secure (restricted storage)
    assert { getApp(:directoryService) }
    @networkNode.api.hook(:globalApp){|*call|
      dispatch(call)
    }
    offer(@name) if @name
    super
  end
  
  def dispatch(call)
    return unless call.is_a?(Array)
    log "DISPATCH",call,@name,@offers
    if @offers.member?(call[0])
      # FIXME: check api
      log "CALLING #{call[1]} withs params #{((call[2..-1])).inspect}"
      return self.send(call[1],*call[2])
    end
    puts "NO APP FOUND"
    nil
  end
  
  protected
  def api(funcName,description,args)
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 apps/global_application_interface/global_application.rb