Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gerd Stolpmann <gerd@gerd-stolpmann.de>
To: Vsevolod Fedorov <sevaAtWork@mail.ru>
Cc: caml-list@yquem.inria.fr
Subject: Re: hydro: is server-to-server call possible?
Date: Wed, 22 Apr 2009 16:02:15 +0200	[thread overview]
Message-ID: <1240408935.13057.42.camel@flake.lan.gerd-stolpmann.de> (raw)
In-Reply-To: <49DDD10E.5050004@mail.ru>


Am Donnerstag, den 09.04.2009, 14:42 +0400 schrieb Vsevolod Fedorov:
> Hello!
> 
> I use Hydro implementation of the Ice protocol and stumbled upon the
> following problem:
> I need one server to make calls to another one. But I can not make a
> synchronous call because I am already inside the event loop. And I can
> not make asynchronous call because asynchronous servants seem to be
> unsupported.
> So here the question: can I do this at all? And if yes, then how?

Of course you can.

First, you can always make a synchronous call. Just create a new event
system with Unixqueue.create_unix_event_system, and throw it away after
the call is over. Of course, your server is blocked during this time.

Asynchronous servants are supported (maybe undocumented :-) ). In fact,
all servants are async, and only the "parachute" enforces a synchronous
behavior. parachute is defined by the generator like

let rec parachute =
  (fun userfn ->
    (fun emit_result -> 
      (fun emit_exn -> 
        (fun session -> 
          try ( emit_result (userfn session) )
          with
            | User_exception e -> emit_exn e
            | g -> 
                session # emit_unknown_exception
                  (Hydro_util.exn_to_string g)
        )
      )
    )
  )

(I've substituted readable variable names.)

Now, a synchronous method definition looks like:

method foo arg1 arg2 ... argN =
  parachute
    (fun session ->
        ...
        result
    )

As you see from its definition, parachute "eats up" three more arguments
and hides them from the user. You could also write

method foo arg1 arg2 ... argN emit_result emit_exn session =
  try 
    let result = ... in
    emit_result result
  with
   | User_exception e -> emit_exn e
   | g -> 
        session # emit_unknown_exception (Hydro_util.exn_to_string g)

I hope it becomes now clear how to make the method async. Just don't
call emit_result/emit_exn immediately, but later when you have the
result (or exception). Bypass parachute, whose task is to ensure that
emit_result/emit_exn is immediately called.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------



      reply	other threads:[~2009-04-22 13:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-09 10:42 Vsevolod Fedorov
2009-04-22 14:02 ` Gerd Stolpmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1240408935.13057.42.camel@flake.lan.gerd-stolpmann.de \
    --to=gerd@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=sevaAtWork@mail.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox