You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Jan Willem Janssen <ja...@luminis.eu> on 2012/10/10 09:56:24 UTC

Use of Future in SPI

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I've been familiarizing myself with the Shindig SPI for a while now
and keep wondering about the use of Future's for the results of most
of the SPI interfaces.
What strikes me most is that an SPI-implementation has to think about
the possible asynchronous nature of its method calls (which, as it
currently boils down, is never used in the current codebase). Aside
that, it makes all the supporting code of the SPI very complex and
hard to debug.

Anybody care to elaborate about the rationale behind this?

- -- 
Met vriendelijke groeten | Kind regards

Jan Willem Janssen | Software Architect
+31 631 765 814

/My world is:/

Luminis Technologies B.V.
IJsselburcht 3
6825 BS  Arnhem
+31 88 586 46 30

http://www.luminis-technologies.com
http://www.luminis.eu

KvK (CoC) 09 16 28 93
BTW (VAT) NL8169.78.566.B.01
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQdSooAAoJEKF/mP2eHDc4BHUP/3azQPhqjdSQq01LjKG4K1vc
Wi0gEoisR2/OUclkzNynnX7woP02J3S/Ct8XRe6kBp/rQOAEi2LPsmN3n0WJVlDI
6yIbEyrVeJQorvyEFAtXM4o3pz/pp03bLoo8URi1v7/79I6UoTckQpWk5vECFzVU
Kq2wq5glpsiRCDdAE7LmI7RQDny1h5L0Lek56lInGNltT4fm3JLsPBm2KUPSd9ap
CEcWO5wVIYxSzvVzEvHW1/vCv/hWb5ZCp8V0Zh96tRlQJuaO29OFkAGrEEjJrPsz
fTwVoxgkN+JHVzbMhKgW9uPxuV30r1y1Sb9LIbgbdyOwJUCPjuMLtvGOVezrUQmU
IcJ/sgHB7cujXwvBeZnPW71dnBhoBh1tHGUFHVBrBWJcwHH3MoOpDYGYcuGG8ffw
nYP/xRGkHGYHQqEWF2Oo/XWDTh+pSwfftWUeNb8lSiuUbz0ljRiCoQ5HZWmyQQfw
UehNv+YeLZPs87p6GwI4S4gODPhJ8kLasZSS78OrES9PFi86ZCfnDGyk14kHqEdP
XGP0LxoUzvA9QLX4uJA2uJngmBpUKoOisKA0ds6KD0RAIgfG0iTOct6TlUJZDvgE
KbnCmRkVI0YPyrHue2Ay3qZ7wqW5R4zHq7TOdsxTyc/bFMTYDzyMFanfOSGkEQPQ
nrdnaMnYbWZMj/IJhKsY
=121v
-----END PGP SIGNATURE-----


Re: Use of Future in SPI

Posted by Jan Willem Janssen <ja...@luminis.eu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/10/12 12:06 PM, Paul Lindner wrote:
> Look at the usage of CompletionService in shindig to see how this
> is useful.
> 
> Sure you *could* wrap every API call in a Callable, however that
> would lead to extra thread consumption.
> 
> Another benefit of a Future<..> api is that you can execute a small
> amount of code on the request thread to set up your Future.  This
> allows for ThreadLocal use on the servlet thread, request scoped
> guice injection, and more.
> 
> I agree that it's a bit ugly, and you can get if you need to take
> the output of a Future and pass it to the input of another it gets
> confusing (even with Futures.transform(...) from guava)
> 

I'm not sure we're on the same track here. I do not oppose against the
use of Future, but question its use in the SPI-parts of Shindig, like
PersonService.

- -- 
Met vriendelijke groeten | Kind regards

Jan Willem Janssen | Software Architect
+31 631 765 814

/My world is:/

Luminis Technologies B.V.
IJsselburcht 3
6825 BS  Arnhem
+31 88 586 46 30

http://www.luminis-technologies.com
http://www.luminis.eu

KvK (CoC) 09 16 28 93
BTW (VAT) NL8169.78.566.B.01
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQdVujAAoJEKF/mP2eHDc4KwcP/21/2Dn2iUrCZNu5n45PPNZX
LbzyhQOxQNjMr+nbrjRG/V6itM01GEFA8h2uEo0BmxbbbEogP6SUvxSJ8At2AA59
Nf4sYGY+ImX1LjFRz216/s32EWiWjeSTJ61JEygFQt78iT8M27lAZt1cwDCz4m5U
WgjCOSrj9VMFitQj75suwjeMvaI39wxiOje4O5Ud2GfAeO7dXYn0sZqEeCF4ddMU
aFDhei8m7aHO8M9gQ6tmPyv0PgUuG1u4YsbxNZKaOCErL8vFNv8fofKEgKm1zTFp
A41TlWJM0dxhrKiWGwpMB3mpwT2gAAPeJJluuyeWfB0CzAchelZs4/Z03I5v7cZS
z1av8VmQO/SWOjtowuRw++j7qpoYyozScLzuMj1kTsA++UEIt1j1vkb93YXdicBh
YoC/7JtGf9MFgdhEOg/AtxOyC71HwabjhoEoB7cp9ZKpcEpvvj1Pjv42s7XtgzO/
QiWyS4rbPFeymuykk2xay4T1DGqSJsW+XjqjLe7YqsqnB7i3DMtdwwR8gA7ZdZLs
ePCULEX5QCbzdzmtPEfN/Y+dGY8awjKoR90+6S6QMexuBQOWo96a7qLsgTpW1VI8
JzKE5xB1mh1Ip9qsvlYk58x0ib7KLV4CgyMuuC1XmeNJRntVYuRsH8NAbCJyhRyk
P7HAYcUVjHq5Lvq8iT8h
=miJf
-----END PGP SIGNATURE-----


Re: Use of Future in SPI

Posted by Paul Lindner <li...@inuus.com>.
Look at the usage of CompletionService in shindig to see how this is useful.

Sure you *could* wrap every API call in a Callable, however that would lead
to extra thread consumption.

Another benefit of a Future<..> api is that you can execute a small amount
of code on the request thread to set up your Future.  This allows for
ThreadLocal use on the servlet thread, request scoped guice injection, and
more.

I agree that it's a bit ugly, and you can get if you need to take the
output of a Future and pass it to the input of another it gets confusing
(even with Futures.transform(...) from guava)


On Wednesday, October 10, 2012, Jan Willem Janssen wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 10/10/12 10:03 AM, Ian Boston wrote:
> > I will have a go since I was involved in the early SPI.
> >
> > Many of the calls in a real Social network impl are remote or over
> > links that may have IO waits. If you use Futures you can dispatch
> > them at the start of the request and collect them all at the end of
> > the request hence interleaving IO time more effectively. Obviously
> > that assumes you SPI impl is capable of being event driven.
>
> Wouldn't the interleaving be an issue of the caller (ie: Shindig)
> instead of the SPI? I mean: you can wrap the calls to your SPI in
> Futures when its desired to have interleaving. Wouldn't this give the
> same semantics?
>
>
> - --
> Met vriendelijke groeten | Kind regards
>
> Jan Willem Janssen | Software Architect
> +31 631 765 814
>
> /My world is:/
>
> Luminis Technologies B.V.
> IJsselburcht 3
> 6825 BS  Arnhem
> +31 88 586 46 30
>
> http://www.luminis-technologies.com
> http://www.luminis.eu
>
> KvK (CoC) 09 16 28 93
> BTW (VAT) NL8169.78.566.B.01
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iQIcBAEBAgAGBQJQdTAfAAoJEKF/mP2eHDc4YsYQAKIqrHbXvPNmYw6Ctt0RWOey
> I4gyI/eAiNVEjwoFLSLUzLm77pBFtikuRttPugf93w5HFWVu1Dr31WKD2NHkejQx
> JsdHaAx3XA9hSKfcqgOGgXKFKdqNdK25B1tz0v76Dc3IVa+EX85+W8CpzXYrYJVQ
> sEhvFfT8eMtkSctMNxmmmKnXllOEyrLYCSpWJ/6F8wpw6VUXrzaV5UfmfBxksU60
> 1cfvnFdT0Pu1WFQHFcyHhCqyelHNLyA6bIrz936ZMjhoWwasPLc2wRZd6bmIOm30
> 6BCtuRKeYHWBGc5jKo6GPlvVYwrgrL/CyqbOCAWTRIPxolzhEyRTFsY31UBkEgFE
> +qVei/Gh2UZBML82TnqOeDX9pZE0mXRVdlH9G8CgIH/zHPJltGmqDe4LBcGMddfP
> TeR44dvOtQ5cNRJImr8UJhLhPYyUxZBj4H61aikE6fNHKCpEWrWC4DGQ+7LYiW54
> hgXI2Xt2xJj1/PxeOpM1j8o0cVYGE1nR9mJbUE/USN8ZoYskmssFx/ucy2o6aK6I
> 5ngKJkKVrzMXJYAO3GEdcPLzSdqXfh7be/tGMKD71sbYqcPaEaGQZyD61T/5JRLd
> HC3C183Eo7oBudh7qoOUAZ09v8O9Ye1D7BvugmmNQACTLYRZZlgfHOW3tBEfMoZx
> 3oknrE5iwkMFwJAWam2f
> =utq4
> -----END PGP SIGNATURE-----
>
>

-- 
Paul Lindner -- lindner@inuus.com -- profiles.google.com/pmlindner

Re: Use of Future in SPI

Posted by Jan Willem Janssen <ja...@luminis.eu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/10/12 10:03 AM, Ian Boston wrote:
> I will have a go since I was involved in the early SPI.
> 
> Many of the calls in a real Social network impl are remote or over 
> links that may have IO waits. If you use Futures you can dispatch
> them at the start of the request and collect them all at the end of
> the request hence interleaving IO time more effectively. Obviously
> that assumes you SPI impl is capable of being event driven.

Wouldn't the interleaving be an issue of the caller (ie: Shindig)
instead of the SPI? I mean: you can wrap the calls to your SPI in
Futures when its desired to have interleaving. Wouldn't this give the
same semantics?


- -- 
Met vriendelijke groeten | Kind regards

Jan Willem Janssen | Software Architect
+31 631 765 814

/My world is:/

Luminis Technologies B.V.
IJsselburcht 3
6825 BS  Arnhem
+31 88 586 46 30

http://www.luminis-technologies.com
http://www.luminis.eu

KvK (CoC) 09 16 28 93
BTW (VAT) NL8169.78.566.B.01
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iQIcBAEBAgAGBQJQdTAfAAoJEKF/mP2eHDc4YsYQAKIqrHbXvPNmYw6Ctt0RWOey
I4gyI/eAiNVEjwoFLSLUzLm77pBFtikuRttPugf93w5HFWVu1Dr31WKD2NHkejQx
JsdHaAx3XA9hSKfcqgOGgXKFKdqNdK25B1tz0v76Dc3IVa+EX85+W8CpzXYrYJVQ
sEhvFfT8eMtkSctMNxmmmKnXllOEyrLYCSpWJ/6F8wpw6VUXrzaV5UfmfBxksU60
1cfvnFdT0Pu1WFQHFcyHhCqyelHNLyA6bIrz936ZMjhoWwasPLc2wRZd6bmIOm30
6BCtuRKeYHWBGc5jKo6GPlvVYwrgrL/CyqbOCAWTRIPxolzhEyRTFsY31UBkEgFE
+qVei/Gh2UZBML82TnqOeDX9pZE0mXRVdlH9G8CgIH/zHPJltGmqDe4LBcGMddfP
TeR44dvOtQ5cNRJImr8UJhLhPYyUxZBj4H61aikE6fNHKCpEWrWC4DGQ+7LYiW54
hgXI2Xt2xJj1/PxeOpM1j8o0cVYGE1nR9mJbUE/USN8ZoYskmssFx/ucy2o6aK6I
5ngKJkKVrzMXJYAO3GEdcPLzSdqXfh7be/tGMKD71sbYqcPaEaGQZyD61T/5JRLd
HC3C183Eo7oBudh7qoOUAZ09v8O9Ye1D7BvugmmNQACTLYRZZlgfHOW3tBEfMoZx
3oknrE5iwkMFwJAWam2f
=utq4
-----END PGP SIGNATURE-----


Re: Use of Future in SPI

Posted by Ian Boston <ie...@tfd.co.uk>.
On 10 October 2012 18:56, Jan Willem Janssen
<ja...@luminis.eu> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> I've been familiarizing myself with the Shindig SPI for a while now
> and keep wondering about the use of Future's for the results of most
> of the SPI interfaces.
> What strikes me most is that an SPI-implementation has to think about
> the possible asynchronous nature of its method calls (which, as it
> currently boils down, is never used in the current codebase). Aside
> that, it makes all the supporting code of the SPI very complex and
> hard to debug.
>
> Anybody care to elaborate about the rationale behind this?


I will have a go since I was involved in the early SPI.

Many of the calls in a real Social network impl are remote or over
links that may have IO waits. If you use Futures you can dispatch them
at the start of the request and collect them all at the end of the
request hence interleaving IO time more effectively. Obviously that
assumes you SPI impl is capable of being event driven.

If you dont want to do this, then you can use immediate futures to
ensure everything is processes as a simple sequential process.

I think that still holds true today, even if no one is using them now.

HTH
Ian

>
> - --
> Met vriendelijke groeten | Kind regards
>
> Jan Willem Janssen | Software Architect
> +31 631 765 814
>
> /My world is:/
>
> Luminis Technologies B.V.
> IJsselburcht 3
> 6825 BS  Arnhem
> +31 88 586 46 30
>
> http://www.luminis-technologies.com
> http://www.luminis.eu
>
> KvK (CoC) 09 16 28 93
> BTW (VAT) NL8169.78.566.B.01
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
>
> iQIcBAEBAgAGBQJQdSooAAoJEKF/mP2eHDc4BHUP/3azQPhqjdSQq01LjKG4K1vc
> Wi0gEoisR2/OUclkzNynnX7woP02J3S/Ct8XRe6kBp/rQOAEi2LPsmN3n0WJVlDI
> 6yIbEyrVeJQorvyEFAtXM4o3pz/pp03bLoo8URi1v7/79I6UoTckQpWk5vECFzVU
> Kq2wq5glpsiRCDdAE7LmI7RQDny1h5L0Lek56lInGNltT4fm3JLsPBm2KUPSd9ap
> CEcWO5wVIYxSzvVzEvHW1/vCv/hWb5ZCp8V0Zh96tRlQJuaO29OFkAGrEEjJrPsz
> fTwVoxgkN+JHVzbMhKgW9uPxuV30r1y1Sb9LIbgbdyOwJUCPjuMLtvGOVezrUQmU
> IcJ/sgHB7cujXwvBeZnPW71dnBhoBh1tHGUFHVBrBWJcwHH3MoOpDYGYcuGG8ffw
> nYP/xRGkHGYHQqEWF2Oo/XWDTh+pSwfftWUeNb8lSiuUbz0ljRiCoQ5HZWmyQQfw
> UehNv+YeLZPs87p6GwI4S4gODPhJ8kLasZSS78OrES9PFi86ZCfnDGyk14kHqEdP
> XGP0LxoUzvA9QLX4uJA2uJngmBpUKoOisKA0ds6KD0RAIgfG0iTOct6TlUJZDvgE
> KbnCmRkVI0YPyrHue2Ay3qZ7wqW5R4zHq7TOdsxTyc/bFMTYDzyMFanfOSGkEQPQ
> nrdnaMnYbWZMj/IJhKsY
> =121v
> -----END PGP SIGNATURE-----
>