3 Replies Latest reply on Sep 22, 2011 12:13 PM by Christian Sadilek

    Duplicate instances of RPC service are created on server-side?

    Alvin McMurdy Newbie

      I think this is a bug, but I'm still very new here.

       

      If I have a server-side class implementing an @Remote RPC interface, then

      two instances will be created on the server.  For example:

      {code}

      @Remote

      public interface RemoteRpcInterface { ... }

       

      @Service

      public class RemoteService implements RemoteRpcInterface {

        @Inject

        public RemoteService(final MessageBus bus) {

          new Exception().printStackTrace();

          ...

        }

        ...

      }

      {code}

       

      On the server, one sees two stack traces, one per instance:

      {code}

      java.lang.Exception

              at myproject.server.RemoteService.<init>(RemoteService.java:54)

              at myproject.server.RemoteService$$FastClassByGuice$$9e04afdf.newInstance(<generated>)

              ...

              at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)

              at org.jboss.errai.bus.server.service.metadata.ServiceProcessor.createRPCScaffolding(ServiceProcessor.java:225)

              at org.jboss.errai.bus.server.service.metadata.ServiceProcessor.process(ServiceProcessor.java:101)

              at org.jboss.errai.bus.server.service.bootstrap.DiscoverServices.execute(DiscoverServices.java:49)

              at org.jboss.errai.bus.server.service.bootstrap.OrderedBootstrap.execute(OrderedBootstrap.java:57)

              at org.jboss.errai.bus.server.service.ErraiServiceImpl.boostrap(ErraiServiceImpl.java:60)

              ...

              at org.jboss.errai.bus.server.servlet.AbstractErraiServlet.buildService(AbstractErraiServlet.java:132)

              at org.jboss.errai.bus.server.servlet.AbstractErraiServlet.init(AbstractErraiServlet.java:103)

              ...

      java.lang.Exception

              at myproject.server.RemoteService.<init>(RemoteService.java:54)

              at myproject.server.RemoteService$$FastClassByGuice$$9e04afdf.newInstance(<generated>)

              ...

              at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)

              at org.jboss.errai.bus.server.service.metadata.ServiceProcessor.process(ServiceProcessor.java:149)

              at org.jboss.errai.bus.server.service.bootstrap.DiscoverServices.execute(DiscoverServices.java:49)

              at org.jboss.errai.bus.server.service.bootstrap.OrderedBootstrap.execute(OrderedBootstrap.java:57)

              at org.jboss.errai.bus.server.service.ErraiServiceImpl.boostrap(ErraiServiceImpl.java:60)

              ...

              at org.jboss.errai.bus.server.servlet.AbstractErraiServlet.buildService(AbstractErraiServlet.java:132)

              at org.jboss.errai.bus.server.servlet.AbstractErraiServlet.init(AbstractErraiServlet.java:103)

              ...

      {code}

       

      Without doing git archaeology, my guess is that the bug is in ServiceProcessor.process(): at some point a bunch

      of inlined code became encapsulated into a new createRPCScaffolding() method --- but a new 'svc' local

      variable was created there, and the svc variable in ServiceProcessor.process() was no longer getting set.

      Then, 47 lines later, "if (svc == null)" evaluates to true and a second instance gets created.

       

      If this is the case, setting "svc = createRPCScaffolding(...)" should fix it (along with returning the new

      service instance from that method).

       

      If this is not a bug... then, why is two instances the correct (and surprising) behavior?