2
2
3
3
-behaviour (supervisor2 ).
4
4
5
- -export ([start_link /4 , init /1 , add_vhost /2 , client_init / 5 , start_vhost /5 , successfully_recovered_state /2 ]).
5
+ -export ([start_link /3 , init /1 , add_vhost /2 , client_init /5 , successfully_recovered_state /2 ]).
6
6
7
- start_link (Name , Dir , ClientRefs , StartupFunState ) ->
7
+ % % Internal
8
+ -export ([start_vhost /4 ]).
9
+
10
+ start_link (Name , ClientRefs , StartupFunState ) ->
8
11
supervisor2 :start_link ({local , Name }, ? MODULE ,
9
- [Name , Dir , ClientRefs , StartupFunState ]).
12
+ [Name , ClientRefs , StartupFunState ]).
10
13
11
- init ([Name , Dir , ClientRefs , StartupFunState ]) ->
14
+ init ([Name , ClientRefs , StartupFunState ]) ->
12
15
{ok , {{simple_one_for_one , 0 , 1 },
13
- [{rabbit_msg_store_vhost , {rabbit_msg_store_vhost_sup , start_vhost ,
14
- [Name , Dir , ClientRefs , StartupFunState ]},
16
+ [{rabbit_msg_store_vhost , {rabbit_msg_store_vhost_sup , start_vhost ,
17
+ [Name , ClientRefs , StartupFunState ]},
15
18
transient , infinity , supervisor , [rabbit_msg_store ]}]}}.
16
19
17
20
18
21
add_vhost (Name , VHost ) ->
19
22
supervisor2 :start_child (Name , [VHost ]).
20
23
21
- start_vhost (Name , Dir , ClientRefs , StartupFunState , VHost ) ->
22
- VHostName = get_vhost_name (Name , VHost ),
23
- VHostDir = get_vhost_dir ( Dir , VHost ),
24
+ start_vhost (Name , ClientRefs , StartupFunState , VHost ) ->
25
+ VHostName = vhost_store_name (Name , VHost ),
26
+ VHostDir = vhost_store_dir ( VHost ),
24
27
ok = rabbit_file :ensure_dir (VHostDir ),
25
- rabbit_msg_store :start_link (VHostName , VHostDir ,
28
+ rabbit_msg_store :start_link (VHostName , VHostDir ,
26
29
ClientRefs , StartupFunState ).
27
30
28
31
@@ -31,27 +34,29 @@ client_init(Server, Ref, MsgOnDiskFun, CloseFDsFun, VHost) ->
31
34
rabbit_msg_store :client_init (VHostName , Ref , MsgOnDiskFun , CloseFDsFun ).
32
35
33
36
maybe_start_vhost (Server , VHost ) ->
34
- VHostName = get_vhost_name (Server , VHost ),
35
- Trace = try throw (42 ) catch 42 -> erlang :get_stacktrace () end ,
37
+ VHostName = vhost_store_name (Server , VHost ),
36
38
case whereis (VHostName ) of
37
39
undefined -> add_vhost (Server , VHost );
38
40
_ -> ok
39
41
end ,
40
42
VHostName .
41
43
42
- get_vhost_name (Name , VHost ) ->
43
- VhostEncoded = encode_vhost (VHost ),
44
- binary_to_atom (<<(atom_to_binary (Name , utf8 ))/binary , " _" , VhostEncoded /binary >>, utf8 ).
44
+ vhost_store_name (Name , VHost ) ->
45
+ VhostEncoded = encode_vhost_name (VHost ),
46
+ binary_to_atom (<<(atom_to_binary (Name , utf8 ))/binary , " _" ,
47
+ VhostEncoded /binary >>,
48
+ utf8 ).
45
49
46
- get_vhost_dir (Dir , VHost ) ->
47
- VhostEncoded = encode_vhost (VHost ),
50
+ vhost_store_dir (VHost ) ->
51
+ Dir = rabbit_mnesia :dir (),
52
+ VhostEncoded = encode_vhost_name (VHost ),
48
53
binary_to_list (filename :join ([Dir , VhostEncoded ])).
49
54
50
- encode_vhost (VHost ) ->
55
+ encode_vhost_name (VHost ) ->
51
56
base64 :encode (VHost ).
52
57
53
58
successfully_recovered_state (Name , VHost ) ->
54
- VHostName = get_vhost_name (Name , VHost ),
59
+ VHostName = vhost_store_name (Name , VHost ),
55
60
rabbit_msg_store :successfully_recovered_state (VHostName ).
56
61
57
62
% force_recovery
0 commit comments