{"id":15044554,"url":"https://github.com/udaychandra/susel","last_synced_at":"2025-04-10T00:42:47.331Z","repository":{"id":57735087,"uuid":"152002724","full_name":"udaychandra/susel","owner":"udaychandra","description":"Super charge the module aware service loader in Java 11","archived":false,"fork":false,"pushed_at":"2018-10-14T20:47:33.000Z","size":121,"stargazers_count":22,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T00:42:41.549Z","etag":null,"topics":["java11","javamodulesystem","jdk11","jpms","serviceloader"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/udaychandra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-08T01:39:17.000Z","updated_at":"2024-03-31T14:21:37.000Z","dependencies_parsed_at":"2022-08-24T11:20:42.216Z","dependency_job_id":null,"html_url":"https://github.com/udaychandra/susel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udaychandra%2Fsusel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udaychandra%2Fsusel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udaychandra%2Fsusel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udaychandra%2Fsusel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udaychandra","download_url":"https://codeload.github.com/udaychandra/susel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137998,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java11","javamodulesystem","jdk11","jpms","serviceloader"],"created_at":"2024-09-24T20:50:42.984Z","updated_at":"2025-04-10T00:42:47.315Z","avatar_url":"https://github.com/udaychandra.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/udaychandra/susel.svg?style=svg)](https://circleci.com/gh/udaychandra/susel)\n\n## Susel\n\u003cem\u003eSu\u003c/em\u003eper \u003cem\u003eSe\u003c/em\u003ervice \u003cem\u003eL\u003c/em\u003eoader: Super charge the module aware service loader in Java 11. \nSusel is a light weight library that helps one build Java module system native applications.\n\n## Introduction\nService loader mechanism of Java, introduced in Java 6 and revised in Java 9, is used to locate and load services. \nA service is a well known interface or class (usually abstract). A service provider is a concrete implementation of a service. \nThe ServiceLoader class is a facility to load service providers that implement a given service. \nA Java native module can declare that it uses a specific service in its module description (module-info.java). The module can then use the ServiceLoader to locate and load the service providers deployed in the run time environment.\n\nSusel builds on this service loading mechanism and provides a few useful features. \nSusel enables you to specify required or optional service references (through annotations) that a a given service provider might need to operate. \nPartly inspired by OSGI, Susel provides an \"activate\" annotation that can be used by a service provider to do some initiation work or to read configuration from a global context map passed to it by Susel.  \n\n## Basic Usage\nIf you are using a build tool like Maven or Gradle, add the following dependency to access Susel API:\n\n- Maven pom.xml\n  ```xml\n   \u003cdependency\u003e\n     \u003cgroupId\u003eio.github.udaychandra.susel\u003c/groupId\u003e\n     \u003cartifactId\u003esusel\u003c/artifactId\u003e\n     \u003cversion\u003e0.1.2\u003c/version\u003e\n   \u003c/dependency\u003e\n   ```\n\n- Gradle build.gradle\n  ```groovy\n   dependencies {\n     compile 'io.github.udaychandra.susel:susel:0.1.2'\n   }\n   ```\n\n\u003e Note that Susel requires Java 11\n\nBegin by defining a service interface.\n\n```java\npackage com.example.svc;\n\npublic interface HelloService {\n    String hello(String id);\n}\n\n```   \nCreate a service provider by implementing the service interface.\n\n```java\npackage com.example.svc.name;\n\npublic class HelloNameService implements HelloService {\n    private UserService userService;\n    \n    @ServiceReference(cardinality = Cardinality.ONE)\n    public void setUserService(UserService userService) {\n        this.userService = userService;\n    }\n    \n    public String hello(String id) {\n        return \"Hello \" + userService.getName(id);\n    }\n}\n```\n\nUpdate the module descriptor (module-info.java)\n```java\nmodule com.example.svc.name {\n    exports com.example.svc.name;\n\n    requires com.example.svc;\n\n    provides com.example.svc.HelloService \n        with com.example.svc.name.HelloNameService;\n}\n\n```\n\nNow, a consuming client of the service interface can delegate the lookup, preparation and loading to Susel. \nSay the module descriptor of the client looks something like this:\n```java\nmodule com.example.client {\n    exports com.example.client;\n\n    requires com.example.svc;\n    requires io.github.udaychandra.susel;\n\n    uses com.example.svc.HelloService;\n}\n```\n\nThe client can then activate Susel once and start loading services. \nFor example, to load the HelloService one can do this in the application's main method:\n```java\nSusel.activate(Map.of());\nvar helloService = Susel.get(HelloService.class);\n```\n\nSusel will take care of loading a service provider that implements the hello service.\nWhen it finds the HelloNameService, it will ensure that at least one service provider that implements \nthe required UserService reference is found and injected, activates HelloNameService and returns the now ready to use HelloNameService. \n\nSusel relies on the presence of a metadata file (META-INF/susel.metadata) in a module to figure out the service references used by a service provider, \ntheir cardinalities and the method that should be invoked to activate the service provider. This metadata file should be generated during compile time.\n\nThere's a gradle [plugin](https://github.com/udaychandra/susel-gradle-plugin) that can automate the generation and packaging of these metadata files. \nThe plugin calls the Susel tool which can be manually invoked as well.\n\n\u003e A maven plugin is in the works\n\n## Development\nThis is a community project. All contributions are welcome.\n\nTo start contributing, do the following:\n* Install JDK 11\n* Fork or clone the source code\n* Run the build using the gradle wrapper\n```bash\ngradlew clean build\n```\n\n## License\nApache License 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudaychandra%2Fsusel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudaychandra%2Fsusel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudaychandra%2Fsusel/lists"}