{"id":20120790,"url":"https://github.com/npgall/mobility-rpc","last_synced_at":"2025-05-06T14:33:23.067Z","repository":{"id":57724695,"uuid":"41263895","full_name":"npgall/mobility-rpc","owner":"npgall","description":"Add Code Mobility to any application","archived":false,"fork":false,"pushed_at":"2016-03-22T00:18:50.000Z","size":1311,"stargazers_count":32,"open_issues_count":8,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-09-30T09:26:14.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npgall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-23T19:30:18.000Z","updated_at":"2022-11-23T01:58:15.000Z","dependencies_parsed_at":"2022-09-02T07:01:53.191Z","dependency_job_id":null,"html_url":"https://github.com/npgall/mobility-rpc","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/npgall%2Fmobility-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npgall%2Fmobility-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npgall%2Fmobility-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npgall%2Fmobility-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npgall","download_url":"https://codeload.github.com/npgall/mobility-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224511120,"owners_count":17323359,"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":[],"created_at":"2024-11-13T19:23:02.604Z","updated_at":"2024-11-13T19:23:03.137Z","avatar_url":"https://github.com/npgall.png","language":"Java","funding_links":[],"categories":["开发框架"],"sub_categories":["RPC框架"],"readme":"# Mobility-RPC #\n\nMobility-RPC is a Java library to bring seamless [Code Mobility](http://en.wikipedia.org/wiki/Code_mobility) to any application.\n\nMove objects or tasks, execution state, **and the underlying code**, seamlessly between JVMs or machines at runtime.\n\n\n## Overview of Mobility-RPC ##\n\n**Trivially easy to use**\n  * Move regular, unmodified Java code and objects between machines as easily as moving them around within a single application - without deploying code to the remote machines in advance\n  * Write objects which can move themselves around the network seamlessly, and statefully\n  * Invoke arbitrary methods or third-party libraries remotely, even if they were never designed for RPC\n  \n**Powerful Design Patterns**\n  * Take advantage of application architectures which are not possible with conventional RPC\n  * As well as the classic code mobility paradigms: remote evaluation, code on demand, mobile agents (see [Wikipedia](http://en.wikipedia.org/wiki/Code_mobility))\n  \n**High performance**\n  * More flexible, outperforms, and is more scalable than RMI (see [Performance Benchmark](documentation/PerformanceBenchmark.md))\n\nRead more: [What is Code Mobility?](documentation/WhatIsCodeMobility.md) and [How does Mobility-RPC differ from conventional RPC?](documentation/ConventionalRpcComparison.md)\n\n## Example Usage ##\nThese examples send objects to fictitious machines named [alice and bob](http://en.wikipedia.org/wiki/Alice_and_Bob).\nIn practice replace these with the name or ip address of an actual machine to which you want to send an object.\n\n\n---\n\n\n### Hello World ###\nPrint \"Hello World\" to the console on a remote machine called \"bob\".\n\nThe line of code `System.out.println(\"Hello World\")` is actually moved to the remote machine and executed there\nautomatically, even though it was not deployed there in advance.\n```java\npublic class HelloWorld {\n\n    public static void main(String[] args) {\n        QuickTask.execute(\"bob\", new Runnable() { public void run() {\n                System.out.println(\"Hello World\");\n        }});\n    }\n}\n```\n\n\n---\n\n\n### Retrieve Data ###\nRetrieve system properties from the remote machine and print to the console on the local machine.\n\n```java\npublic class RetrieveData {\n\n    public static void main(String[] args) {\n        Properties data = QuickTask.execute(\"bob\", new Callable\u003cProperties\u003e() {\n            public Properties call() throws Exception {\n                return System.getProperties();\n            }\n        });\n        System.out.println(data);\n    }\n}\n```\n\nHere a serialized `Callable` object, and its underlying bytecode, is sent to and executed on the remote machine, and the\nvalue it produced (a `Properties` object) is transported back to the local machine _seamlessly_.\n\n---\n\n\n### Boomerang Pattern ###\nThe Boomerang Pattern - a `Callable` object which returns itself.\n\nSend a Callable object to a remote machine, where it gathers some data, and then returns itself back to the local machine. The data is printed to the console on the local machine.\n```java\npublic class BoomerangPattern {\n\n    static class BoomerangObject implements Callable\u003cBoomerangObject\u003e {\n\n        private Properties someData;\n        private InetAddress someOtherData;\n\n        public BoomerangObject call() throws Exception {\n            someData = System.getProperties();\n            someOtherData = InetAddress.getLocalHost();\n            return this;\n        }\n    }\n\n    public static void main(String[] args) {\n        BoomerangObject boomerangObject = QuickTask.execute(\"bob\", new BoomerangObject());\n        System.out.println(boomerangObject.someData);\n        System.out.println(boomerangObject.someOtherData);\n    }\n}\n```\n\n\n---\n\n\n### Regular Object Migration ###\nTransfer a regular object to a remote machine. The object is not special in any way and does not implement any particular interfaces.\n\nSend the object, and call its `printDetails()` method on the remote machine.\n```java\npublic class RegularObjectMigration {\n\n    static class RegularObject {\n\n        private String name = \"Joe Bloggs\";\n        private String address = \"Sesame Street\";\n\n        public void printDetails() {\n            System.out.println(name);\n            System.out.println(address);\n        }\n    }\n\n    public static void main(String[] args) {\n        final RegularObject regularObject = new RegularObject();\n        QuickTask.execute(\"bob\", new Runnable() { public void run() {\n                regularObject.printDetails();\n        }});\n    }\n}\n```\n\n\n---\n\n\n### Mobile Agent ###\nAn object which autonomously migrates itself around the network.\n\nThe main method transfers the object to machine _bob_, where the run() method is called. It prints \"Hello World\" and its hop number, 1, to the console on _bob_.\n\nFrom _bob_ the object transfers itself to _alice_, which is the next machine on its list of machines to visit. It prints \"Hello World\" and its incremented hop number, 2, to the console on _alice_.\n\nFrom _alice_ the object transfers itself back to _bob_ again, where it prints \"Hello World\" and an incremented hop number, 3, but then it finds that it has run out of machines to visit, so it prints \"Ran out of machines to visit\".\n\n```java\npublic class MobileAgentPattern {\n\n    static class MobileAgent implements Runnable {\n        private List\u003cString\u003e machinesToVisit = new ArrayList\u003cString\u003e(Arrays.asList(\"alice\", \"bob\"));\n        private int hopNumber = 0;\n\n        public void run() {\n            MobilitySession session = MobilityContext.getCurrentSession();\n            System.out.println(\"Hello World, this is hop number: \" + (++hopNumber) + \" in \" + session);\n            if (machinesToVisit.isEmpty()) {\n                System.out.println(\"Ran out of machines to visit\");\n            } else {\n                // Migrate to next machine and remove from the list...\n                session.execute(machinesToVisit.remove(0), this);\n            }\n            session.release();\n        }\n    }\n    // Agent visits bob, then alice, then bob again...\n    public static void main(String[] args) {\n        QuickTask.execute(\"bob\", new MobileAgent());\n    }\n}\n```\n\n**Output on bob**\n```\nHello World, this is hop number: 1 in MobilitySession{sessionId=836d7e5f-42ca-445f-acf0-4db525dcd6ab}\nHello World, this is hop number: 3 in MobilitySession{sessionId=836d7e5f-42ca-445f-acf0-4db525dcd6ab}\nRan out of machines to visit\n```\n\n**Output on alice**\n```\nHello World, this is hop number: 2 in MobilitySession{sessionId=836d7e5f-42ca-445f-acf0-4db525dcd6ab}\n```\n\n\n---\n\n## Getting Started ##\n\n### Usage in Maven and Non-Maven Projects ###\n\nMobility-RPC is in Maven Central, and can be added to a Maven project as follows. See [ReleaseNotes](documentation/ReleaseNotes.md) for the latest version number.\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.googlecode.mobilityrpc\u003c/groupId\u003e\n    \u003cartifactId\u003emobility-rpc\u003c/artifactId\u003e\n    \u003cversion\u003ex.x.x\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nFor non-Maven projects, **and for running Mobility-RPC as a standalone server**, a version built with [maven-shade-plugin](http://maven.apache.org/plugins/maven-shade-plugin/) is also provided.\nIt contains Mobility-RPC and all of its own dependencies packaged in a single jar file (ending \"-all\"). It can be downloaded from Maven central as \"-all.jar\" [here](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.googlecode.mobilityrpc%22%20AND%20a%3A%22mobility-rpc%22).\n\n### Receive Incoming Objects ###\nYou can run Mobility-RPC as a library inside your application on remote machine(s), or you can run Mobility-RPC as a standalone server in its own right on remote machine(s).\n\n#### Run as a library: receive incoming objects in your application ####\nAdd the Maven dependency to your application, and have your application call the following method.\n```java\nEmbeddedMobilityServer.start();\n```\nYour application can then receive objects from client machines and those objects can interact with your application.\n\nNote if your application will both send and receive objects, it is recommended that you use the same `MobilityController` for both, as provided by [EmbeddedMobilityServer](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/quickstart/EmbeddedMobilityServer.html).\n\n#### Run as a standalone server: send objects to arbitrary machines ####\nDownload the *standalone* Mobility-RPC \"-all.jar\" from maven central as discussed above, and then there are two ways to launch it as follows.\n\n_**Method 1: Run in Graphical Mode**_\n\n![mobility-rpc-system-tray.png](documentation/images/mobility-rpc-system-tray.png)\n\n  * Double-click the jar on the machine on which you want to run the server. This will start Mobility-RPC as a standalone server, and it will add an icon to the system tray on Windows, the menu bar on Mac, or the notification area on Linux automatically.\n  * The icon displays the IP address on which the server is running, which you can use that to send objects to the machine. The icon also allows you to shut down the mobility-rpc server when you have finished.\n\n_**Method 2: Run from the command line**_\n\n  * The standalone server can be launched from the command line as follows: `java -jar mobility-rpc-x.x.x-all.jar`\n  * If a GUI is available, this will also start mobility-rpc standalone server in the system tray. If you wish to force the library not to use the GUI, supply \"`-Dcom.googlecode.mobilityrpc.headless=true`\" as a command line parameter. If no GUI is available in the first place (for example on a headless Linux server), the library will run \"headless\" automatically.\n\n**Firewalls**\n\nNote: if you have a firewall on the remote machine, choose to allow incoming connections to **port 5739** on that machine.\n\nSee [StandaloneMobilityServer](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/quickstart/StandaloneMobilityServer.html) for more details.\n\n\n---\n\n\n###  Running the Examples ###\nOnce you have launched Mobility-RPC as a server on a remote machine, take note of the IP address on which it is listening.\n\nThe best way to get started with Mobility-RPC, is then to add the library as a dependency to a Maven project, and try running a few of the examples above in your IDE, to send objects to the remote machine.\n\nCopy \u0026 paste the examples into your IDE, and replace \"alice\" or \"bob\" in the examples with the ip address on which the server is running. You can then start sending objects to the remote machine.\n\nYou can launch the server on multiple remote machines, to build more sophisticated applications or to send Mobile Agents around the network.\n\n\n---\n\n\n## API ##\nThe examples above mostly use the [QuickTask](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/quickstart/QuickTask.html) class, in the [quickstart](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/quickstart/package-summary.html) package - a simplified API to the library, wrapping the main APIs, tailored for specific use cases and for getting started with the library quickly.\n\nThe main APIs of the library are marked `[`public api`]` in the [API JavaDocs](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/index.html), but essentially the main API is as follows:\n\n  * [MobilityRPC](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/MobilityRPC.html) - A static factory, to get an instance of `MobilityController`\n  * [MobilityController](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/controller/MobilityController.html) - Manages an instance of the library\n  * [MobilitySession](http://htmlpreview.github.io/?http://raw.githubusercontent.com/npgall/mobility-rpc/master/documentation/javadoc/apidocs/com/googlecode/mobilityrpc/session/MobilitySession.html) - The gateway through which the application can send objects to remote machines\n\n## Compiling from source ##\nIf you want to compile from source and tinker with the internals of the library itself, you will need [Protobuf](http://code.google.com/p/protobuf/) on your machine. That's command `sudo port install protobuf-java` if you're on Mac, `sudo apt-get install protobuf-java` (or similar) if you're on Linux, or download the binaries manually from the Protobuf website if you're on Windows.\n\nNote that Mobility-RPC was compiled with Protobuf 2.4.1. If you will compile it with a newer version of Protobuf, remember to update the version of `protobuf-java` in the pom.xml file to match the version of Protobuf installed on your system.\n\n## Documentation ##\nFor more documentation, see the [documentation](documentation) directory.\n\n## Project Status ##\nMobility-RPC is in Maven Central (see above), and is largely feature-complete. See [ReleaseNotes](documentation/ReleaseNotes.md) for version details.\n\nReport any bugs/feature requests in the [Issues](http://github.com/npgall/mobility-rpc/issues) tab.\n\nFor support please use the [Discussion Group](http://groups.google.com/forum/?fromgroups#!forum/mobility-rpc-discuss), not direct email to the developers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpgall%2Fmobility-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpgall%2Fmobility-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpgall%2Fmobility-rpc/lists"}