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

feat: Simplify usage of ListenerService API - MEED-7009 - Meeds-io/meeds#2116 #64

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

boubaker
Copy link
Member

@boubaker boubaker commented Jun 6, 2024

Using current implementation of ListenerService, it's difficult to trigger and to add event listeners. In fact the source code is very noisy when handling ListenerService, by example

  • to add a Listener:
listenerService.addListener("event.to.catch", new EventListener<> {
  public void onEvent(Event<S, D> event) {
     // Code ....
  }
});
  • to trigger an event:
try {
  listenerService.broadcast("", s, d);
} catch(Exception e) {
  ....
}

This change will use @FuntionalInterface behavior to allow using Lambda expressions and avoid having to catch a checked exception while broadcasting event.

(Resolves Meeds-io/meeds#2116)

…eds#2116

**Is your feature request related to a problem? Please describe.**
Using current implementation of `ListenerService`, it's difficult to trigger and to add event listeners. In fact the source code is very noisy when handling `ListenerService`, by example
-  to add a Listener:
```java
listenerService.addListener("event.to.catch", new EventListener<> {
  public void onEvent(Event<S, D> event) {
     // Code ....
  }
});
```
- to trigger an event:

```java
try {
  listenerService.broadcast("", s, d);
} catch(Exception e) {
  ....
}
```

This change will use `@FuntionalInterface` behavior to allow using Lambda expressions and avoid having to catch a checked exception while broadcasting event.
@boubaker boubaker enabled auto-merge (squash) June 6, 2024 15:19
Copy link

sonarcloud bot commented Jun 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
48.9% Coverage on New Code (required ≥ 60%)

See analysis details on SonarCloud

@boubaker boubaker merged commit 8cf08d9 into develop Jun 6, 2024
4 of 5 checks passed
@boubaker boubaker deleted the meed-7009 branch June 6, 2024 16:54
exo-swf pushed a commit that referenced this pull request Jun 6, 2024
…eds#2116 (#64)

**Is your feature request related to a problem? Please describe.**
Using current implementation of `ListenerService`, it's difficult to trigger and to add event listeners. In fact the source code is very noisy when handling `ListenerService`, by example
-  to add a Listener:
```java
listenerService.addListener("event.to.catch", new EventListener<> {
  public void onEvent(Event<S, D> event) {
     // Code ....
  }
});
```
- to trigger an event:

```java
try {
  listenerService.broadcast("", s, d);
} catch(Exception e) {
  ....
}
```

This change will use `@FuntionalInterface` behavior to allow using Lambda expressions and avoid having to catch a checked exception while broadcasting event.
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

Successfully merging this pull request may close these issues.

ListenerService isn't a Functional Interface and throws a sneaky exception
2 participants