question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ProjectServiceClient refactoring

See original GitHub issue

PoC

There is a requirement to refactor existed org.eclipse.che.ide.api.project.ProjectServiceClient.

Due to upgrade a GWT library to 2.8, we can use java 8 features. So, there is no need to work with Promises library and according to refactoring resource management (https://github.com/eclipse/che/issues/3248) and we can perform some refactoring tasks:

Needed for: https://github.com/eclipse/che/issues/4222

Changes

Refactor AsyncRequestCallback

There is a proposal to create an adapter for the org.eclipse.che.ide.rest.AsyncRequestCallback which can operate with java 8 consumers. (issue link)

Class diagram

requestcallbacktoconsumeradapter

Example of usage consumers in client service to obtain a DTO obejct:

    public void getItemMetaData(Consumer<DTO> success, Consumer<Throwable> fail) {
        reqFactory.createGetRequest(...)
                  .send(new RequestCallbackToConsumerAdapter<DTO>(unmarshallerFactory.newUnmarshaller(DTO.class)) {
                      @Override
                      public Consumer<DTO> getSuccessConsumer() {
                          return success;
                      }

                      @Override
                      public Consumer<Throwable> getErrorConsumer() {
                          return fail;
                      }
                  });
    }

Example of usage consumers in client service to obtain just success result (w/o DTO):

    public void getItemMetaData(Consumer<Void> success, Consumer<Throwable> fail) {
        reqFactory.createGetRequest(...)
                  .send(new RequestCallbackToConsumerAdapter<Void>() {
                      @Override
                      public Consumer<Void> getSuccessConsumer() {
                          return success;
                      }

                      @Override
                      public Consumer<Throwable> getErrorConsumer() {
                          return fail;
                      }
                  });
    }

Refactor AsyncRequest

Deprecations

  • Mark methods as deprecated (issue link):
    • org.eclipse.che.ide.rest.AsyncRequest#send(org.eclipse.che.ide.rest.Unmarshallable<R>)
    • org.eclipse.che.ide.rest.AsyncRequest#send()
    • Remove deprecated methods in next sprints (issue link)

As far as these methods operates with Promises they aren’t efficient.

Refactor ProjectServiceClient

There is a proposal do decouple ProjectServiceClient component into two standalone components that will perform separate operations based on the physical objects (files, folders) and logical (projects).

Physical operations (issue link)

There is no need to mix file based operations with logical, so we can extract resource-based operations into component called FileSystemClient.

Class diagram

filesystemclient

Participants

  • FileSystemClient - main entry point for operating with resources’ metadata;

    • injects FileSystemClientImplementorFactory and creates a new instance of FileSystemClientImp which holds in the class and not public for developers;
    • provides public consumer-based API for the operating with resources:
      • getItemMetaData;
      • createEmptyFile;
      • readFileContentAsText;
      • writeNewFileContent;
      • createFolder;
      • deleteItemMetaData;
      • copyItemMetaData;
      • moveItemMetaData;
      • getChildrenMetaData;
      • getTreeMetaData;
      • search;
    • delegates requests from the public API into FileSystemClientImp.
  • FileSystemClientImp - implementation bridge for the FileSystemClient that allows to be extended independently from the FileSystemClient, at the moment duplicates the public API.

  • FileSystemClientImplementorFactory - factory for producing implementation for the implementor bridge.

  • FileSystemApiModule - Gin module for configuring main components that works together on the ide-app part;

    • binds FileSystemClient as Singleton;
    • binds FileSystemClientImplementorFactory to WsAgentFileSystemImplementorFactory as Singleton.
  • WsAgentFileSystemImplementor - bridge implementation for the communicating with particular workspace agent, implements FileSystemClientImp.

  • WsAgentFileSystemImplementorFactory - factory for producing a new instance of WsAgentFileSystemImplementor.

Logical operations (issue link)

As far as file based operations moved to the standalone component, operations with projects also might be moved to component called ProjectClient

Class diagram

projectclient

Participants

  • ProjectClient - main entry point for operating with projects’ metadata;

    • injects ProjectClientImplementorFactory and creates a new instance of ProjectClientImp which holds in the class and not public for developers;
    • provides public consumer-based API for the operating with project configurations:
      • getProjectsConfiguration;
      • getProjectConfiguration;
      • updateProjectConfiguration;
      • createProject;
      • createProjects;
      • importProject;
      • resolveFolder;
      • estimateFolder;
    • delegates requests from the public API into ProjectClientImp.
  • ProjectClientImp - implementation bridge for the ProjectClient that allows to be extended independently from the ProjectClient, at the moment duplicates the public API.

  • ProjectClientImplementorFactory - factory for producing implementation for the implementor bridge.

  • ProjectApiModule - existed Gin module, that adds additional configuration for main components that works together on the ide-app part;

    • binds ProjectClient as Singleton;
    • binds ProjectClientImplementorFactory to WsAgentProjectCLientImplementorFactory as Singleton.
  • WsAgentProjectClientImplementor - bridge implementation for the communicating with particular workspace agent, implements ProjectClientImp.

  • WsAgentProjectClientImplementorFactory - factory for producing a new instance of WsAgentProjectClientImplementor.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vparfonovcommented, Jul 11, 2017

We don’t need refactoring just for refactoring, if it not solve some concrete problem. At least for now

2reactions
dkuleshovcommented, Jul 12, 2017

Due to upgrade a GWT library to 2.8, we can use java 8 features.

I must admit that that’s a very bright idea however at the moment we can’t completely stop using javascript promise wrappers until we will have appropriate alternatives inside GWT (e.g. CompletableFuture). So here we should proceed with caution to leave backward compatibility.

Examples of usage of consumers in client service looks just fine to me, I would also recommend to overload single parameter methods like

public void getItemMetaData(Consumer<DTO> success) {
        reqFactory.createGetRequest(...)
                  .send(new RequestCallbackToConsumerAdapter<DTO>(unmarshallerFactory.newUnmarshaller(DTO.class)) {
                      @Override
                      public Consumer<DTO> getSuccessConsumer() {
                          return success;
                      }

                      @Override
                      public Consumer<Throwable> getErrorConsumer() {
                          return t -> {};
                      }
                  });
    }

or something similar for all possible variants.

There is a proposal do decouple ProjectServiceClient component into two standalone components that will perform separate operations based on the physical objects (files, folders) and logical (projects).

In general sounds quite reasonable. Speaking about the implementation itself I would argue for method names and purposes. However that’s a topic for more specific implementation-related discussion.

In my opinion the author underlined an important task of moving our project for a deep support of java 8 features, which is obviously a pretty important initiative in general. Though the description lacks implementation details to have more accurate understanding of author’s vision, the idea in general seems to be quite okay so I guess we can proceed with further more specific conversations in dedicated issues.

My only concern here is that we’re in a process of moving some REST-based functionality to JSON-RPC based and that would obviously impact the project service, so it might be a good idea to finish the transition to the new architecture first. It is quite possible that moving to the new way of communication will change the ProjectServiceClient to some degree as well, so this specification may become outdated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resource manager framework refactoring and unit test covering
The main goals of refactoring resource manager component is to: Clean up the existed codebase, which includes in removing deprecated methods ...
Read more >
FaultContract Based 的Exception Handling in WCF - 51CTO博客
NOTE: You can use the "Rename" command on the "Refactor" menu to change the ... ProjectServiceClient sv = new ProjectServiceClient();.
Read more >
Easy places to start in refactoring Java to Microservices
The good news is that refactoring your code is not as hard as you may think and in many cases, it's actually pretty...
Read more >
FaultContract Based 的Exception Handling in WCF - quietwalk
NOTE: You can use the "Rename" command on the "Refactor" menu to change the ... ProjectServiceClient sv = new ProjectServiceClient();.
Read more >
Refactoring made easy with IntelliCode! - Visual Studio Blog
Have you ever found yourself refactoring your code and making the same or similar changes in multiple locations?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found