services.html 4.7 KB

123456789101112131415161718192021222324
  1. <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>Service system</title><link rel="stylesheet" href="./asciidoctor.css">
  2. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  3. <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/spidermonkey/tutorial/services.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/spidermonkey/tutorial/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Service system</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#creating-services">Creating services</a></li><li><a href="#using-services">Using services</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="admonitionblock warning"><table><tr><td class="icon"><i class="fa icon-warning" title="Warning"></i></td><td class="content"><div class="paragraph"><p>This article covers a deprecated <abbr title="Application Programming Interface">API</abbr>! See <a href="../../jme3/advanced/networking.html">networking</a> for current documentation.</p></div></td></tr></table></div>
  4. <div class="paragraph"><p>The service system is meant to create a common way of using plugins. It is a tiny system, on Server and Client level. In this tutorial I&#8217;ll tell you how to use services, and how to create your own.</p></div></div></div>
  5. <div class="sect1"><h2 id="creating-services">Creating services</h2><div class="sectionbody"><div class="paragraph"><p>Creating services is really easy - you just have to implement the Service interface. <strong>Make sure you don&#8217;t do anything time consuming</strong> since the developer may not be expecting it. Services can choose to support Server, Client, or both. To implement this, use the appropriate constructors:</p></div>
  6. <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">MyExampleService</span> <span class="directive">implements</span> Service {
  7. <span class="directive">public</span> MyExampleService(Server server) {
  8. <span class="comment">// By adding the constructor with the Server as argument, this service</span>
  9. <span class="comment">// now supports servers.</span>
  10. }
  11. <span class="directive">public</span> MyExampleService(Client client) {
  12. <span class="comment">// Same goes for client. I could just leave this constructor out, and</span>
  13. <span class="comment">// SpiderMonkey would determine this service does not support client mode.</span>
  14. }
  15. }</code></pre></div></div></div></div>
  16. <div class="sect1"><h2 id="using-services">Using services</h2><div class="sectionbody"><div class="paragraph"><p>The Server and Client class both have a method called getService(). It retrieves a service based on class name, and instantiates it if necessary. From there you can use the service.</p></div>
  17. <div class="paragraph"><p>The Service system is not a terribly powerful system, neither does it do safety checks and service management - it just provides a way to commonly manage extensions.</p></div>
  18. <div class="paragraph"><p>That&#8217;s it! Next tutorial we&#8217;re going to have a look at how to use the streaming <abbr title="Application Programming Interface">API</abbr>.</p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-15 23:15:33 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
  19. apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
  20. indexName: 'jmonkeyengine',
  21. inputSelector: '#doc-search',
  22. debug: false // Set debug to true if you want to inspect the dropdown
  23. });</script></body></html>