Sha256: 1287d5d2a454287da4b106de831411fe31732fb9ed741400bfc5e36dff9c7c63

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

ServiceId=Struct.new(:name)
class ServiceId
  def hash
    Crypt::digest(@name.to_s)
  end
end

class ServiceDescriptor
  attr_accessor :redundancy, :serviceId
end

# NetApplication is an application that runs on *every* node and provides some
# basic functionality like a directory service
class NetApplication<Application
  
  class NotInitialized<Exception
    
  end
  
  class CouldNotInitialize<Exception
    
  end
  
  class RemoteNode
    def initialize(myNode,remoteNode,app)
      @myNode=myNode
      @remoteNode=remoteNode
      @app=app
      assert{myNode}
      assert{remoteNode}
    end
    def method_missing(*args)
      @app.log "Trying to call"
      @app.log "Trying to call #{@remoteNode} #{args.inspect}"
      result=@myNode.send(@remoteNode,*args).wait
      @app.log "Trying to called RESULT ",result
      result
    end
  end
  
  def initialize(cluster,options)
    super
  end
  
  def waitForNodeCount(count)
    while node.nodeList.length<count
      sleep 1
    end
  end
  
  def defApi(*array)
    wait=10
    wait.times{
      break if node?
      sleep 1
    }
    raise CouldNotInitialize unless node?
    #return unless node?
    this=self
    log "setting hook #{getAppName}"
    @service=node.api.hook(getAppName) do |*args|
    log "PAPI:"
    log args
      name=args[0]
      args=args[1..-1]
      if array.member?(name)
        this.send(name,*args)
      end
    end
  end
  
  def node?
    if cluster
      @node||=getApp(:fullNetworkNode)
    end
    @node
  end
  
  def node(nodeId=nil)
   # log nodeId
    node?
    if nodeId.nil?
      raise NotInitialized.new unless @node
      return @node
    end
    RemoteNode.new(@service,nodeId,self)
  end
  
  def stop
    @node.removeReceiver(getAppName) if @node
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 apps/directory_service/net_application.rb