{"id":19861585,"url":"https://github.com/ischwarz23/listenersupport","last_synced_at":"2025-10-17T22:16:41.881Z","repository":{"id":91902408,"uuid":"73944472","full_name":"ISchwarz23/ListenerSupport","owner":"ISchwarz23","description":"A very lightweight library, that simplifies the usage of custom listeners.","archived":false,"fork":false,"pushed_at":"2017-01-07T20:02:53.000Z","size":354,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T14:50:10.580Z","etag":null,"topics":["custom-listeners","java-8","lambda","listener"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ISchwarz23.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-16T17:33:23.000Z","updated_at":"2019-11-04T06:29:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"d702f694-5d97-4e42-8310-ac8c489409ba","html_url":"https://github.com/ISchwarz23/ListenerSupport","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/ISchwarz23%2FListenerSupport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ISchwarz23%2FListenerSupport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ISchwarz23%2FListenerSupport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ISchwarz23%2FListenerSupport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ISchwarz23","download_url":"https://codeload.github.com/ISchwarz23/ListenerSupport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241263405,"owners_count":19936057,"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":["custom-listeners","java-8","lambda","listener"],"created_at":"2024-11-12T15:09:17.227Z","updated_at":"2025-10-17T22:16:36.828Z","avatar_url":"https://github.com/ISchwarz23.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/ISchwarz23/ListenerSupport.svg?branch=master)](https://travis-ci.org/ISchwarz23/ListenerSupport) \n[![Download](https://api.bintray.com/packages/ischwarz/maven/ListenerSupport/images/download.svg)](https://bintray.com/ischwarz/maven/ListenerSupport/_latestVersion)  \n  \n![ListenerSupport-Logo](https://raw.githubusercontent.com/ISchwarz23/ListenerSupport/master/readme/listenersupport-logo-with-name.png)  \n  \nA very lightweight library, that simplifies the usage of custom listeners. It is inspired\nby the `PropertyChangeSupport` but it has the advantage of a custom listener implementation\nlike type safety.  \n  \n**Minimum Java-Version:** 8  |  **Compile Java-Version:** 8  |  **Latest Library Version:** 0.9.0   \n\n## Features\nAs soon as you are going to create a listener interface for your view, model, controller or any other part of\nyour application, you have to write a lot of boilerplate code to manage and notify this listeners, like...\n- manage a collection to store the listeners\n- add new listeners to that collection (after checking that it is not part of it, yet)\n- removing old listeners from that collection (after checking that it was part of it)\n- iterate over the whole collection to notify these listeners with the specific params\n- catch exceptions thrown by the listeners to avoid errors\n- make sure the notification is done in the correct thread\n- ...\n\nThis is where the `ListenerSupport` library comes in place. The `ListenerSupport` simplifies the \nmanagement of your listeners. Adding, removing and notifying them is now only ONE method call.  \n\nOn top of that, you can...\n- define `Executor`s that will be used to do this notification (e.g. do a notification in the \nUI-Thread). \n- define `FailureStrategie`s that will be called, when any listener throws an exception on notification call.\n\n## Add it to your Project\n1) Add JCenter to your artifact repositories\n```groovy\n// using gradle\nrepositories {\n    jcenter()\n}\n```\n2) Add the ListenerSupport to your dependencies\n```groovy\n// using gradle\ndependencies {\n    compile 'de.codecrafters.listenersupport:listenersupport:\u003cversion\u003e'\n}\n```\n\n## ListenerSupport Creation\nThe following example will the listener interface definition below.\n```java\npublic interface MyListener {\n    void onSomethingHappened( final String something );\n}\n```\nTo create a `ListenerSupport` for any listener definition, you simply use the\n`ListenerSupport` class.\n```java\nmyListenerSupport = ListenerSupport.createFor( MyListener::onSomethingHappened );\n```\nThis simple call will create a ListenerSupport that enables you to add and remove\nlisteners of type `MyListener` and provides a `notifyListeners()`-method which takes the same arguments\nas the `MyListener#onSomethingHappened` method.  \n\n## Manage Listeners\nAs described in the \"ListenerSupport Creation\" section, after the creation you are able to use\ntype safe methods to add, remove and notify listeners.  \n\nSo if we use the example above, the `myListenerSupport` will provide the following methods (among others):  \n`myListenerSupport#addListener( MyListener )`  \n`myListenerSupport#removeListener( MyListener )`  \n`myListenerSupport#notifyListeners( String )`  \n\nThe most interesting of these methods is the notify method, which has exactly the same arguments as the \nmethod that shall be called (in this case it's the `MyListener#onSomethingHappened` method).\n\n## Notify Executors\nTo define in which thread the notification is done, or if the notifications are done serial or in \nparallel you can give an `Executor` that will be used. Simply pass the `Executor` that shall be used\nfor notification as second parameter to the `ListenerSupport#createFor()` method. \n```java\nmyListenerSupport = ListenerSupport.createFor( MyListener::onSomethingHappened, NotifyExecutors.uiThreadExecutor() );\n```\nIf no `Executor` is passed, it'll notify the listeners in the thread from which the `notify()` method \nwas called.\n\n## Failure Strategies\nAs there can be errors thrown by listeners that are notified, there is the possibility\nto register a `FailureStrategy` to the `ListenerSupport`. That `FailureStrategy` is\ncalled whenever a listener has thrown a `Throwable`.\n\nThere are already multiple `FailureStrategie`s available to be used:  \n\n| Name | Artifact |\n| --- | --- |\n| JavaLoggingFailureStrategy | `de.codecrafters.listenersupport:failurestrategy-javalogger` |\n| Log4jFailureStrategy | `de.codecrafters.listenersupport:failurestrategy-log4j` |\n| PrintStackTraceFailureStrategy | none (set if no other available) |\n| Slf4jFailureStrategy | `de.codecrafters.listenersupport:failurestrategy-slf4j` |\n| SystemErrorFailureStrategy | `de.codecrafters.listenersupport:failurestrategy-systemerrorwriter` |\n\nIf you want to apply any of these failure strategies, just add it as runtime dependency to your project. It'll be\nautomatically used for every `ListenerSupport` you create.\nIf you have multiple failure strategies in your classpath you can define the default one by creating a property file\ncalled \"failurestrategyloader.properties\" and set the name of the strategy that shall be the default for the\nproperty called \"strategyName\".  \n\nIf you need to set the failure strategy different for any `ListenerSupport` just use the \n`ListenerSupport#setFailureStrategy()` method.\n\nIf you want to have all failure strategies available just use the `de.codecrafters.listenersupport:failurestrategy-all` \nartifact. This one also contains a factory called `FailureStrategies` that simplifies the creation for all failure\nstrategies.  \n\nIf the available failure strategies are not fulfilling your needs, you could of cause create your custom strategy.\n\n#### JavaLoggingFailureStrategy\nA `FailureStrategy` implementation that will log the thrown errors using the `java.util.logging.Logger`. The used \nlog level is `ERROR`.\n\n#### Log4jFailureStrategy\nA `FailureStrategy` implementation that will log the thrown errors using the `org.apache.logging.log4j.Logger`. The \nused log level is `ERROR`.\n\n#### PrintStackTraceFailureStrategy\nA `FailureStrategy` implementation that will print the thrown errors using the `Throwable#printStackTrace()` method.\n\n#### Slf4jFailureStrategy\nA `FailureStrategy` implementation that will log the thrown errors using the `org.slf4j.Logger`. The used log level \nis `ERROR`.\n\n#### SystemErrorFailureStrategy\nA `FailureStrategy` implementation that will print the thrown errors using the `System.err` print stream \n(like `Throwable#printStackTrace(System.err)`) after printing the class information of the listener which has thrown\nthis error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fischwarz23%2Flistenersupport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fischwarz23%2Flistenersupport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fischwarz23%2Flistenersupport/lists"}