hashgraph / hedera-services

Crypto, token, consensus, file, and smart contract services for the Hedera public ledger
Apache License 2.0
310 stars 136 forks source link

Inversion of control between Platform and App #5292

Closed swirlds-automation closed 5 months ago

swirlds-automation commented 1 year ago

This issue is outdated. The relation between Platform and App has already been refactored.

The main goal of this epic is to provide an API that makes it as easy + flexible as possible for an app developer to create an app that depend on the platform. In such case an app can have not only 1 platform but can 1-N platforms.

Current state

Today the platform is started by a main or by the browser and will start an application. This behavior is complex for app developers. Next to this there is a hard connection to the Browser that must be an optional component.

API idea

We discussed several ideas on the DevCon and the current idea looks like this:

It must be super easy for a developer to create an app and use the platform. The most easiest case should look like this:

class App {

    public static void main(String[] args) {
        final GlobalContext context = GlobalContextFactory.create();
        final Platform platform = PlatformFactory.create(context);
        platform.start();
    }
}

This code hides some details like the PlatformContext. A more complex example might look like this:

class App {

    public static void main(String[] args) {
        final GlobalContext globalContext = GlobalContextFactory.create("path/to/global.properties");
        final PlatformContext platformContext = PlatformContextFactory.create(globalContext, "path/to/app.properties");
        final Platform platform = PlatformFactory.create(platformContext);
        platform.start();
    }
}

Next to have this usecase (that uses the platform as a library) we still need to support the Browser and the functionallity to start & stop apps dynamically. Here is the example fake code from the DevCon:

class App implements Browsable {

    private Platform platform;

    @Override
    public void start(final GlobalContext globalContext ) {
        final PlatformContext platformContext = PlatformContextFactory.create(globalContext, "path/to/app.properties");
        platform = PlatformFactory.create(platformContext);
        platform.start();
    }

    @Override
    public void stop() {
        platform.stop();
    }

}
swirlds-automation commented 1 year ago

This epic is highly related to #5267 since the platform context and global context are needed author:hendrikebbers, createdAt:2022-09-15T20:49:43Z, updatedAt=2022-09-15T20:49:43Z

swirlds-automation commented 1 year ago

We had an additional round of discussion (@netopyr @nathanklick @hendrikebbers ) and decided that the platform should be used like a library. That means that we do not will provide a workflow like it is sketched with the Browsable interface. An app developer will create a platform instance "by hand". We discussed that it will make sense to rename the Browser to "Developer Tools" and handle it like that. Everything that has a portal like usecase should be added in future and do not belong to the "Developer Tools". Maybe that would be not even a desktop app but an web app, who knows.. author:hendrikebbers, createdAt:2022-09-16T15:07:50Z, updatedAt=2022-09-16T15:07:50Z

swirlds-automation commented 1 year ago

migrated from: url=https://github.com/swirlds/swirlds-platform/issues/6027 author:hendrikebbers, #:6027, createdAt:2022-09-15T19:59:30Z, updatedAt=2023-02-17T22:22:59Z labels=Epic,Migration:Base