Skip to content

Commit

Permalink
feat: Forwarded the event listener feature to the connection wrapped …
Browse files Browse the repository at this point in the history
…by the cache.
  • Loading branch information
chrisdutz committed Aug 14, 2024
1 parent 1f00503 commit d5c1b30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/
package org.apache.plc4x.java.utils.cache;

import org.apache.plc4x.java.api.EventPlcConnection;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.PlcConnectionManager;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.api.listener.EventListener;
import org.apache.plc4x.java.utils.cache.exceptions.PlcConnectionManagerClosedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -170,4 +172,17 @@ public void run() {
}
}


public void addEventListener(EventListener listener) {
if((connection != null) && (connection instanceof EventPlcConnection)) {
((EventPlcConnection) connection).addEventListener(listener);
}
}

public void removeEventListener(EventListener listener) {
if((connection != null) && (connection instanceof EventPlcConnection)) {
((EventPlcConnection) connection).removeEventListener(listener);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
*/
package org.apache.plc4x.java.utils.cache;

import org.apache.plc4x.java.api.EventPlcConnection;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.api.listener.EventListener;
import org.apache.plc4x.java.api.messages.*;
import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
import org.apache.plc4x.java.api.model.PlcQuery;
Expand All @@ -40,7 +42,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

public class LeasedPlcConnection implements PlcConnection {
public class LeasedPlcConnection implements EventPlcConnection {

private static final Logger log = LoggerFactory.getLogger(LeasedPlcConnection.class);
private final ConnectionContainer connectionContainer;
Expand Down Expand Up @@ -484,4 +486,14 @@ public PlcBrowseRequest.Builder addQuery(String name, String query) {
};
}

@Override
public void addEventListener(EventListener listener) {
connectionContainer.addEventListener(listener);
}

@Override
public void removeEventListener(EventListener listener) {
connectionContainer.removeEventListener(listener);
}

}

0 comments on commit d5c1b30

Please sign in to comment.