orber_env.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,444 行 · 第 1/4 页

ERL
1,444
字号
%%-----------------------------------------------------------------configure(Key, Value) when atom(Key) ->    configure(Key, Value, check);configure(Key, _) ->    ?EFORMAT("Given key (~p) not an atom.", [Key]).configure_override(Key, Value)  when atom(Key) ->    configure(Key, Value, loaded);configure_override(Key, _) ->    ?EFORMAT("Given key (~p) not an atom.", [Key]).%%-----------------------------------------------------------------%% function : multi_configure%% Arguments: %% Returns  : %% Exception: %% Effect   : %%-----------------------------------------------------------------multi_configure(KeyValueList) when list(KeyValueList) ->    case orber_tb:is_loaded() of	false ->	    application:load(orber),	    multi_configure_helper(KeyValueList, loaded);	true ->	    case orber_tb:is_running() of		false ->		    multi_configure_helper(KeyValueList, loaded);		true ->		    multi_configure_helper(KeyValueList, running)	    end    end;multi_configure(KeyValueList) ->    ?EFORMAT("Given configuration parameters not a Key-Value-pair list: ~p", 	     [KeyValueList]).multi_configure_helper([], _) ->    ok;multi_configure_helper([{Key, Value}|T], Status) ->    configure(Key, Value, Status),    multi_configure_helper(T, Status);multi_configure_helper([What|_], _) ->    ?EFORMAT("Incorrect configuration parameters supplied: ~p", [What]).%%------ Keys we can update at any time -----%% Initial Services Referencesconfigure(orbDefaultInitRef, String, Status) when list(String) ->    do_configure(orbDefaultInitRef, String, Status);configure(orbDefaultInitRef, undefined, Status) ->    do_configure(orbDefaultInitRef, undefined, Status);configure(orbInitRef, String, Status) when list(String) ->    do_configure(orbInitRef, String, Status);configure(orbInitRef, undefined, Status) ->    do_configure(orbInitRef, undefined, Status);%% IIOP-versionconfigure(giop_version, {1, 0}, Status) ->    do_configure(giop_version, {1, 0}, Status);configure(giop_version, {1, 1}, Status) ->    do_configure(giop_version, {1, 1}, Status);configure(giop_version, {1, 2}, Status) ->    do_configure(giop_version, {1, 2}, Status);%% configure 'iiop_timout' will only have effect on new requests.configure(iiop_timeout, infinity, Status) ->    do_configure(iiop_timeout, infinity, Status);configure(iiop_timeout, Value, Status) when integer(Value), Value =< 1000000 ->    do_configure(iiop_timeout, Value, Status);%% Backlogconfigure(iiop_backlog, Value, Status) when integer(Value), Value >= 0 ->    do_configure(iiop_backlog, Value, Status);%% configure 'iiop_in_keepalive' will only have effect on new connections.configure(iiop_in_keepalive, true, Status) ->    do_configure(iiop_in_keepalive, true, Status);configure(iiop_in_keepalive, false, Status) ->    do_configure(iiop_in_keepalive, false, Status);%% configure 'iiop_out_keepalive' will only have effect on new connections.configure(iiop_out_keepalive, true, Status) ->    do_configure(iiop_out_keepalive, true, Status);configure(iiop_out_keepalive, false, Status) ->    do_configure(iiop_out_keepalive, false, Status);%% configure 'iiop_connection_timout' will only have effect on new connections.configure(iiop_connection_timeout, infinity, Status) ->    do_configure(iiop_connection_timeout, infinity, Status);configure(iiop_connection_timeout, Value, Status) when integer(Value), Value =< 1000000 ->    do_configure(iiop_connection_timeout, Value, Status);%% configure 'iiop_in_connection_timout' will only have effect on new connections.configure(iiop_in_connection_timeout, infinity, Status) ->    do_configure(iiop_in_connection_timeout, infinity, Status);configure(iiop_in_connection_timeout, Value, Status) when integer(Value), Value =< 1000000 ->    do_configure(iiop_in_connection_timeout, Value, Status);%% configure 'iiop_setup_connection_timeout' will only have effect on new connections.configure(iiop_setup_connection_timeout, infinity, Status) ->    do_configure(iiop_setup_connection_timeout, infinity, Status);configure(iiop_setup_connection_timeout, Value, Status) when integer(Value) ->    do_configure(iiop_setup_connection_timeout, Value, Status);%% configure 'iiop_max_fragments' will only have effect on new connections.configure(iiop_max_fragments, infinity, Status) ->    do_configure(iiop_max_fragments, infinity, Status);configure(iiop_max_fragments, Value, Status) when integer(Value), Value > 0 ->    do_configure(iiop_max_fragments, Value, Status);%% configure 'iiop_max_in_requests' will only have effect on new connections.configure(iiop_max_in_requests, infinity, Status) ->    do_configure(iiop_max_in_requests, infinity, Status);configure(iiop_max_in_requests, Value, Status) when integer(Value), Value > 0 ->    do_configure(iiop_max_in_requests, Value, Status);%% configure 'iiop_max_in_connections' will only have effect on new connections.configure(iiop_max_in_connections, infinity, Status) ->    do_configure(iiop_max_in_connections, infinity, Status);configure(iiop_max_in_connections, Value, Status) when integer(Value), Value > 0 ->    do_configure(iiop_max_in_connections, Value, Status);%% Garbage Collect the object keys DB.configure(objectkeys_gc_time, infinity, Status) ->    do_configure(objectkeys_gc_time, infinity, Status);configure(objectkeys_gc_time, Value, Status) when integer(Value), Value =< 1000000 ->    do_configure(objectkeys_gc_time, Value, Status);%% Orber debug printoutsconfigure(orber_debug_level, Value, Status) when integer(Value) ->    do_configure(orber_debug_level, Value, Status);%%------ Keys we cannot change if Orber is running -----%% Set the listen portconfigure(iiop_port, Value, Status) when integer(Value) ->    do_safe_configure(iiop_port, Value, Status);%% Set the NAT listen portconfigure(nat_iiop_port, Value, Status) when integer(Value), Value > 0 ->    do_safe_configure(nat_iiop_port, Value, Status);configure(nat_iiop_port, {local, Value1, Value2}, Status) when integer(Value1), 							       Value1 > 0,							       list(Value2) ->    do_safe_configure(nat_iiop_port, {local, Value1, Value2}, Status);%% Set Maximum Packet Sizeconfigure(iiop_packet_size, Max, Status) when integer(Max), Max > 0 ->    do_safe_configure(iiop_packet_size, Max, Status);%% IIOP interceptorsconfigure(interceptors, Value, Status) when tuple(Value) ->    do_safe_configure(interceptors, Value, Status);%% Local interceptorsconfigure(local_interceptors, Value, Status) when tuple(Value) ->    do_safe_configure(local_interceptors, Value, Status);%% Orber Domainconfigure(domain, Value, Status) when list(Value) ->    do_safe_configure(domain, Value, Status);%% Set the IP-address we should useconfigure(ip_address, Value, Status) when list(Value) ->    do_safe_configure(ip_address, Value, Status);configure(ip_address, {multiple, Value}, Status) when list(Value) ->    do_safe_configure(ip_address, {multiple, Value}, Status);configure(ip_address_local, Value, Status) when list(Value) ->    do_safe_configure(ip_address_local, Value, Status);%% Set the NAT IP-address we should useconfigure(nat_ip_address, Value, Status) when list(Value) ->    do_safe_configure(nat_ip_address, Value, Status);configure(nat_ip_address, {multiple, Value}, Status) when list(Value) ->    do_safe_configure(nat_ip_address, {multiple, Value}, Status);configure(nat_ip_address, {local, Value1, Value2}, Status) when list(Value1),								list(Value2) ->    do_safe_configure(nat_ip_address, {local, Value1, Value2}, Status);%% Set the range of ports we may use on this machine when connecting to a server.configure(iiop_out_ports, {Min, Max}, Status) when integer(Min), integer(Max) ->    do_safe_configure(iiop_out_ports, {Min, Max}, Status);%% Set the lightweight option.configure(lightweight, Value, Status) when list(Value) ->    do_safe_configure(lightweight, Value, Status);%% Configre the System Flagsconfigure(flags, Value, Status) when integer(Value) ->    do_safe_configure(flags, Value, Status);%% Configre the ACLconfigure(iiop_acl, Value, Status) when list(Value) ->    do_safe_configure(iiop_acl, Value, Status);%% SSL settings%% configure 'iiop_in_keepalive' will only have effect on new connections.configure(iiop_ssl_in_keepalive, true, Status) ->    do_configure(iiop_ssl_in_keepalive, true, Status);configure(iiop_ssl_in_keepalive, false, Status) ->    do_configure(iiop_ssl_in_keepalive, false, Status);%% configure 'iiop_ssl_out_keepalive' will only have effect on new connections.configure(iiop_ssl_out_keepalive, true, Status) ->    do_configure(iiop_ssl_out_keepalive, true, Status);configure(iiop_ssl_out_keepalive, false, Status) ->    do_configure(iiop_ssl_out_keepalive, false, Status);configure(iiop_ssl_accept_timeout, infinity, Status) ->    do_configure(iiop_ssl_accept_timeout, infinity, Status);configure(iiop_ssl_accept_timeout, Value, Status) when integer(Value), Value >= 0 ->    do_configure(iiop_ssl_accept_timeout, Value, Status);configure(secure, ssl, Status) ->    do_safe_configure(secure, ssl, Status);configure(iiop_ssl_ip_address_local, Value, Status) when list(Value) ->    do_safe_configure(iiop_ssl_ip_address_local, Value, Status);configure(iiop_ssl_backlog, Value, Status) when integer(Value), Value >= 0 ->    do_safe_configure(iiop_ssl_backlog, Value, Status);configure(nat_iiop_ssl_port, Value, Status) when integer(Value), Value > 0 ->    do_safe_configure(nat_iiop_ssl_port, Value, Status);configure(nat_iiop_ssl_port, {local, Value1, Value2}, Status) when integer(Value1), 								   Value1 > 0,								   list(Value2) ->    do_safe_configure(nat_iiop_ssl_port, {local, Value1, Value2}, Status);configure(iiop_ssl_port, Value, Status) when integer(Value) ->    do_safe_configure(iiop_ssl_port, Value, Status);configure(ssl_server_certfile, Value, Status) when list(Value) ->    do_safe_configure(ssl_server_certfile, Value, Status);configure(ssl_server_certfile, Value, Status) when atom(Value) ->    do_safe_configure(ssl_server_certfile, atom_to_list(Value), Status);configure(ssl_client_certfile, Value, Status) when list(Value) ->    do_safe_configure(ssl_client_certfile, Value, Status);configure(ssl_client_certfile, Value, Status) when atom(Value) ->    do_safe_configure(ssl_client_certfile, atom_to_list(Value), Status);configure(ssl_server_verify, Value, Status) when integer(Value) ->    do_safe_configure(ssl_server_verify, Value, Status);configure(ssl_client_verify, Value, Status) when integer(Value) ->    do_safe_configure(ssl_client_verify, Value, Status);configure(ssl_server_depth, Value, Status) when integer(Value) ->    do_safe_configure(ssl_server_depth, Value, Status);configure(ssl_client_depth, Value, Status) when integer(Value) ->    do_safe_configure(ssl_client_depth, Value, Status);configure(ssl_server_cacertfile, Value, Status) when list(Value) ->    do_safe_configure(ssl_server_cacertfile, Value, Status);configure(ssl_server_cacertfile, Value, Status) when atom(Value) ->    do_safe_configure(ssl_server_cacertfile, atom_to_list(Value), Status);configure(ssl_client_cacertfile, Value, Status) when list(Value) ->    do_safe_configure(ssl_client_cacertfile, Value, Status);configure(ssl_client_cacertfile, Value, Status) when atom(Value) ->    do_safe_configure(ssl_client_cacertfile, atom_to_list(Value), Status);configure(ssl_client_password, Value, Status) when list(Value) ->    do_safe_configure(ssl_client_password, Value, Status);configure(ssl_client_password, Value, Status) when atom(Value) ->    do_safe_configure(ssl_client_password, atom_to_list(Value), Status);configure(ssl_client_keyfile, Value, Status) when list(Value) ->    do_safe_configure(ssl_client_keyfile, Value, Status);configure(ssl_client_keyfile, Value, Status) when atom(Value) ->    do_safe_configure(ssl_client_keyfile, atom_to_list(Value), Status);configure(ssl_server_password, Value, Status) when list(Value) ->    do_safe_configure(ssl_server_password, Value, Status);configure(ssl_client_password, Value, Status) when atom(Value) ->    do_safe_configure(ssl_server_password, atom_to_list(Value), Status);configure(ssl_server_keyfile, Value, Status) when list(Value) ->    do_safe_configure(ssl_server_keyfile, Value, Status);configure(ssl_server_keyfile, Value, Status) when atom(Value) ->    do_safe_configure(ssl_server_keyfile, atom_to_list(Value), Status);configure(ssl_server_ciphers, Value, Status) when list(Value) ->    do_safe_configure(ssl_server_ciphers, Value, Status);configure(ssl_server_ciphers, Value, Status) when atom(Value) ->    do_safe_configure(ssl_server_ciphers, atom_to_list(Value), Status);configure(ssl_client_ciphers, Value, Status) when list(Value) ->    do_safe_configure(ssl_client_ciphers, Value, Status);configure(ssl_client_ciphers, Value, Status) when atom(Value) ->    do_safe_configure(ssl_client_ciphers, atom_to_list(Value), Status);configure(ssl_client_cachetimeout, Value, Status) when integer(Value), Value > 0 ->    do_safe_configure(ssl_client_cachetimeout, Value, Status);configure(ssl_server_cachetimeout, Value, Status) when integer(Value), Value > 0 ->    do_safe_configure(ssl_server_cachetimeout, Value, Status);configure(Key, Value, _) ->    ?EFORMAT("Bad configuration parameter: {~p, ~p}", [Key, Value]).%% This function may be used as long as it is safe to change a value at any time.do_configure(Key, Value, check) ->    case orber_tb:is_loaded() of	false ->	    application:load(orber),	    application:set_env(orber, Key, Value);	true ->	    application:set_env(orber, Key, Value)    end;do_configure(Key, Value, _) ->    application:set_env(orber, Key, Value).%% This function MUST(!!) be used when we cannot change a value if Orber is running.do_safe_configure(_, _, running) ->    exit("Orber already running, the given key may not be updated!");do_safe_configure(Key, Value, check) ->    case orber_tb:is_loaded() of	false ->	    application:load(orber),	    application:set_env(orber, Key, Value);	true ->	    case orber_tb:is_running() of		false ->		    application:set_env(orber, Key, Value);		true ->		    ?EFORMAT("Orber already running. {~p, ~p} may not be updated!",			     [Key, Value])	    end    end;do_safe_configure(Key, Value, loaded) ->    application:set_env(orber, Key, Value).%%-----------------------------------------------------------------%% Internal functions%%-----------------------------------------------------------------%%-----------------------------------------------------------------%% Server functions%%-----------------------------------------------------------------init(_Opts) ->    {ok, #env{acl = orber_acl:init_acl(iiop_acl()),	      parameters = init_env()}}.terminate(_Reason, _State) ->	    ok.handle_call(_, _From, State) ->    {reply, ok, State}.handle_cast(_, State) ->    {noreply,  State}.handle_info(_, State) ->    {noreply,  State}.code_change(_OldVsn, State, _Extra) ->    {ok, State}.%%-----------------------------------------------------------------%% function : env%% Arguments: %% Returns  : %% Exception: %% Effect   : Used when Key always exists (Default Value)%%-----------------------------------------------------------------env(Key) ->    [#parameters{value = Val}] = ets:lookup(?ENV_DB, Key),    Val.%%-----------------------------------------------------------------%% function : init_env%% Arguments: %% Returns  : %% Exception: %% Effect   : %%-----------------------------------------------------------------init_env() ->    application:load(orber),    DB = ets:new(?ENV_DB, [set, public, named_table, {keypos, 2}]),%    init_env(?ENV_KEYS),    DB.%init_env([{H,D}|T]) ->%    case application:get_env(orber, H) of%	{ok, V} ->%	    ets:insert(?ENV_DB, #parameters{key = H, value = V, flags = 0}),%	    init_env(T);%	_ ->%	    ets:insert(?ENV_DB, #parameters{key = H, value = D, flags = 0}),%	    init_env(T)%    end;%init_env([H|T]) ->%    case application:get_env(orber, H) of%	{ok, V} ->%	    ets:insert(?ENV_DB, #parameters{key = H, value = V, flags = 0}),%	    init_env(T);%	_ ->%	    ets:insert(?ENV_DB, #parameters{key = H, value = undefined, flags = 0}),%	    init_env(T)%    end;%init_env([]) ->%    ok.%%-----------------------------------------------------------------%%------------- END OF MODULE -------------------------------------%%-----------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?