Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the GWT RPC on the Java and Android platforms, I'm currently experimenting with using gwt-syncproxy to provide Java client access to the GWT RPC methods, and I'm using Guice, Gin, and RoboGuice on their respective target platforms to inject the appropriate asynchronous service instances for the instantiated Game object.</p> <p>In the core/pom.xml for a PlayN project, I include the following dependency coordinates to support DI from Gin/Guice/RoboGuice as needed:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;javax.inject&lt;/groupId&gt; &lt;artifactId&gt;javax.inject&lt;/artifactId&gt; &lt;version&gt;1&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Then I add @Inject annotations to any fields inside of the concrete Game implementation:</p> <pre><code>public class TestGame implements Game { @Inject TestServiceAsync _testService; ... } </code></pre> <p>In the html/pom.xml, I include the dependency coordinates for Gin:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.google.gwt.inject&lt;/groupId&gt; &lt;artifactId&gt;gin&lt;/artifactId&gt; &lt;version&gt;1.5.0&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>And I create TestGameGinjector and TestGameModule classes:</p> <p><strong>TestGameGinjector.java</strong></p> <pre><code>@GinModules(TestGameModule.class) public interface TestGameGinjector extends Ginjector { TestGame getGame(); } </code></pre> <p><strong>TestGameModule.java</strong></p> <pre><code>public class TestGameModule extends AbstractGinModule { @Override protected void configure() { } } </code></pre> <p>Since at the moment, I'm only injecting the TestServiceAsync interface, I don't need to put any implementation in the TestGameModule.configure() method; Gin manages instantiation of AsyncServices for me via GWT.create().</p> <p>I then added the following to TestGame.gwt.xml</p> <pre><code>&lt;inherits name='com.google.gwt.inject.Inject'/&gt; </code></pre> <p>And finally, I made the following changes to TestGameHtml.java</p> <pre><code>public class TestGameHtml extends HtmlGame { private final TestGameGinjector _injector = GWT.create(TestGameGinjector.class); @Override public void start() { HtmlPlatform platform = HtmlPlatform.register(); platform.assetManager().setPathPrefix("test/"); PlayN.run(_injector.getGame()); } } </code></pre> <p>And this pretty much covers the HTML5 platform for PlayN.</p> <p>For the Java platform, I add the following dependency coordinates to java/pom.xml:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.gdevelop.gwt.syncrpc&lt;/groupId&gt; &lt;artifactId&gt;gwt-syncproxy&lt;/artifactId&gt; &lt;version&gt;0.4-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.google.inject&lt;/groupId&gt; &lt;artifactId&gt;guice&lt;/artifactId&gt; &lt;version&gt;3.0-rc2&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>Do note that the gwt-syncproxy project on Google Code does not contain a pom.xml. I have a <em>mavenized</em> version of gwt-syncproxy forked and available via git at <a href="https://bitbucket.org/hatboyzero/gwt-syncproxy.git" rel="noreferrer">https://bitbucket.org/hatboyzero/gwt-syncproxy.git</a>. You should be able to clone it, run <strong>mvn clean package install</strong> to get it into your local Maven repository.</p> <p>Anyways, I created a TestGameModule.java for the Java platform as follows:</p> <pre><code>public class TestGameModule extends AbstractModule { @Override protected void configure() { bind(TestServiceAsync.class).toProvider(TestServiceProvider.class); } public static class TestServiceProvider implements Provider&lt;TestServiceAsync&gt; { public TestServiceAsync get() { return (TestServiceAsync) SyncProxy.newProxyInstance( TestServiceAsync.class, Deployment.gwtWebPath(), // URL to webapp -- http://127.0.0.1:8888/testgame "test" ); } } } </code></pre> <p>And I modified TestGameJava.java as follows:</p> <pre><code>public class TestGameJava { public static void main(String[] args) { Injector _injector = Guice.createInjector(new TestGameModule()); JavaPlatform platform = JavaPlatform.register(); platform.assetManager().setPathPrefix("test/images"); PlayN.run(_injector.getInstance(TestGame.class)); } } </code></pre> <p>I went through a similar exercise with the Android platform and RoboGuice -- without going into tremendous detail, the relevant changes/snippets are as follows:</p> <p><strong>pom.xml dependencies</strong></p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.gdevelop.gwt.syncrpc&lt;/groupId&gt; &lt;artifactId&gt;gwt-syncproxy&lt;/artifactId&gt; &lt;version&gt;0.4-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.roboguice&lt;/groupId&gt; &lt;artifactId&gt;roboguice&lt;/artifactId&gt; &lt;version&gt;1.1.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.google.inject&lt;/groupId&gt; &lt;artifactId&gt;guice&lt;/artifactId&gt; &lt;version&gt;3.0-rc2&lt;/version&gt; &lt;classifier&gt;no_aop&lt;/classifier&gt; &lt;/dependency&gt; </code></pre> <p><strong>TestGameApplication.java</strong></p> <pre><code>public class TestGameApplication extends RoboApplication { @Override protected void addApplicationModules(List&lt;Module&gt; modules) { modules.add(new TestGameModule()); } } </code></pre> <p><strong>TestGameModule.java</strong></p> <pre><code>public class TestGameModule extends AbstractModule { @Override protected void configure() { bind(TestServiceAsync.class).toProvider(TestServiceProvider.class); } public static class TestServiceProvider implements Provider&lt;TestServiceAsync&gt; { public TestServiceAsync get() { return (TestServiceAsync) SyncProxy.newProxyInstance( TestServiceAsync.class, Deployment.gwtWebPath(), // URL to webapp -- http://127.0.0.1:8888/testgame "test" ); } } } </code></pre> <p><strong>TestGameActivity.java</strong></p> <pre><code>public class TestGameActivity extends GameActivity { @Override public void onCreate(Bundle savedInstanceState) { final Injector injector = ((RoboApplication) getApplication()).getInjector(); injector.injectMembers(this); super.onCreate(savedInstanceState); } @Override public void main(){ platform().assetManager().setPathPrefix("test/images"); final Injector injector = ((RoboApplication) getApplication()).getInjector(); PlayN.run(injector.getInstance(TestGame.class)); } } </code></pre> <p>That's a quick and dirty rundown of how I got Gin/Guice/RoboGuice + GWT working in my project, and I have verified that it works on both Java and HTML platforms beautifully.</p> <p>Anyways, there's the GWT approach to providing RPC calls to multiple PlayN platforms :).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload