Protocol::HTTP2SourceProtocolHTTP2Dependency

class Dependency

Definitions

attr :connection

The connection this stream belongs to.

attr :id

Stream ID (odd for client initiated streams, even otherwise).

attr_accessor :parent

The parent dependency.

attr_accessor :children

The dependent children.

attr_accessor :weight

The weight of the stream relative to other siblings.

def exclusive_child(parent)

An exclusive flag allows for the insertion of a new level of dependencies. The exclusive flag causes the stream to become the sole dependency of its parent stream, causing other dependencies to become dependent on the exclusive stream.

Implementation

def exclusive_child(parent)
	parent.children = @children
	
	@children&.each_value do |child|
		child.parent = parent
	end
	
	parent.clear_cache!
	
	@children = {parent.id => parent}
	self.clear_cache!
	
	parent.parent = self
end

def priority= priority

Change the priority of the stream both locally and remotely.

Implementation

def priority= priority
	send_priority(priority)
	process_priority(priority)
end

def priority(exclusive = false)

The current local priority of the stream.

Implementation

def priority(exclusive = false)
	Priority.new(exclusive, @parent.id, @weight)
end

def consume_window(size)

Traverse active streams in order of priority and allow them to consume the available flow-control window.

Implementation

def consume_window(size)
	# If there is an associated stream, give it priority:
	if stream = self.stream
		return if stream.window_updated(size)
	end
	
	# Otherwise, allow the dependent children to use up the available window:
	self.ordered_children&.each do |child|
		# Compute the proportional allocation:
		allocated = (child.weight * size) / @total_weight
		
		child.consume_window(allocated) if allocated > 0
	end
end