Add API for get current transaction ID
This commit is contained in:
parent
7635272fbd
commit
4c517a8147
3 changed files with 20 additions and 3 deletions
|
|
@ -1,7 +1,10 @@
|
|||
defmodule Tres.Controller do
|
||||
def controller_helpers do
|
||||
quote do
|
||||
import Tres.SwitchRegistry, only: [send_message: 2]
|
||||
import Tres.SwitchRegistry, only: [
|
||||
send_message: 2,
|
||||
get_current_xid: 1
|
||||
]
|
||||
|
||||
use Tres.Messages
|
||||
use Tres.MessageHelper
|
||||
|
|
|
|||
|
|
@ -251,6 +251,11 @@ defmodule Tres.SecureChannel do
|
|||
:keep_state_and_data
|
||||
end
|
||||
|
||||
defp handle_CONNECTED({:call, from}, :get_xid, state_data) do
|
||||
xid = State.get_transaction_id(state_data.xid)
|
||||
{:keep_state_and_data, [{:reply, from, {:ok, xid}}]}
|
||||
end
|
||||
|
||||
defp handle_CONNECTED(:cast, {:send_message, message} = action, state_data) do
|
||||
new_action_queue =
|
||||
if XACT_KV.is_empty(state_data.xact_kv_ref) do
|
||||
|
|
|
|||
|
|
@ -19,13 +19,22 @@ defmodule Tres.SwitchRegistry do
|
|||
end
|
||||
|
||||
def send_message(message, {_dpid, _aux_id} = datapath_id) do
|
||||
Registry.dispatch(__MODULE__, datapath_id, &dispatch(&1, message))
|
||||
Registry.dispatch(__MODULE__, datapath_id, &do_send_message(&1, message))
|
||||
end
|
||||
|
||||
def send_message(message, dpid) when is_binary(dpid) do
|
||||
send_message(message, {dpid, 0})
|
||||
end
|
||||
|
||||
def get_current_xid({_dpid, _aux_id} = datapath_id) do
|
||||
[{pid, _}|_] = Registry.lookup(__MODULE__, datapath_id)
|
||||
:gen_statem.call(pid, :get_xid, 1000)
|
||||
end
|
||||
|
||||
def get_current_xid(datapath_id) do
|
||||
get_current_xid({datapath_id, 0})
|
||||
end
|
||||
|
||||
def monitor(datapath_id) do
|
||||
datapath_id
|
||||
|> lookup_pid
|
||||
|
|
@ -34,7 +43,7 @@ defmodule Tres.SwitchRegistry do
|
|||
|
||||
# private function
|
||||
|
||||
defp dispatch(entries, message) do
|
||||
defp do_send_message(entries, message) do
|
||||
for {pid, _} <- entries, do: :gen_statem.cast(pid, {:send_message, message})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue