{"id":18832410,"url":"https://github.com/brainpoint/febs-java","last_synced_at":"2026-01-25T09:30:17.568Z","repository":{"id":57715806,"uuid":"259841431","full_name":"brainpoint/febs-java","owner":"brainpoint","description":"The common libraries in fluent api. Most api is like javascript.","archived":false,"fork":false,"pushed_at":"2020-10-13T21:35:47.000Z","size":108,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T07:11:50.679Z","etag":null,"topics":["febs","fetch","java-js","net","promise","promise-java","stage","thread","threadpool"],"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/brainpoint.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":"2020-04-29T06:18:24.000Z","updated_at":"2020-07-28T06:43:14.000Z","dependencies_parsed_at":"2022-09-26T16:40:20.461Z","dependency_job_id":null,"html_url":"https://github.com/brainpoint/febs-java","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/brainpoint%2Ffebs-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainpoint%2Ffebs-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainpoint%2Ffebs-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainpoint%2Ffebs-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainpoint","download_url":"https://codeload.github.com/brainpoint/febs-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239768935,"owners_count":19693763,"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":["febs","fetch","java-js","net","promise","promise-java","stage","thread","threadpool"],"created_at":"2024-11-08T01:57:47.092Z","updated_at":"2026-01-25T09:30:17.500Z","avatar_url":"https://github.com/brainpoint.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Febs\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/cn.brainpoint/febs/badge.svg)](https://maven-badges.herokuapp.com/maven-central/cn.brainpoint/febs/)\n[![License](https://img.shields.io/github/license/brainpoint/febs-java)](https://opensource.org/licenses/MIT)\n\nFebs is a common libraries in fluent API. Most api is like javascript.\n\n- [How to use](#how-to-use)\n- [Asynchronous in ThreadPool](#Asynchronous-in-ThreadPool)\n- [Asynchronous in Promise](#Asynchronous-in-Promise)\n- [Network transfer in Fetch](#Network-transfer-in-Fetch)\n- [Utilities](#Utilities)\n\n## How to use\n\nmaven config.\n\n```html\n\u003cdependency\u003e\n    \u003cgroupId\u003ecn.brainpoint\u003c/groupId\u003e\n    \u003cartifactId\u003efebs\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.3\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\n```js\nimport cn.brainpoint.febs;\n\n//\n// It will execute asynchronously after call `execute()`\n//\nPromiseFuture future = Febs.Net.fetch(\"https://xxx\")\n                            // get response status code.\n                            .then(res-\u003e{\n                                // code.\n                                System.out.print(res.statusCode);\n                                // message.\n                                System.out.print(res.statusMsg);\n                                \n                                // get text content.\n                                return res.text();\n                            })\n                            .then(content-\u003e{\n                        \n                            })\n                            .execute();\n\n\n//\n// Can use `future.get()` to get result in synchronize.\n//\nString result = (String) future.get();\n\n```\n\n\n### config\n\nIt can initial with thread pool config. Thread pool will affect performance of promise.\n\n```js\n// Initial with thread pool config.\nFebs.init(new Febs.ThreadPoolCfg(\n                        2, \n                        4, \n                        20000, \n                        new LinkedBlockingQueue\u003c\u003e(),\n                        new ThreadPoolExecutor.AbortPolicy())\n         );\n```\n\n## Asynchronous in ThreadPool\n\nUse `getExecutorService` api to get a asynchronous work item.\n\n```js\ntry {\n    Future\u003cObject\u003e future \n                    = Febs.getExecutorService.submit(()-\u003e{\n                        // do anything in this thread.\n                        return \"any\";\n                    });\n    Object result = future.get();\n} catch (ExecutionException e) {\n    e.printStackTrace();\n} catch (InterruptedException e) {\n    e.printStackTrace();\n} catch (Exception e) {\n    e.printStackTrace();\n}\n```\n\n## Asynchronous in Promise\n\nFebs promise like javascript promise api, use chain list way to do asynchronous work.\n\n- `.then`: same as js-es6 promise`.then` chain.\n- `.fail`: same as js-es6 promise`.catch` chain.\n- `.finish`: same as js promise`.finally` chain.\n- `.execute`: It must be call to activate promise in Febs promise.\n\n### Base scene\n\n```js\n/**\n * Make a promise object.\n */\nPromise promise = new Promise((IResolve resolve, IReject reject)-\u003e { \n\n                                // call this set status to 'fulfilled'\n                                resolve.execute(retVal); \n\n                                // call this set status to 'rejected'\n                                reject.execute(new Exception(\"\"));\n                            });\n\n/**\n * chain.\n */\nPromiseFuture = promise.then(res-\u003e{  })\n                       .then(()-\u003e{ return 1; })\n                       .then(res1-\u003e{  })\n                       .fail(e-\u003e{  })  // same as javascript catch()\n                       .finish(()-\u003e{}) // same as javascript finally()\n                       .execute();  // activate promise.\n\n/**\n * Block until promise finish, if you want to wait.\n */\nPromiseFuture.get();\n```\n\n### return another promise object in chain.\n\n```js\npromise.then(res-\u003e{\n            // this nest promise cannot call execute().\n            return new Promise((resolve, reject)-\u003e{\n                ...\n            });\n        })\n        .then(res-\u003e{\n        })\n        .execute();\n```\n\n### all\n\n```js\n/**\n * Promise object array.\n * !Warning: All promise object cannot call execute() funciton.\n */\nPromise[] promiseArr = {...};\n\n/**\n * execute all promise object.\n */\nPromise.all(promiseArr)\n       .then(res-\u003e{\n            // all promise done.\n        })\n        .fail(e-\u003e{\n            // if some promise rejected.\n        })\n       .execute();\n```\n\n### template\n\nThe `then` and `fail` chain can return a object to next chain. The data type of return value is unkonw, we can use template to spacify a data type.\n\ne.g.\n\n```js\n// Spacify a data type.\nPromise\u003cInteger\u003e promise = new Promise\u003cInteger\u003e((IResolve\u003cInteger\u003e resolve, IReject reject)-\u003e { \n                                resolve.execute(2); \n                            });\n\n// use the data type.\npromise.then((Integer res)-\u003e{ \n            // ...\n        })\n       .execute();  // execute promise.\n```\n\n### Uncaught Exception Handler\n\nSome promise object will catch exception use this method, if it have't call `.fail()`\n\n```js\nPromise.setUncaughtExceptionHandler(e-\u003e{\n  // handle error.\n});\n```\n\n## Network transfer in Fetch\n\nThe network transfer in fetch style\n\n### Get text content.\n\n```js\nimport cn.brainpoint.febs;\n\nFebs.Net.fetch(\"https://xxxx\")\n        // get text content.\n        .then(res-\u003e{ return res.text(); })\n        // print content.\n        .then(res-\u003e{\n            System.out.print(res);\n        })\n        // If exception cause.\n        .fail((e)-\u003e{\n            System.err.print(e.getMessage());\n        })\n        .execute();\n```\n\n### Get binary content.\n\n```js\nimport cn.brainpoint.febs;\n\nFebs.Net.fetch(\"https://xxxx\")\n        // get blob content.\n        .then(res-\u003e{ return res.blob(); })\n        // print content.\n        .then((res)-\u003e{\n            BufferedReader in = (BufferedReader)res;\n            char buf[] = new char[1024];\n\n            while (in.read(buf, 0, buf.length) != -1) {\n                System.out.printf(\"%s\",  Arrays.toString(buf));\n                Arrays.fill(buf, '\\0');\n            }\n\n            // important to call close().\n            in.close();\n        })\n        // If exception cause.\n        .fail((e)-\u003e{\n            System.err.print(e.getMessage());\n        })\n        .execute();\n```\n\n\u003e IMPORTANT: close BufferedReader after read blob.\n\n\n### Get response headers.\n\n```js\nimport cn.brainpoint.febs;\n\nFebs.Net.fetch(\"https://xxxx\")\n        // get response status code.\n        .then(res-\u003e{\n            // code.\n            System.out.print(res.statusCode);\n            // message.\n            System.out.print(res.statusMsg);\n            \n            return res;\n        })\n        // get response headers.\n        .then(res-\u003e{\n            Set\u003cString\u003e keySet = res.headers.keySet();\n            Iterator\u003cString\u003e it1 = keySet.iterator();\n            while(it1.hasNext()){\n                String Key = it1.next();\n                System.out.print(\"header: \" + Key);\n                List\u003cString\u003e values = res.headers.get(Key);\n                System.out.print(values);\n            }\n        })\n        // If exception cause.\n        .fail((e)-\u003e{\n            System.err.print(e.getMessage());\n        })\n        .execute();\n```\n\n### Set request parameter \n\n```js\nimport cn.brainpoint.febs;\n\nFebs.Net.fetch(new Requset(\n                    url,\n                    body,\n                    method,\n                    headers,\n                    timeout,\n                ))\n        // get blob content.\n        .then(res-\u003e{ return res.blob(); })\n        .execute();\n```\n\n### SSL trust manager\n\n```js\nimport cn.brainpoint.febs;\n\n/**\n * set the trust manager.\u003cbr\u003e\n * The default trust manager is trust all site.\n * \n * @param trustManger the trust manager object.\n */\nFebs.Net.setDefaultTrustManger(X509TrustManager trustManager);\n```\n\n## Utilities\n\n### sleep\n\nUse `sleep` API to schedule tasks.\n\n```js\nimport cn.brainpoint.febs;\n\nFebs.Utils.sleep(1000)\n        .then(()-\u003e{\n            System.out.print(\"after 1000ms.\");\n        })\n        .execute();\n\n\nFebs.Utils.sleep(1000)\n        .then(res-\u003e{\n            System.out.print(\"after 1000ms.\");\n            return Febs.Utils.sleep(2000);\n        })\n        .then(res-\u003e{\n            System.out.print(\"after 2000ms.\");\n        })\n        .execute();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainpoint%2Ffebs-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainpoint%2Ffebs-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainpoint%2Ffebs-java/lists"}