-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify chained profile implementation.
Closes #85. Earlier implementation from 2021/2022 did rely on thread local. While collision at thread local were unlikely to spot, overall architecture of this component become fairly complex. In order to simplify and keep it in clean shape internal call flow have been redesigned to rely on local stack. Since all profiles are known before hand, we can use order of their creation as well as intention (callback method call), to determine direction in which we should navigate further. Once all callbacks are passed, a framework callback is called. Signed-off-by: Łukasz Dywicki <[email protected]>
- Loading branch information
Showing
9 changed files
with
266 additions
and
151 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../main/java/org/connectorio/addons/profile/counter/internal/state/DummyStateRetriever.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...r/src/test/java/org/connectorio/addons/profile/counter/internal/CollectorProfileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c/test/java/org/connectorio/addons/profile/counter/internal/EnergyCounterProfileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
...profile/src/main/java/org/connectorio/addons/profile/internal/ChainedProfileCallback.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...dons.profile/src/main/java/org/connectorio/addons/profile/internal/NavigableCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.connectorio.addons.profile.internal; | ||
|
||
import org.openhab.core.thing.link.ItemChannelLink; | ||
import org.openhab.core.thing.profiles.ProfileCallback; | ||
import org.openhab.core.types.Command; | ||
import org.openhab.core.types.State; | ||
|
||
/** | ||
* Callback implementation which is aware of its position in chain. | ||
* | ||
* When this callback is asked to dispatch command or sate it passes it to chain with upper (state) | ||
* or lower (command) element index. This construction allows to move state/command information | ||
* across entire chain without too complex logic. Finalization of the call happens n stacked profile | ||
* callback which know chain boundaries. | ||
*/ | ||
public class NavigableCallback implements ProfileCallback { | ||
|
||
private final ItemChannelLink link; | ||
private final int index; | ||
private final StackedProfileCallback stack; | ||
|
||
public NavigableCallback(ItemChannelLink link, int index, StackedProfileCallback stack) { | ||
this.link = link; | ||
this.index = index; | ||
this.stack = stack; | ||
} | ||
|
||
@Override | ||
public void handleCommand(Command command) { | ||
stack.handleCommand(index - 1, command); | ||
} | ||
|
||
@Override | ||
public void sendCommand(Command command) { | ||
stack.sendCommand(index - 1, command); | ||
} | ||
|
||
@Override | ||
public void sendUpdate(State state) { | ||
stack.sendUpdate(index + 1, state); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Chained Callback [" + link + " at index " + index + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.