services.adoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. = Service system
  2. :author:
  3. :revnumber:
  4. :revdate: 2016/03/17 20:48
  5. :relfileprefix: ../../
  6. :imagesdir: ../..
  7. ifdef::env-github,env-browser[:outfilesuffix: .adoc]
  8. [WARNING]
  9. ====
  10. This article covers a deprecated +++<abbr title="Application Programming Interface">API</abbr>+++! See <<jme3/advanced/networking#,networking>> for current documentation.
  11. ====
  12. 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'll tell you how to use services, and how to create your own.
  13. == Creating services
  14. Creating services is really easy - you just have to implement the Service interface. *Make sure you don't do anything time consuming* since the developer may not be expecting it. Services can choose to support Server, Client, or both. To implement this, use the appropriate constructors:
  15. [source,java]
  16. ----
  17. public class MyExampleService implements Service {
  18. public MyExampleService(Server server) {
  19. // By adding the constructor with the Server as argument, this service
  20. // now supports servers.
  21. }
  22. public MyExampleService(Client client) {
  23. // Same goes for client. I could just leave this constructor out, and
  24. // SpiderMonkey would determine this service does not support client mode.
  25. }
  26. }
  27. ----
  28. == Using services
  29. 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.
  30. 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.
  31. That's it! Next tutorial we're going to have a look at how to use the streaming +++<abbr title="Application Programming Interface">API</abbr>+++.