|
14 | 14 | import java.util.Optional; |
15 | 15 |
|
16 | 16 | /** |
17 | | - * This class allows to bind an {@link AbstractActivity} to the Real Time Events source, or Datafeed. |
| 17 | + * This class allows to bind/unbind an {@link AbstractActivity} to the Real Time Events source, or Datafeed. |
18 | 18 | * It also maintains the list of registered activities. |
19 | 19 | * <p> |
20 | 20 | * If an activity to be registered is already existing in the registry, then the old one will be replaced. |
@@ -55,22 +55,30 @@ public void register(final AbstractActivity<?, ?> activity) { |
55 | 55 | this.activityList.add(activity); |
56 | 56 | } |
57 | 57 |
|
58 | | - public List<AbstractActivity<?, ?>> getActivityList() { |
59 | | - return new ArrayList<>(activityList); |
60 | | - } |
61 | | - |
62 | | - private void preProcessActivity(AbstractActivity<?, ?> activity) { |
63 | | - |
| 58 | + /** |
| 59 | + * Unregisters an activity from the registry. |
| 60 | + * |
| 61 | + * @param activity An activity. |
| 62 | + */ |
| 63 | + public void unregister(final AbstractActivity<?, ?> activity) { |
64 | 64 | Optional<AbstractActivity<?, ?>> act = this.activityList.stream() |
65 | 65 | .filter(a -> a.equals(activity)) |
66 | 66 | .findFirst(); |
67 | 67 |
|
68 | 68 | act.ifPresent(abstractActivity -> { |
69 | 69 | abstractActivity.bindToRealTimeEventsSource(this.datafeedLoop::unsubscribe); |
70 | 70 | this.activityList.remove(abstractActivity); |
71 | | - log.debug("One activity '{}' has been removed/unsubscribed in order to be replaced", |
| 71 | + log.debug("One activity '{}' has been removed/unsubscribed", |
72 | 72 | abstractActivity.getInfo().name()); |
73 | 73 | }); |
| 74 | + } |
| 75 | + |
| 76 | + public List<AbstractActivity<?, ?>> getActivityList() { |
| 77 | + return new ArrayList<>(activityList); |
| 78 | + } |
| 79 | + |
| 80 | + private void preProcessActivity(AbstractActivity<?, ?> activity) { |
| 81 | + unregister(activity); // Unregister, in case it already exists |
74 | 82 |
|
75 | 83 | // a command activity (potentially) needs the bot display name and user ID in order to parse the message text content |
76 | 84 | // this way of passing this information is not very clean though, we should find something |
|
0 commit comments