{"id":20056159,"url":"https://github.com/marmelo/chili","last_synced_at":"2025-05-05T13:33:35.646Z","repository":{"id":26779197,"uuid":"30237359","full_name":"marmelo/chili","owner":"marmelo","description":"Chili is a collection of Java annotations that simplify common tasks.","archived":false,"fork":false,"pushed_at":"2018-11-22T01:52:51.000Z","size":55,"stargazers_count":6,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T00:04:27.049Z","etag":null,"topics":["annotations","cache","dependency-injection","guice","java","log","memoize","timeout"],"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/marmelo.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":"2015-02-03T10:25:41.000Z","updated_at":"2023-03-13T02:45:58.000Z","dependencies_parsed_at":"2022-08-31T08:20:14.828Z","dependency_job_id":null,"html_url":"https://github.com/marmelo/chili","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelo%2Fchili","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelo%2Fchili/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelo%2Fchili/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marmelo%2Fchili/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marmelo","download_url":"https://codeload.github.com/marmelo/chili/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252506677,"owners_count":21759096,"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":["annotations","cache","dependency-injection","guice","java","log","memoize","timeout"],"created_at":"2024-11-13T12:52:08.069Z","updated_at":"2025-05-05T13:33:35.331Z","avatar_url":"https://github.com/marmelo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chili\n\n[![Build Status](https://travis-ci.org/marmelo/chili.svg?branch=master)](https://travis-ci.org/marmelo/chili)\n[![Maven Central](https://img.shields.io/badge/maven--central-v1.0-blue.svg)](http://search.maven.org/#artifactdetails|me.defying.chili|chili|1.0|jar)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/marmelo/chili/blob/master/LICENSE)\n\n\n**Chili** is a collection of Java annotations that simplify common tasks.\n\nThese annotations allow to dynamically alter the functionality of class methods\nwithout changing their implementation. Chili relies on [Guice AOP](https://github.com/google/guice/wiki/AOP)\nto process the annotations and requires JDK 1.7 or higher.\n\nThe following [annotations](#annotations) are currently implemented:\n\n- [@Log](#log) - Log method invocation.\n- [@Memoize](#memoize) - Cache the method computed result.\n- [@Timeout](#timeout) - Interrupt method invocation if time limit is exceeded.\n- [@ToString](#tostring) - Generate ```toString``` method automatically.\n\n\n## Configuration\n\nYou can get Chili straight from Maven central repository:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eme.defying.chili\u003c/groupId\u003e\n  \u003cartifactId\u003echili\u003c/artifactId\u003e\n  \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nAlternatively, you may use the latest snapshot release from the Sonatype's repository (which may require additional repository configuration).\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eme.defying.chili\u003c/groupId\u003e\n  \u003cartifactId\u003echili\u003c/artifactId\u003e\n  \u003cversion\u003e1.1-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n```xml\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003esonatype.oss.snapshots\u003c/id\u003e\n    \u003cname\u003eSonatype OSS Snapshot Repository\u003c/name\u003e\n    \u003curl\u003ehttp://oss.sonatype.org/content/repositories/snapshots\u003c/url\u003e\n    \u003creleases\u003e\n      \u003cenabled\u003efalse\u003c/enabled\u003e\n    \u003c/releases\u003e\n    \u003csnapshots\u003e\n      \u003cenabled\u003etrue\u003c/enabled\u003e\n    \u003c/snapshots\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n## Usage\n\nAre you in a hurry? Please refer to the provided [```chili-example```](https://github.com/marmelo/chili/tree/master/chili-example) project.\n\nTo use Chili annotations you only need to perform three steps:\n\n1. Add annotations to your code;\n2. Create a Guice ```Injector``` registering a ```ChiliModule``` instance;\n3. Compile and run your project.\n\nNot acquainted with Guice? Please read its [documentation](https://github.com/google/guice/wiki/Motivation).\n\nLets create a simple class with a [@Memoize](#memoize) annotation:\n\n```java\npublic class MemoizeService {\n\n    /**\n     * Returns the given value raised to the power of two.\n     *\n     * @param x the base value.\n     * @return the value {@code x}\u003csup\u003e2\u003c/sup\u003e.\n     */\n    @Memoize\n    public int power(int x) {\n        return x * x;\n    }\n}\n```\n\nThe [@Memoize](#memoize) annotation will store the method results and return them when\nthe same inputs occur again. That is, if we call multiple times the ```power``` method\nwith the same argument it will only perform the calculation the first time and return\ncached results in the next invocations.\n\nNevertheless, the [@Memoize](#memoize) annotation alone produces no effect. We need to\nintroduce a Guice ```Injector``` to intercept the method invocation and inject new meaning\nto it.\n\nTo create an empty ```Injector``` you only need to write:\n\n```java\nGuice.createInjector();\n```\n\nThe ```createInjector``` method receives a list of modules that contain the application\n[bindings](https://github.com/google/guice/wiki/Bindings). To simplify this process it\nis provided a ```ChiliModule``` class with all the Chili annotations bindings configured.\n\n```java\nGuice.createInjector(new ChiliModule());\n```\n\nIf your are already using Guice in you project you may add the ```ChiliModule``` next to yours.\n\n```java\nGuice.createInjector(new MyExistingModule(), new ChiliModule());\n```\n\nNow that you have created the ```Injector``` you need to use it to inject the annotation\nbindings into your code.\n\n```java\npublic class MemoizeExample {\n\n    public static void main(String[] args) {\n        // create the injector\n        Injector injector = Guice.createInjector(new ChiliModule());\n\n        // create an injected instance of the service\n        MemoizeService service = injector.getInstance(MemoizeService.class);\n\n        // cache miss\n        service.power(3);\n\n        // cache hit\n        service.power(3);\n    }\n}\n```\n\nPlease refer to the [```chili-example```](https://github.com/marmelo/chili/tree/master/chili-example)\nproject for further examples.\n\n\n## Annotations\n\n#### @Log\n\nLog method invocation with arguments, return value and execution time.\n\nThe [@Log](#log) annotation accepts the following elements:\n\n| Element     | Type     | Default       | Description  |\n| ----------- | -------- | ------------- | ------------ |\n| ```level``` | LogLevel | INFO | Log level to be used. Possible values are TRACE, DEBUG, INFO, WARNING and ERROR. |\n\n#### @Memoize\n\nStores results of expensive function calls and returns the cached result when the\nsame inputs occur again. Please refer to [Wikipedia](https://en.wikipedia.org/wiki/Memoization)\nfor further details.\n\nThe [@Memoize](#memoize) annotation accepts the following elements:\n\n| Element    | Type     | Default      | Description  |\n| ---------- | -------- | ------------ | ------------ |\n| ```size```       | long     | 0L           | Maximum entries the cache may have. |\n| ```time```       | long     | 0L           | For how long the method invocation should be cached according to the ```unit``` value. If unspecified or equal to zero the cache will not be time bound. |\n| ```unit```       | TimeUnit | MILLISECONDS | The ```TimeUnit``` the ```time``` value refers to. |\n| ```statistics``` | boolean  | false        | Whether or not cache statistics should be logged. |\n\nWhen the ```size``` and ```time``` values are active, both are enforced.\n\n#### @Timeout\n\nInterrupts method invocation if time limit is exceeded. When time is exceeded invocation is interrupted and a ```TimeoutException``` exception is thrown.\n\nThe [@Timeout](#timeout) annotation accepts the following elements:\n\n| Element    | Type     | Default      | Description  |\n| ---------- | -------- | ------------ | ------------ |\n| ```time```       | long     | 0L           | For how long the method invocation should be time limited according to the ```unit``` value. If unspecified or equal to zero the method will not be time bound. |\n| ```unit```       | TimeUnit | MILLISECONDS | The ```TimeUnit``` the ```time``` value refers to. |\n\n#### @ToString\n\nGenerate `toString` method automatically including all or some class fields.\n\nThe [@ToString](#tostring) annotation accepts the following elements:\n\n| Element     | Type     | Default       | Description  |\n| ----------- | -------- | ------------- | ------------ |\n| ```fields``` | String[] | {} | List of class fields to include in the ```toString``` generation. If empty, all class fields will be included. Unknown fields will be silently ignored. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmelo%2Fchili","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarmelo%2Fchili","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarmelo%2Fchili/lists"}