Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project with new solutions #248

Open
2 of 3 tasks
stachu540 opened this issue Jan 3, 2021 · 1 comment
Open
2 of 3 tasks

Refactor project with new solutions #248

stachu540 opened this issue Jan 3, 2021 · 1 comment

Comments

@stachu540
Copy link
Contributor

stachu540 commented Jan 3, 2021

Prerequisites

  • If this is a question/suggestion, I have already considered discuss it on Discord Server
  • This issue specifically has something to do with Twitch4J
  • I have attempted to look for similar issues already

Description

Current calling solutions uses feign + hystrix - typical hybrid and advanced solutions when retrofit using it. All solutions are handling on Dynamice Proxy Classes using Annotations in Runtime. But I didn't see any RequestBuild thing solution for specific methods, only putting some null variables when we didn't overload methods when null is not nessecarly (we don't need them). To solving any painful searching solutions, I try solving it using OUR own HttpClient. Each request are returns Rest<T> class call (where T is returned type of call). Also I have some other ideas. Not only our new HttpClient too. Merging auth and external dependency eventmanager to new core project. And managable SocketClient in our way.

HttpClient

Client will always returns Rest class call to resolving response sync (get / execute) or async (enqueue), with mapping them and resolving mappings after calling response. Also we can delay our response using Duration. We can complexing our Rest class call to reactive results too using defined methods.

Internal EventManager

Currently eventmanager uses as external dependency. Merging it will solving some download dependency problems and it will be internal with the project. Some users doesn't like download additional dependency for that. "for that" I mean.

auth project migration

auth project should be together with core project. Also we can create interface for caching token into variate solution. We can cache only one AppCredential and it will serve for service-only solutions and projects, providing for App Token only calls. Also we can use Predicate to getting stored credential or trying remove them from stored interface.

Custom SocketClient

You can name it as WebSocketClient. Our customization allows uses internal calls (using jre HttpClient's) or external depends: okhttp or nv-websocket-client. With okhttp we can easily build WebSocket interface with no complexity (you can proxing same way like using like this) . nv-websocket-client is a complex. Storing our address, event (not our lib event), and proxy data, and throws Exception if we trying uses WebSocketFactory#createSocket, we wanna try avoid that and move definition to method (not into constructor). JRE 11 have own WebSocket client so we can provide it too, if it is possible.

Solutions

  1. Creates our HttpClient which are returns Rest<T> class call (where T is returned type of call)
    • Rest can be mapped using map or flatMap
    • Rest have handlers for successful onSuccesss, throwable onError (with specific error type) and onComplete
    • Rest call can be freezed before call using Duration for specific time
    • Rest can having caching solutions for many entries
  2. No more external eventmanager dependency. EventManager only inside the library.
    • using lists, reactive, coroutines or else.
    • Creating LoggingEventManager for logging and debugging events
    • Adding new events for calling Rest interaction (creating, executing, callbacking, mapping etc.)
  3. Merge auth project to new core project
    • Adding TokenCache with search result using Predicate, id or login and and caching AppCredential for application
    • creating URL using CodeFlowRequest
  4. Creates our SocketClient using 3 ways: okhttp, [Socket (for jre8)/ WebSocket (for jre11)] or nv-websocket-client

Alternatives

Sitting and thingking about how to reporoduce those methods when users doesn't needs adding nulls to request or what else. Or try replicate methods when javadoc will be expanded and overloaded with data.

TL;DR If you think it is a joke, you are got damn right. 😄

Additional context

This schematic is a only prototype. They can be changed in time:
twitch4j-classes
Legend:
All fields have getters / setters
+ - public
# - protected
- - private

The solution needs to discuss
Sample calls:

helix.getModerators(credential, spec -> { // method will reads user id and token from credential
   spec.limit = 100 // limit for each page or none if you wanna caching them all
   spec.userId = Arrays.asList(208416203, 541118541) // filter by user id
}) // returns Rest<List<Moderator>> or IterableRest<Moderator>
   .enqueue(Duration.ofSeconds(10), response -> {}, error -> {}) // after 10 seconds will consume on response, otherwise will throws on error consumer
   // .forEach(result -> {}) // if it is IterableRest
@stachu540 stachu540 changed the title Rebuilding project with new solutions Refactor project with new solutions Jan 3, 2021
@stachu540
Copy link
Contributor Author

stachu540 commented May 5, 2021

Client code will be provided as private repository. Maintainers have access to this repo. After some clarification for this changes we will provide some proposal changes and improvements to this repository.

Provided code will be supports with streamlabs4j

And also planning improvements for Kotlin developers to improve his source code with external functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant