caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* hydro: is server-to-server call possible?
@ 2009-04-09 10:42 Vsevolod Fedorov
  2009-04-22 14:02 ` Gerd Stolpmann
  0 siblings, 1 reply; 2+ messages in thread
From: Vsevolod Fedorov @ 2009-04-09 10:42 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: caml-list

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?

Thank you.

Vsevolod (sevaatwork@mail.ru)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: hydro: is server-to-server call possible?
  2009-04-09 10:42 hydro: is server-to-server call possible? Vsevolod Fedorov
@ 2009-04-22 14:02 ` Gerd Stolpmann
  0 siblings, 0 replies; 2+ messages in thread
From: Gerd Stolpmann @ 2009-04-22 14:02 UTC (permalink / raw)
  To: Vsevolod Fedorov; +Cc: caml-list


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
------------------------------------------------------------



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-22 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-09 10:42 hydro: is server-to-server call possible? Vsevolod Fedorov
2009-04-22 14:02 ` Gerd Stolpmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).