You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Christofer Dutz <ch...@c-ware.de> on 2023/01/08 14:35:54 UTC

[DISCUSS] Refactor the PlcDriverManager in Java?

Hi all,

I’m currently working on a new Connection Cache for Java and have stumbled over two things:

The one is the fact, that the PlcDriverManager is a class and not an interface.
This makes it problematic for me to have the PlcDriverManager implement the same interface.
I could probably override every method, so this is not a big problem.
However, having a PlcDriverManager interface would be the cleaner solution.
This would require us to change the name of the current PlcDriverManager class to something like DefaultPlcDriverManager… this would be a breaking change.

Another is that the getConnection doesn’t return a Future … the main reason for this was the try-with-resources pattern, that automatically closes the PlcConnection returned from getConnection.
However, returning a future might be the better option and it would be more like in the other languages.
Especially when we’re working with cached connections. Here a client might be waiting a while till it gets a connection handle.
This also would be a breaking change.


What do you folks think?

Chris



Re: [DISCUSS] Refactor the PlcDriverManager in Java?

Posted by Christofer Dutz <ch...@c-ware.de>.
So I noticed, while doing this

That the DriverManager has the two “getConnection” methods, but a load of others about listing drivers, accessing driver implementations etc.
So for now I settled with introducing a “PlcConnectionManager” interface and having the PlcDriverManager implement that (well … it already did)
This interface simply contains the two getConnection methods.

This way the CachedConnectionManager simply implements this interface and is exchangeable.

Chris



From: Łukasz Dywicki <lu...@code-house.org>
Date: Sunday, 8. January 2023 at 23:10
To: dev@plc4x.apache.org <de...@plc4x.apache.org>
Subject: Re: [DISCUSS] Refactor the PlcDriverManager in Java?
Hey Chris,
I second approach with interfaces as it clearly cuts implementation and
declaration of operations. It could also help people who use OSGi
because making a PlcDriverManager valid osgi service will be easier
(lighter) with interface. It boils down to runtime where proxy for
interface type is built in JVM while proxy for class involves cglib/asm etc.

Best,
Łukasz

On 8.01.2023 15:35, Christofer Dutz wrote:
> Hi all,
>
> I’m currently working on a new Connection Cache for Java and have stumbled over two things:
>
> The one is the fact, that the PlcDriverManager is a class and not an interface.
> This makes it problematic for me to have the PlcDriverManager implement the same interface.
> I could probably override every method, so this is not a big problem.
> However, having a PlcDriverManager interface would be the cleaner solution.
> This would require us to change the name of the current PlcDriverManager class to something like DefaultPlcDriverManager… this would be a breaking change.
>
> Another is that the getConnection doesn’t return a Future … the main reason for this was the try-with-resources pattern, that automatically closes the PlcConnection returned from getConnection.
> However, returning a future might be the better option and it would be more like in the other languages.
> Especially when we’re working with cached connections. Here a client might be waiting a while till it gets a connection handle.
> This also would be a breaking change.
>
>
> What do you folks think?
>
> Chris
>
>
>

Re: [DISCUSS] Refactor the PlcDriverManager in Java?

Posted by Łukasz Dywicki <lu...@code-house.org>.
Hey Chris,
I second approach with interfaces as it clearly cuts implementation and 
declaration of operations. It could also help people who use OSGi 
because making a PlcDriverManager valid osgi service will be easier 
(lighter) with interface. It boils down to runtime where proxy for 
interface type is built in JVM while proxy for class involves cglib/asm etc.

Best,
Łukasz

On 8.01.2023 15:35, Christofer Dutz wrote:
> Hi all,
> 
> I’m currently working on a new Connection Cache for Java and have stumbled over two things:
> 
> The one is the fact, that the PlcDriverManager is a class and not an interface.
> This makes it problematic for me to have the PlcDriverManager implement the same interface.
> I could probably override every method, so this is not a big problem.
> However, having a PlcDriverManager interface would be the cleaner solution.
> This would require us to change the name of the current PlcDriverManager class to something like DefaultPlcDriverManager… this would be a breaking change.
> 
> Another is that the getConnection doesn’t return a Future … the main reason for this was the try-with-resources pattern, that automatically closes the PlcConnection returned from getConnection.
> However, returning a future might be the better option and it would be more like in the other languages.
> Especially when we’re working with cached connections. Here a client might be waiting a while till it gets a connection handle.
> This also would be a breaking change.
> 
> 
> What do you folks think?
> 
> Chris
> 
> 
> 

Re: [DISCUSS] Refactor the PlcDriverManager in Java?

Posted by Christofer Dutz <ch...@c-ware.de>.
I just noticed, that the PlcDriverManager currently does more stuff than we need for the caches.
So, I simply created a PlcConnectionManager interface with the two getConnection methods.
This way we don’t even have to refactor anything, and problem number 1 is solved.

From: Christofer Dutz <ch...@c-ware.de>
Date: Sunday, 8. January 2023 at 15:36
To: dev@plc4x.apache.org <de...@plc4x.apache.org>
Subject: [DISCUSS] Refactor the PlcDriverManager in Java?
Hi all,

I’m currently working on a new Connection Cache for Java and have stumbled over two things:

The one is the fact, that the PlcDriverManager is a class and not an interface.
This makes it problematic for me to have the PlcDriverManager implement the same interface.
I could probably override every method, so this is not a big problem.
However, having a PlcDriverManager interface would be the cleaner solution.
This would require us to change the name of the current PlcDriverManager class to something like DefaultPlcDriverManager… this would be a breaking change.

Another is that the getConnection doesn’t return a Future … the main reason for this was the try-with-resources pattern, that automatically closes the PlcConnection returned from getConnection.
However, returning a future might be the better option and it would be more like in the other languages.
Especially when we’re working with cached connections. Here a client might be waiting a while till it gets a connection handle.
This also would be a breaking change.


What do you folks think?

Chris