#6 ✓resolved
Rusty Klophaus

[TODO] Make Nitrogen follow OTP Principles

Reported by Rusty Klophaus | December 28th, 2008 @ 06:22 PM

Comments and changes to this ticket

  • MS

    MS December 29th, 2008 @ 03:18 AM

    • State changed from “new” to “open”
    • Assigned user set to “MS”
  • MS

    MS December 29th, 2008 @ 05:42 AM

    • Title changed from “Make Nitrogen follow OTP Principles” to “[TODO] Make Nitrogen follow OTP Principles”
  • Rusty Klophaus

    Rusty Klophaus December 29th, 2008 @ 09:35 AM

    • Tag set to feature, otp

    I think we should create a separate application for each Nitrogen site. Inside the .app file, we would store the Port, DocRoot, and some of the stuff that's currently in wf_global.erl, including the signkey and session timeout.

    Then, inside the mysite_app.erl file, there would be:

    • The normal application start and stop functions (this gives a good place to start the ActiveState processes)

    • An optional route(Path) function. This takes the incoming request path and turns it into {AtomModule, ExtraPathInfo}. If this is present then it is used. If not, or if it returns undefined, then wf_utils:path_to_module(Path) is called instead. This gives simple routing support to Nitrogen.

    • An optional request(Module) function pulled from wf_global.erl. This function is called at the start of a request and returns ok if the request should proceed. If the request should not proceed, then it can redirect or spit out content.

    That seems the cleanest to me. Any way to make it cleaner?

  • Jón Grétar Borgþórsson

    Jón Grétar Borgþórsson December 29th, 2008 @ 10:13 AM

    I think one should rather think of an Nitrogen supervisor rather than a Nitrogen application. That can then be in return be included in an application.

    That makes it look nice both when someone makes a pure Nitrogen web and also when people use Nitrogen as a small part of a larger app. And it sounds a bit more OTP.

    Nitrogen is at the moment the only web framework that is so easily embeddable in a larger application that is not web focused. So even though that is not the focus of Nitrogen to do that it would be nice to still leave that option as something easily done.

  • MS

    MS December 29th, 2008 @ 07:50 PM

    first "proof of concept" implementation: http://github.com/zeitgeist/nitr...

    examples of startup calls:

    • boot nitrogen with standard platform type: erl -pa ebin -pa .. -pa ../ebin -boot nitrogen

    • boot nitrogen with mochiweb as platform:

    1) erl -pa ebin -pa ../../mochiweb/ebin -pa .. -pa ../ebin -boot nitrogen_mochiweb

    2) erl -pa ebin -pa ../../mochiweb/ebin -pa .. -pa ../ebin -boot nitrogen -nitrogen platform mochiweb_helper

    Code is here:

    http://github.com/zeitgeist/nitr...

    Please integrate the code.

    Regarding integration: there is a supervisor "nitrogen_sup". The integration of nitrogen into the webplatform used has to be done by the integrator, though.

  • Rusty Klophaus

    Rusty Klophaus December 29th, 2008 @ 10:11 PM

    There is still some investigation to do in the start functions of
    mochiweb_helper, yaws_helper, and inets_helper.

    To be properly OTP-ifiable, the start functions in these modules need
    to "create and link to the child process, and should return {ok,Child}
    or {ok,Child,Info} where Child is the pid of the child process and
    Info an arbitrary term which is ignored by the supervisor." (http://erlang.org/doc/man/superv... )

    On Dec 29, 2008, at 7:50 PM, Lighthouse wrote:

  • MS

    MS December 30th, 2008 @ 03:35 AM

    You are absolutely right.

    It didn't mean the task was done (it is still open). I have started to implement what you mention, but had to take a first look into the frameworks you use (I haven't used mochiweb before).

  • MS

    MS December 30th, 2008 @ 04:01 AM

    inets is not integrateable into nitrogen's supervision tree. inets:start() returns 'ok' -- and if you look at inets' supervision tree then, you see inside inets' supervision tree get the processes started. The same applies to yaws.

    Mochiweb on the other hand is easily integrateable into nitrogen's supervision tree.

    All in all: there is no generic way to integrate all the different platforms into nitrogen. IMHO the whole OTP-related code feels more like a hack than everything else.

  • MS

    MS December 30th, 2008 @ 04:02 AM

    just pushed 9da7edbcf9e772462d97b64ba07e75a6c5f798b1 into nitrogen-activestate/zg-otpify

  • MS

    MS January 3rd, 2009 @ 04:18 PM

    • State changed from “open” to “resolved”
    • Assigned user changed from “MS” to “Rusty Klophaus”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Nitrogen Web Framework for Erlang

Tags