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

New Implementation of the Connection-Cache #747

Merged
merged 21 commits into from
Jan 21, 2023

Conversation

chrisdutz
Copy link
Contributor

New-implementation of the Connection Cache and removal of both the old connection-cache as well as the connection-pool.

In addition some types in the API module were updated:

  • The PlcDriverManager was renamed to DefaultPlcDriverManager
  • A new Type PlcDriverManager
  • A new Type PlcConnectionManager
  • PlcDriverManager contains a getConnectionManager() method
  • PlcDriverManager contains a static method getDefault() which returns an instance of the DefaultDriverManager
  • DefaultPlcDriverManager implements both interfaces

…ding the datatypes in case of raw address queries.
…read device telemetry from the PLC using MDP
…ch just contains the getConnection variants in preparation of building a drop-in replacement plc-connection cache.
…read device telemetry from the PLC using MDP

- Added some more data to the example (now we have the memory usage in %)
- Mostly untested draft implementation ... tests are coming.
- Implemented the timeout for leases
- Added some more tests for timeouts
- Updated the rest of the project to use the new cache and deleted the old implementations.
- Created 2 new interfaces PlcConnectionManager and PlcDriverManager
- Renamed the previous PlcDriverManager to DefaultPlcDriverManager
…ection-cache-and-scraper-ng

# Conflicts:
#	plc4go/protocols/knxnetip/readwrite/model/KnxManufacturer.go
#	plc4j/drivers/knxnetip/src/main/generated/org/apache/plc4x/java/knxnetip/readwrite/KnxManufacturer.java
…ection-cache-and-scraper-ng

# Conflicts:
#	plc4j/tools/opm/src/test/java/org/apache/plc4x/java/opm/PlcEntityInterceptorTest.java

private static final Logger LOGGER = LoggerFactory.getLogger(PlcDriverManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(org.apache.plc4x.java.DefaultPlcDriverManager.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static final Logger LOGGER = LoggerFactory.getLogger(org.apache.plc4x.java.DefaultPlcDriverManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPlcDriverManager.class);

* @return PlcConnection object.
* @throws PlcConnectionException an exception if the connection attempt failed.
*/
PlcConnection getConnection(String url, PlcAuthentication authentication) throws PlcConnectionException;
Copy link
Contributor

Choose a reason for hiding this comment

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

@chrisdutz we should some day think about using the option pattern from Golang here to (the ones with the varargs options). This way we could combine the getConnection into one method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well that is incompatible with the try-with-resources pattern ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least I think so

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think that should be a Problem but maybe I don't see it :D


PlcConnection create() throws PlcConnectionException;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should leave the create method as deprecated default implementation:

default PlcConnection create() {
    return getConnectionManager().create();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What for? I mean ... we're obviously not using it.

Copy link
Contributor

Choose a reason for hiding this comment

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

because it is part of the API package an might break exiting deployments from customers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's agree on not calling them "customers" as they are missing one important aspect of a typical customer relation.
I would say that "customers" have the chance to come forward and announce this would break things for them. I would consider it important to have backward compatibility once we are at 1.0.0. But I wouldn't object your proposal. Feel free to add it.

}
//if (configuration.isLoadSymbolAndDataTypeTables()) {
context.fireConnected();
// future.completeExceptionally(new PlcConnectionException(
Copy link
Contributor

Choose a reason for hiding this comment

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

is the outcommmented code here an accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No ... it's a first step to make it possible to still connect to an ADS without loading the symbol table (if you just use raw addresses) ...

</plugin>
</plugins>
</build>

</project>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
</project>
</project>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seriously? Not willing to do a discussion on the usage of new-lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -27,7 +27,7 @@
</encoder>
</appender>

<root level="error">
<root level="info">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<root level="info">
<root level="error">

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using the logging to output information on INFO level ... what good would the application be, if we set the log level to Error and just stripped all usable output? If yes, then you should have suggested a logger entry to explicitly set the log level of the application to info, but this change doesn't make any sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Couple of months back I turned them all up to error as we just exceeded the logoutput because of the size of our build. Those changes where all in the test-logback.xml. Just noticed that this is the main logback file so that should be fine so nvm


public PlcConnection getConnection(String url) throws PlcConnectionException {
ConnectionContainer connectionContainer;
synchronized (connectionContainers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

an alternative here might be the use of the ConcurrentHashMap

*/
@Test
public void testSingleConnectionRequestTest() throws PlcConnectionException {
PlcConnectionManager mockConnectionManager = Mockito.mock(PlcConnectionManager.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is also the Mockito Annotation which is pretty cool to use

<root level="error">
<logger name="org.apache.plc4x.java.utils.cache" level="debug"/>

<root level="info">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<root level="info">
<root level="error">

@@ -27,7 +27,9 @@
</encoder>
</appender>

<root level="error">
<logger name="org.apache.plc4x.java.utils.cache" level="debug"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<logger name="org.apache.plc4x.java.utils.cache" level="debug"/>
<logger name="org.apache.plc4x.java.utils.cache" level="error"/>

</dependency>
</dependencies>

</project>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
</project>
</project>

<artifactId>plc4j-connection-cache</artifactId>
<version>0.11.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
</project>
</project>

<description>Utility to efficiently collect a large number of items on multiple devices by different triggers.</description>

<dependencies>
<!--Jackson-->
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe remove those outcommented deps

Copy link
Contributor

@sruehl sruehl left a comment

Choose a reason for hiding this comment

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

Left some suggestions which should be easy to apply

@chrisdutz chrisdutz merged commit b3b8513 into develop Jan 21, 2023
@chrisdutz chrisdutz deleted the feature/cdutz/connection-cache-and-scraper-ng branch January 21, 2023 17:12
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.

None yet

2 participants