{"id":16558111,"url":"https://github.com/zeromemes/alpine","last_synced_at":"2026-04-07T04:31:24.138Z","repository":{"id":37271298,"uuid":"92676679","full_name":"ZeroMemes/Alpine","owner":"ZeroMemes","description":"A lightweight event system for Java 8+","archived":false,"fork":false,"pushed_at":"2023-07-17T05:05:05.000Z","size":478,"stargazers_count":92,"open_issues_count":6,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T00:23:24.723Z","etag":null,"topics":["eventbus","events","functional-interfaces","java-8","lambda-expressions"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZeroMemes.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,"governance":null}},"created_at":"2017-05-28T17:37:45.000Z","updated_at":"2025-03-07T18:18:23.000Z","dependencies_parsed_at":"2022-07-08T07:43:49.304Z","dependency_job_id":"fe8b20d9-4e96-4936-861c-65e63e976125","html_url":"https://github.com/ZeroMemes/Alpine","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/ZeroMemes/Alpine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroMemes%2FAlpine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroMemes%2FAlpine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroMemes%2FAlpine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroMemes%2FAlpine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZeroMemes","download_url":"https://codeload.github.com/ZeroMemes/Alpine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZeroMemes%2FAlpine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31500397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["eventbus","events","functional-interfaces","java-8","lambda-expressions"],"created_at":"2024-10-11T20:09:37.439Z","updated_at":"2026-04-07T04:31:24.113Z","avatar_url":"https://github.com/ZeroMemes.png","language":"Java","readme":"\u003cdiv align=\"center\"\u003e\n\n# Alpine\nA lightweight event system for Java 8+\n\n[![Releases][releases-badge]](https://github.com/ZeroMemes/Alpine/releases)\n[![License][license-badge]](/LICENSE)\n[![Status][status-badge]](https://github.com/ZeroMemes/Alpine/actions/workflows/gradle-build.yml)\n[![Coverage][coverage-badge]](https://app.codecov.io/gh/ZeroMemes/Alpine)\n[![Code Size][codesize-badge]](/)\n\n\u003c/div\u003e\n\n[releases-badge]: https://img.shields.io/github/v/release/ZeroMemes/Alpine?style=flat-square\n\n[license-badge]: https://img.shields.io/github/license/ZeroMemes/Alpine?style=flat-square\n\n[status-badge]: https://img.shields.io/github/actions/workflow/status/ZeroMemes/Alpine/gradle-build.yml?style=flat-square\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/ZeroMemes/Alpine?style=flat-square\n\n[codesize-badge]: https://img.shields.io/github/languages/code-size/ZeroMemes/Alpine?style=flat-square\n\n## Setup\n\nThe following setup assumes the usage of the [Impact Development Maven](https://impactdevelopment.github.io/maven) repo.\nAlternatively, the [GitHub package](https://github.com/ZeroMemes/Alpine/packages) may be used.\n\n### Gradle\n\n```gradle\ndependencies {\n    compile 'com.github.ZeroMemes:Alpine:3.1.0'\n}\n```\n\n### Maven\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.ZeroMemes\u003c/groupId\u003e\n    \u003cartifactId\u003eAlpine\u003c/artifactId\u003e\n    \u003cversion\u003e3.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Tutorial\n\nFor starters, we must create an EventBus to handle events and their respective listeners.\nAlpine provides a default implementation of EventBus that is configurable through a builder, so we'll be using that:\n\n```java\npublic class MyApplication {\n\n    public static final EventBus EVENT_BUS = EventManager.builder()\n        .setName(\"my_application/root\") // Descriptive name for the bus\n        .setSuperListeners()            // Enable Listeners to receive subtypes of their target\n        .build();\n}\n```\nSpecifying a name for the bus is required; although, there is no hard restriction on its uniqueness. Additional settings\nsuch as `setSuperListeners` can be seen in the documentation of [`EventBusBuilder`](src/main/java/me/zero/alpine/bus/EventBusBuilder.java).\n\nNow to actually receive events that are posted to the event bus, we'll need to create a `Listener` object and supply its\ngeneric argument with the type of event we'd like to receive. One of the ways that this can be done by creating a\n`Listener` member variable in a class implementing `Subscriber`, and annotating it with `@Subscribe`. Let's do that\nin our existing class:\n```java\npublic class MyApplication implements Subscriber {\n\n    public static final EventBus EVENT_BUS = ...;\n\n    @Subscribe\n    private Listener\u003cString\u003e stringListener = new Listener\u003c\u003e(str -\u003e {\n        System.out.println(str);\n    });\n}\n```\nIn order to use our `Listener`, we need to create a new instance of the `Subscriber` implementation and subscribe\nit to the event bus.\n```java\npublic class MyApplication implements Subscriber {\n\n    public static final EventBus EVENT_BUS = ...;\n\n    public static void main(String[] args) {\n        MyApplication app = new MyApplication();\n        EVENT_BUS.subscribe(app);\n    }\n\n    @Subscribe\n    private Listener\u003cString\u003e stringListener = new Listener\u003c\u003e(str -\u003e {\n        System.out.println(str);\n    });\n}\n```\nAn alternative to creating a `Subscriber` implementation and using annotated `Listener` fields to receive events\nis creating an independent `Listener` instance and subscribing it directly:\n```java\npublic class MyApplication {\n\n    public static final EventBus EVENT_BUS = ...;\n    \n    public static void main(String[] args) {\n        EVENT_BUS.subscribe(new Listener\u003cString\u003e(str -\u003e {\n            System.out.println(str);\n        }));\n        // or, alternatively... (println has a String implementation which will get bound to here)\n        EVENT_BUS.subscribe(new Listener\u003cString\u003e(System.out::println));\n    }\n}\n```\nIn cases where a method reference (`::`) is used for a `Listener` body and the underlying method's argument isn't the\n`Listener` target, a `ClassCastException` can occur during runtime. This is due to incorrect target resolution, and can\nbe fixed by explicitly specifying the target type:\n```java\npublic class MyApplication {\n\n    public static final EventBus EVENT_BUS = ...;\n\n    public static void main(String[] args) {\n        // Incorrect, can cause ClassCastException upon runtime depending on EventBus configuration\n        EVENT_BUS.subscribe(new Listener\u003cString\u003e(Main::supertypeAcceptor));\n\n        // Correct, explicitly defines the target and no runtime exception or unintended behavior will occur\n        EVENT_BUS.subscribe(new Listener\u003c\u003e(String.class, Main::supertypeAcceptor));\n    }\n\n    // Note the 'Object' argument type, this is what causes the need for an explicit target\n    private static void supertypeAcceptor(Object o) {\n        System.out.println(o);\n    }\n}\n```\nProviding our `Listener` with an event, in this case, any `String`, is straight-forward:\n```java\npublic class MyApplication {\n\n    public static final EventBus EVENT_BUS = ...;\n\n    public static void main(String[] args) {\n        MyApplication app = new MyApplication();\n        EVENT_BUS.subscribe(app);\n        EVENT_BUS.post(\"Test\");\n    }\n\n    @Subscribe\n    private Listener\u003cString\u003e stringListener = new Listener\u003c\u003e(str -\u003e {\n        // Prints \"Test\"\n        System.out.println(str);\n    });\n}\n```\nListeners may have filters applied which must pass in order for the body to receive a given event. A listener can have as\nmany filters as is needed, which are added as the last arguments in the `Listener` constructor.\n```java\npublic class MyApplication {\n\n    ...\n\n    @Subscribe\n    private Listener\u003cString\u003e stringListener = new Listener\u003c\u003e(str -\u003e {\n        // No output, \"Test\".length() != 3\n        System.out.println(str);\n    }, new LengthOf3Filter()); // \u003c-- Predicate\u003c? super String\u003e... as last argument to Listener\n\n    // Create nested class implementation of our filter\n    public static class LengthOf3Filter implements Predicate\u003cCharSequence\u003e {\n\n        @Override\n        public boolean test(CharSequence t) {\n            return t.length() == 3;\n        }\n    }\n}\n```\nThe complete example class can be found in [Java](example/src/main/java/JavaApplication.java) and [Kotlin](example/src/main/kotlin/KotlinApplication.kt).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromemes%2Falpine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeromemes%2Falpine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromemes%2Falpine/lists"}