Class: Goat::UpdateDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/goat.rb

Class Method Summary collapse

Class Method Details

.component_updated(pgid, update) ⇒ Object



960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File 'lib/goat.rb', line 960

def self.component_updated(pgid, update)
  if Dynamic.variable?(:txn)
    txn = Dynamic[:txn]
    txn_pgid = Dynamic[:txn_pgid]
    if updates = @active_txns[txn]
      if pgid == txn_pgid
        updates[:page_updates] << update
      else
        updates[:other_updates] << update
      end
    else
      raise "Got an update for an un-started txn (#{txn.inspect}, #{pgid})"
    end
  else
    dispatch_update(update)
  end
end

.dispatch_update(update) ⇒ Object



956
957
958
# File 'lib/goat.rb', line 956

def self.dispatch_update(update)
  StateSrvClient.component_updated(nil, update.skel.pgid, update)
end

.dispatch_updates(txn, pgid, ups) ⇒ Object



943
944
945
946
947
948
949
950
951
952
953
954
# File 'lib/goat.rb', line 943

def self.dispatch_updates(txn, pgid, ups)
  pgups = ups.map{|u| u.skel.pgid}.uniq
  if pgups.size > 1
    raise "Got updates for different pages: #{pgups.inspect}"
  end

  StateSrvClient.components_updated(
    txn,
    pgid,
    ups
  )
end

.enableObject



916
917
918
919
# File 'lib/goat.rb', line 916

def self.enable
  Goat::NotificationCenter.subscribe(self, :txn_start, 'type' => 'txn_start')
  Goat::NotificationCenter.subscribe(self, :txn_complete, 'type' => 'txn_complete')
end

.finish_txn(txn_id) ⇒ Object



935
936
937
938
939
940
941
# File 'lib/goat.rb', line 935

def self.finish_txn(txn_id)
  if txn = @active_txns[txn_id]
    pgid = txn[:pgid]
    dispatch_updates(txn_id, pgid, txn[:page_updates])
    txn[:other_updates].each{|u| dispatch_update(u)}
  end
end

.txn_complete(n) ⇒ Object



931
932
933
# File 'lib/goat.rb', line 931

def self.txn_complete(n)
  finish_txn(n['txn'])
end

.txn_start(n) ⇒ Object



923
924
925
926
927
928
929
# File 'lib/goat.rb', line 923

def self.txn_start(n)
  @active_txns[n['txn']] = {
    :page_updates => [],
    :other_updates => [],
    :pgid => n['pgid']
  }
end