RPC call from server to client

Hi !

Could someone explain me why these three situations work/don’t work ?

I’ve got an extension for VerticalLayout called TMarkerExtension - it draws something on it (using Canvas) and provides ClientRPC interface(TMarkerClientRPC) with two example functions :

  • public void setTimeRatioFactor(double _trFactor);
  • public void foo();
    They are implemented in constructor of TMarkerConnector, setTimeRatioFactor just assigns _trFactor to variable trFactor (member of TMarkerConnector), foo only calls Window.alert(“foo”) - quite simple right ?
    I also added on client side click handler to print value of trFactor on my Canvas.

Moreover there is a ServerRPC interface(TMarkerRPC) where I put one function :

  • public void getTrFactor();
    Its implementation looks like this :
    {
    getRpcProxy(TMarkerClientRPC.class).setTimeRatioFactor(newTrFactorValue); // newTrFactorValue changes by other button click
    getRpcProxy(TMarkerClientRPC.class).foo();
    }
    And it’s properly registered in TMarkerExtension construtor.

And now these three situations :

  1. Somewhere on the page I have a button with ClickListener that makes RPC calls :
    {
    getRpcProxy(TMarkerClientRPC.class).foo();
    getRpcProxy(TMarkerClientRPC.class).setTimeRatioFactor(2);
    }
    In Chrome console I can see messages:
    INFO: Server to client RPC call: 335:pl.waw.itl.vaadineditor.core.widgetset.client.markercomponent.TMarkerClientRPC.foo()
    INFO: Server to client RPC call: 335:pl.waw.itl.vaadineditor.core.widgetset.client.markercomponent.TMarkerClientRPC.setTimeRatioFactor([2]
    )
    but nothing happens more - alert window doesn’t appear and value of trFactor on client side doesn’t change(I print that value on Canvas when I click somewhere on layout (…) )

  2. I changed client side click handler a little bit - it calls rpc.getTrFactor() and then it prints trFactor value - now it works like a charm, alert window prints “foo” and trFactor changes as it should.

  3. Using shared state mechanism - trFactor changes properly.

Why does it behave like this ?

I have similar problem. Anyone?

I’m not really sure what’s going on in your code. Could you provide a complete but minimal test application?

ok, here you are, as simple as possible :slight_smile:


http://pastebin.com/ahB6y2H0

calling (3) doesn’t work
state change (5) works
letting go of mouse button (1) works too

summing up
state change from serve side → client side (5)
call from client side → server side → client side (1) - works
call from server side → client side (3) - doesn’t work - why? why? why ?

Thanks, although I’d have very much preferred something compilable.

Anyway, the problem is that you’re calling the TimelineComp panel’s getRpcProxy() method to get a proxy for the extension’s RPC. This will end up invoking the RPC for the panel, not the extension, after all there’s no info whatsoever at the call site about which extension instance you want. The corresponding client-side PanelConnector instance, of course, does not have an implementation for that RPC registered. Because of the way the client-side RPC handling is implemented, this ends up being simply a no-op instead of an error condition of some sort.

The takeaway is that RPCs are an implementation detail and are not meant to be directly invoked from outside the component or extension to which the RPC belongs; instead you should write an appropriate public API. It would be nice if this mistake could be automatically prevented somehow, though.

Opened ticket
#13051
.