Hello All.<br>I have tried without success to be able to update my running applications. The code below is a very simple example in which there is a loop, that will always call itself with ?MODULE:loop(L) which according to the documentation should always call the latest version of itself, but this is what happens:<br><br>1) I start the app with test1:start().<br>2) I compile it and send some message to it, everything works<br>3) I repeat step 2 and the program fails<br><br>Erlang seems to have upgraded one version and retains still one old version in step 2), but in step 3) it kicks out the old code and terminates my program. What I do not understand is why does the running application NOT upgrade itself, as far as I get it, the ?MODULE:loop(L) should cause the program to load its latest version, but it does not, the running application stays in the old version and given that Erlang retains 2 versions in memory whenever a 3rd pops up, it terminates
the first version. The only way around it seems to be that when you REALLY want to upgrade your code, you are required to spawn a new version and pass the current parameters to that loop. <br><br>Question: Is there a better way to do it ?? Why does ?MODULE:loop(L) not update the running loop, if it doesn't, than this functionality is useless or isn't it (or maybe I miss its working entirely) ?? The only other way seems to be doing it OTP (which at this I would like to avoid) and write all data, that the loop would hold (this code has been removed from example) to mnesia, but this scheme would complicate everything quite a bit, when I require to process data to/from client sockets.<br><br>I want to be able to continously update my application as my development advances on multiple nodes without ever stopping it or disconnecting neither services, processes or clients.<br><br>Best
regards,<br>Bo<br>-------------------------------------------------------------------------------<br>-module(test1).<br>-define(VERSION, "0.0.11A").<br>-compile(export_all).<br><br>stop() -><br> test ! quit.<br>version() -><br> test ! version.<br>start() -><br> start_server([]).<br>start(L) -><br> start_server(L).<br><br>start_server(L) -><br> process_flag(trap_exit, true),<br> register(test, <br> spawn(fun() -><br> process_flag(trap_exit, true),<br> Val= (catch ?MODULE:server_loop([L])),<br> io:format("Server terminated with:~p~n",[Val])<br> end)).<br><br>server_loop(L)
-><br> receive<br> version -><br> io:format("Server Version: ~p~n",[?VERSION]),<br> ?MODULE:server_loop(L);<br> quit -><br> io:format("Server shutting down=~p~n",[quit]),<br> {ok, true}; <br> upgrade -><br> io:format("Server upgrading ...~n"),<br> unregister(test),<br> ?MODULE:start(L), <br> {ok, true}; <br> Msg -><br>
io:format("Server received Msg=~p~n",[Msg]),<br> ?MODULE:server_loop(L)<br> end.<br><br><p>
<hr size=1>Be a better Heartthrob. <a href="http://us.rd.yahoo.com/evt=48255/*http://answers.yahoo.com/dir/_ylc=X3oDMTI5MGx2aThyBF9TAzIxMTU1MDAzNTIEX3MDMzk2NTQ1MTAzBHNlYwNCQUJwaWxsYXJfTklfMzYwBHNsawNQcm9kdWN0X3F1ZXN0aW9uX3BhZ2U-?link=list&sid=396545433">Get better relationship answers </a>from someone who knows.<br>Yahoo! Answers - Check it out.