-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
571 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
defmodule Strom.Mixer do | ||
alias Strom.GenMix | ||
|
||
defstruct [:gen_mix, :inputs, :output, :opts, :flow_pid, :sup_pid] | ||
|
||
def new(inputs, output, opts \\ []) do | ||
unless is_list(inputs) do | ||
raise "Mixer sources must be a list, given: #{inspect(inputs)}" | ||
end | ||
|
||
%__MODULE__{inputs: inputs, output: output, opts: opts} | ||
end | ||
|
||
def start(args \\ []) | ||
|
||
def start(%__MODULE__{opts: opts, flow_pid: flow_pid, sup_pid: sup_pid} = mixer) do | ||
gen_mix = %GenMix{opts: opts, flow_pid: flow_pid, sup_pid: sup_pid} | ||
GenMix.start(gen_mix) | ||
defstruct pid: nil, | ||
inputs: [], | ||
output: nil, | ||
opts: [], | ||
flow_pid: nil, | ||
sup_pid: nil | ||
|
||
def new(inputs, output) | ||
when is_list(inputs) or (is_map(inputs) and map_size(inputs) > 0) do | ||
%__MODULE__{inputs: inputs, output: output} | ||
end | ||
|
||
def start(opts) when is_list(opts) do | ||
GenMix.start(opts) | ||
end | ||
|
||
def call(flow, %__MODULE__{gen_mix: mix}, to_mix, name) when is_map(flow) and is_list(to_mix) do | ||
def start( | ||
%__MODULE__{ | ||
inputs: inputs, | ||
output: output, | ||
flow_pid: flow_pid, | ||
sup_pid: sup_pid | ||
} = mixer, | ||
opts \\ [] | ||
) do | ||
inputs = | ||
Enum.reduce(to_mix, %{}, fn name, acc -> | ||
Map.put(acc, name, fn _el -> true end) | ||
end) | ||
|
||
outputs = %{name => fn _el -> true end} | ||
|
||
GenMix.call(flow, mix, inputs, outputs) | ||
if is_list(inputs) do | ||
Enum.reduce(inputs, %{}, fn name, acc -> | ||
Map.put(acc, name, fn _el -> true end) | ||
end) | ||
else | ||
inputs | ||
end | ||
|
||
outputs = %{output => fn _el -> true end} | ||
|
||
gen_mix = %GenMix{ | ||
inputs: inputs, | ||
outputs: outputs, | ||
opts: opts, | ||
flow_pid: flow_pid, | ||
sup_pid: sup_pid | ||
} | ||
|
||
{:ok, pid} = GenMix.start(gen_mix) | ||
%{mixer | pid: pid, opts: opts} | ||
end | ||
|
||
def call(flow, %__MODULE__{gen_mix: mix}, to_mix, name) when is_map(flow) and is_map(to_mix) do | ||
outputs = %{name => fn _el -> true end} | ||
GenMix.call(flow, mix, to_mix, outputs) | ||
def call(flow, %__MODULE__{pid: pid}) do | ||
GenMix.call(flow, pid) | ||
end | ||
|
||
def stop(%__MODULE__{gen_mix: mix}), do: GenMix.stop(mix) | ||
def stop(%__MODULE__{pid: pid, sup_pid: sup_pid}), do: GenMix.stop(pid, sup_pid) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,48 @@ | ||
defmodule Strom.Splitter do | ||
alias Strom.GenMix | ||
|
||
defstruct [:gen_mix, :input, :partitions, :opts, :flow_pid, :sup_pid] | ||
|
||
def new(input, partitions, opts \\ []) do | ||
unless is_map(partitions) and map_size(partitions) > 0 do | ||
raise "Branches in splitter must be a map, given: #{inspect(partitions)}" | ||
end | ||
|
||
%Strom.Splitter{input: input, partitions: partitions, opts: opts} | ||
end | ||
|
||
def start(args \\ []) | ||
|
||
def start(%__MODULE__{opts: opts, flow_pid: flow_pid, sup_pid: sup_pid}) do | ||
gen_mix = %GenMix{opts: opts, flow_pid: flow_pid, sup_pid: sup_pid} | ||
GenMix.start(gen_mix) | ||
end | ||
|
||
def start(opts) when is_list(opts) do | ||
GenMix.start(opts) | ||
defstruct pid: nil, | ||
input: nil, | ||
outputs: [], | ||
opts: [], | ||
flow_pid: nil, | ||
sup_pid: nil | ||
|
||
def new(input, outputs) when is_list(outputs) or (is_map(outputs) and map_size(outputs)) > 0 do | ||
%Strom.Splitter{input: input, outputs: outputs} | ||
end | ||
|
||
def call(flow, %__MODULE__{gen_mix: mix}, name, partitions) when is_list(partitions) do | ||
inputs = %{name => fn _el -> true end} | ||
def start( | ||
%__MODULE__{input: input, outputs: outputs, flow_pid: flow_pid, sup_pid: sup_pid} = | ||
splitter, | ||
opts \\ [] | ||
) do | ||
inputs = %{input => fn _el -> true end} | ||
|
||
outputs = | ||
Enum.reduce(partitions, %{}, fn name, acc -> | ||
Map.put(acc, name, fn _el -> true end) | ||
end) | ||
|
||
GenMix.call(flow, mix, inputs, outputs) | ||
if is_list(outputs) do | ||
Enum.reduce(outputs, %{}, fn name, acc -> | ||
Map.put(acc, name, fn _el -> true end) | ||
end) | ||
else | ||
outputs | ||
end | ||
|
||
gen_mix = %GenMix{ | ||
inputs: inputs, | ||
outputs: outputs, | ||
opts: opts, | ||
flow_pid: flow_pid, | ||
sup_pid: sup_pid | ||
} | ||
|
||
{:ok, pid} = GenMix.start(gen_mix) | ||
%{splitter | pid: pid, opts: opts} | ||
end | ||
|
||
def call(flow, %__MODULE__{gen_mix: mix}, name, partitions) when is_map(partitions) do | ||
inputs = %{name => fn _el -> true end} | ||
GenMix.call(flow, mix, inputs, partitions) | ||
def call(flow, %__MODULE__{pid: pid}) do | ||
GenMix.call(flow, pid) | ||
end | ||
|
||
def stop(%__MODULE__{gen_mix: mix}), do: GenMix.stop(mix) | ||
def stop(%__MODULE__{pid: pid, sup_pid: sup_pid}), do: GenMix.stop(pid, sup_pid) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters