{"id":20372858,"url":"https://github.com/sidmishraw/foop-improved-2","last_synced_at":"2025-06-30T10:32:52.364Z","repository":{"id":86400553,"uuid":"108173850","full_name":"sidmishraw/foop-improved-2","owner":"sidmishraw","description":"A improved version of FOOP, it has STM and state separation logic baked in","archived":false,"fork":false,"pushed_at":"2017-10-29T21:17:39.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T20:43:25.582Z","etag":null,"topics":["foop","java-8","software-transactional-memory","stm"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sidmishraw.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-24T19:30:40.000Z","updated_at":"2017-10-28T08:16:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"f4859a9b-1f59-4bfb-bf09-24726c184433","html_url":"https://github.com/sidmishraw/foop-improved-2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sidmishraw/foop-improved-2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffoop-improved-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffoop-improved-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffoop-improved-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffoop-improved-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sidmishraw","download_url":"https://codeload.github.com/sidmishraw/foop-improved-2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffoop-improved-2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262756108,"owners_count":23359474,"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":["foop","java-8","software-transactional-memory","stm"],"created_at":"2024-11-15T01:15:14.683Z","updated_at":"2025-06-30T10:32:52.327Z","avatar_url":"https://github.com/sidmishraw.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# STM with object - state separation\n\nA improved version of FOOP, it has STM and state separation logic baked in.\n\n\nThere are 2 fundamental operations possible on a **`Memory Cell`**.\n\n* Read(`readT`)\n\n* Write(`writeT`)\n\nThe `StateManager` is responsible for handling all the boilerplate tasks for creating variables, reading from memory cells and writing to memory cells.\n\nThe StateManager is also responsible for creating you a transaction which then you can pass around and use accordingly.\n\nThe variables in `FOOP` are special in the sense that, they have their `State` separated from them. \n\nSo, a bank account in `FOOP` will be represented as:\n\n``` \n[AccountInfo] + [AccountBalance] \n```\n\nwhere `AccountInfo` is the `Variable` and `AccountBalance` is its `State`.\n\n\n\u003e Note: The code snippet below uses [Project Lombok]() for boilerplate reduction.\n\nIn the following snippet, AccountBalance is defined as a State. \n\n```java\n@EqualsAndHashCode(callSuper = false)\n@ToString\npublic class AccountBalance extends State {\n    \n    private @Getter float balance;\n    \n    /**\n     * @param balance\n     */\n    public AccountBalance(float balance) {\n        \n        this.balance = balance;\n    }\n}\n```\n\nThe snippet below shows the way to make variables in `FOOP`. The variables are made by the `StateManager`.\n\n```java\n// create the bank accounts to operate on\nmanager.make(\"Account1\");\nmanager.make(\"Account2\");\n```\n\nTo add `State` to these newly created memory cells or `Variable`s, one must use the `writeT` method of the `StateManager`.\n\n\u003e Note: readT and writeT are to be used in a `Transaction` context. This means, they can only be used inside a transaction.\n\n```java\nmanager.newTransaction(null)\n\t.op(\n\t\t() -\u003e {\n\t\t    try {\n\t\t        // make initial states\n\t\t        manager.writeT(\"Account1\", new AccountBalance(500.0F));\n\t\t        manager.writeT(\"Account2\", new AccountBalance(1500.0F));\n\t\t    } catch (Exception e) {\n\t\t        logger.error(e.getMessage(), e);\n\t\t        return TAction.FAIL;\n\t\t    }\n\t\t    return TAction.DONE;\n\t\t}\n\t)\n\t.done()\n\t.execute();\n```\n\nTo create a new transaction, one must use the builder pattern.\n\nThe pattern is as follows:\n\n```java\nTransaction t = manager.newTransaction(\"Transaction name\")\n\t\t\t\t\t.op(operation1)\n\t\t\t\t\t.op(operation2)\n\t\t\t\t\t...\n\t\t\t\t\t.done();\n```\n\nThe operations are chained and represent the sequential order they need to be executed in.\n\nThe `done()` is the terminal operation and returns the constructed transaction.\n\nThe transaction is executed by calling its `execute()`.\n\n\n```java\nmanager.newTransaction(\"T1\")\n                .op(() -\u003e deposit(\"Account1\", 500.0F))\n                .op(() -\u003e withdraw(\"Account2\", 500.0F))\n                .done()\n                .execute();\n```\n\nFor chaining multiple transactions one can use:\n\n```java\nCountDownLatch latch = new CountDownLatch(2);\n            \nmanager.newTransaction(\"T1\")\n        .op(() -\u003e deposit(\"Account1\", 500F))\n        .op(() -\u003e withdraw(\"Account2\", 500F))\n        .done()\n        .execute(latch);\n\nmanager.newTransaction(\"T2\")\n        .op(() -\u003e deposit(\"Account2\", 100F))\n        .op(() -\u003e withdraw(\"Account1\", 100F))\n        .done()\n        .execute(latch);\n\ntry {\n    \n    // wait till all the transactions are done\n    latch.await();\n} catch (InterruptedException e) {\n    \n    logger.error(e.getMessage(), e);\n}\n```\n\nBy using the latch, the main thread or the calling thread will wait till both the transctions are done processing.\n\n\u003e Note: The transctions themselves are actual threads and are processed concurrently.\n\n\nCaveats:\n\n* It is still boilerplate code heavy. (Might be because of Java)\n\n* Needs better examples, worst case time complexity analysis.\n\n\n`-Sid`\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidmishraw%2Ffoop-improved-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidmishraw%2Ffoop-improved-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidmishraw%2Ffoop-improved-2/lists"}