{"id":22769125,"url":"https://github.com/vincent4vx/singleinstance","last_synced_at":"2025-03-30T11:20:30.065Z","repository":{"id":57731348,"uuid":"291044035","full_name":"vincent4vx/SingleInstance","owner":"vincent4vx","description":"Java library for prevent running multiple instances of an application, and offer a communication with the first instance.","archived":false,"fork":false,"pushed_at":"2020-08-29T12:34:59.000Z","size":63,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T13:14:20.666Z","etag":null,"topics":["ipc","java","single-instance","single-instance-app"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vincent4vx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-28T12:43:24.000Z","updated_at":"2023-06-18T16:15:13.000Z","dependencies_parsed_at":"2022-09-26T22:10:21.955Z","dependency_job_id":null,"html_url":"https://github.com/vincent4vx/SingleInstance","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent4vx%2FSingleInstance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent4vx%2FSingleInstance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent4vx%2FSingleInstance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vincent4vx%2FSingleInstance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vincent4vx","download_url":"https://codeload.github.com/vincent4vx/SingleInstance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246308962,"owners_count":20756643,"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":["ipc","java","single-instance","single-instance-app"],"created_at":"2024-12-11T14:16:02.132Z","updated_at":"2025-03-30T11:20:30.029Z","avatar_url":"https://github.com/vincent4vx.png","language":"Java","readme":"# SingleInstance\n[![Build Status](https://scrutinizer-ci.com/g/vincent4vx/SingleInstance/badges/build.png?b=master)](https://scrutinizer-ci.com/g/vincent4vx/SingleInstance/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/vincent4vx/SingleInstance/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/vincent4vx/SingleInstance/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/vincent4vx/SingleInstance/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/vincent4vx/SingleInstance/?branch=master) [![javadoc](https://javadoc.io/badge2/fr.quatrevieux/single-instance/javadoc.svg)](https://javadoc.io/doc/fr.quatrevieux/single-instance) [![Maven Central](https://img.shields.io/maven-central/v/fr.quatrevieux/single-instance)](https://search.maven.org/artifact/fr.quatrevieux/single-instance) \n \nJava library for prevent running multiple instances of an application, and offer a communication with the first instance.\n\nIt's based on the use of a lock file with exclusive lock to ensure that only the first process can write into this file.\nFor the IPC communication, a simple single thread socket server is start by the first process, and the port number is written \non the lock file.\n\n## Installation\n\nFor installing using maven, add this dependency into the `pom.xml` :\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003efr.quatrevieux\u003c/groupId\u003e\n    \u003cartifactId\u003esingle-instance\u003c/artifactId\u003e\n    \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\n### Basic usage\n\nUse [SingleInstance](src/main/java/fr/quatrevieux/singleinstance/SingleInstance.java)`#onAlreadyRunning()` to check if an instance is running, and send a message.\nThen start the IPC server using `SingleInstance#onMessages()`.\n\n```java\n/**\n * Forward the arguments to the first running application\n */\npublic class MyApp {\n    public static void main(String[] args) {\n        // Check if there is a running instance\n        SingleInstance.onAlreadyRunning(instance -\u003e {\n            try {\n                // Forward arguments to the instance\n                for (String arg : args) {\n                    instance.send(\"Open\", arg.getBytes());\n                }\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n\n            // Quit the process\n            System.exit(0);\n        });\n\n        // We are on the first running instance here : initialize application\n        MyApp app = new MyApp();\n\n        // Start the IPC server and consume messages\n        SingleInstance.onMessage(message -\u003e {\n            // Handle the \"Open\" message\n            if (message.name().equals(\"Open\")) {\n                app.open(new String(message.data()));\n            }\n        });\n\n        // Continue execution\n        for (String arg : args) {\n            app.open(arg);\n        }\n    }\n\n    public void open(String argument) {\n        // ...\n    }\n}\n```\n\n## Licence\n\nThis project is licensed under the LGPLv3 licence. See [COPYING](./COPYING) and [COPYING.LESSER](./COPYING.LESSER) files for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent4vx%2Fsingleinstance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvincent4vx%2Fsingleinstance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvincent4vx%2Fsingleinstance/lists"}