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

HTTP-Bridge add support for time based subscribes #2539

Merged
merged 14 commits into from
Feb 21, 2024

Conversation

michaelgrill
Copy link
Contributor

now to get an instance of a BridgeHttp the following code needs to be added

@Reference
private BridgeHttpFactory httpBridgeFactory;
private BridgeHttp httpBridge;

@Activate
private void activate() {
    this.httpBridge = this.httpBridgeFactory.get();
}

@Deactivate
private void deactivate() {
    this.httpBridgeFactory.unget(this.httpBridge);
    this.httpBridge = null;
}

as far as i know the exception which is happening is not intended to happen but for now to avoid unexpected behaviour because of the exception this is the prefered way to use it.

  • Made CycleSubscriber thread safe to avoid concurrent modification exceptions

  • Added time based subscribtions
    simple example to add a subscription with a delay of 1 minute between the calls would be

 final var delayProvider = DelayTimeProviderChain.fixedDelay(new Delay(1L, TimeUnit.MINUTES);
 this.httpBridge.subscribeTime(delayProvider, "http://127.0.0.1/status", t -> {
 	// process data
 }, t -> {
 	// handle error
 });

Copy link

Code Coverage

Copy link

Code Coverage

@Sn0w3y
Copy link
Contributor

Sn0w3y commented Feb 13, 2024

@michaelgrill could you check if my fix for my Pull is now using it correctly?

Also please review the Implementations of the Shelly devices if you can?

[PullRequest](https://github.com/OpenEMS/openems/pull/2519/files#diff-3d5ae9c7ded7d622bee13862ce0399cbb1d8f040a1fae7f863b6a9e6dddb53f1)

Copy link

Code Coverage

Copy link

Code Coverage

Copy link

Code Coverage

Copy link
Contributor

@sfeilmeier sfeilmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you both for the professional code & review! 👍

@sfeilmeier sfeilmeier changed the title Edge: HTTP-Bridge add support for time based subscribes HTTP-Bridge add support for time based subscribes Feb 21, 2024
@sfeilmeier sfeilmeier merged commit 37cb29a into develop Feb 21, 2024
2 checks passed
@sfeilmeier sfeilmeier deleted the feature/enhance-http-bridge branch February 21, 2024 22:39
TRACE(false) //
;

private final boolean bodyAllowed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelgrill I would just make this public final boolean isBodyAllowed; - and avoid the getter.

fanass-dev pushed a commit to fanass-dev/openems that referenced this pull request May 6, 2024
…#2539)

- "Fixed" bug where an exception gets throw during deactivation of a component using the HTTP-Bridge (ty @Sn0w3y OpenEMS#2381 (comment))

now to get an instance of a `BridgeHttp` the following code needs to be added

```
@reference
private BridgeHttpFactory httpBridgeFactory;
private BridgeHttp httpBridge;

@activate
private void activate() {
    this.httpBridge = this.httpBridgeFactory.get();
}

@deactivate
private void deactivate() {
    this.httpBridgeFactory.unget(this.httpBridge);
    this.httpBridge = null;
}
```
as far as i know the exception which is happening is not intended to happen but for now to avoid unexpected behaviour because of the exception this is the prefered way to use it.

- Made CycleSubscriber thread safe to avoid concurrent modification exceptions

- Added time based subscribtions
  simple example to add a subscription with a delay of 1 minute between the calls would be
  
```
 final var delayProvider = DelayTimeProviderChain.fixedDelay(new Delay(1L, TimeUnit.MINUTES);
 this.httpBridge.subscribeTime(delayProvider, "http://127.0.0.1/status", t -> {
 	// process data
 }, t -> {
 	// handle error
 });
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants