You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/04/07 15:37:48 UTC

[plc4x] branch develop updated: - Moved the Plc4xBootstrap to the test-channel (renamed it to EmbeddedBootstrap) to avoid OSGI problems.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new d40333d  - Moved the Plc4xBootstrap to the test-channel (renamed it to EmbeddedBootstrap) to avoid OSGI problems.
d40333d is described below

commit d40333d8b81b86239c1b87d1668230032bfa59cf
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Apr 7 17:37:39 2020 +0200

    - Moved the Plc4xBootstrap to the test-channel (renamed it to EmbeddedBootstrap) to avoid OSGI problems.
---
 .../plc4x/java/spi/connection/NettyChannelFactory.java       | 11 +++++++++--
 .../src/main/java/io/netty/bootstrap/EmbeddedBootstrap.java} | 12 ++++--------
 .../src/main/java/io/netty/bootstrap/EventLoopProvider.java  |  0
 .../apache/plc4x/java/transport/test/TestChannelFactory.java |  8 ++++++--
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/NettyChannelFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/NettyChannelFactory.java
index c42a845..f07b88a 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/NettyChannelFactory.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/NettyChannelFactory.java
@@ -20,7 +20,6 @@
 package org.apache.plc4x.java.spi.connection;
 
 import io.netty.bootstrap.Bootstrap;
-import io.netty.bootstrap.Plc4xBootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandler;
@@ -60,6 +59,14 @@ public abstract class NettyChannelFactory implements ChannelFactory {
     public abstract Class<? extends Channel> getChannel();
 
     /**
+     * We need to be able to override this in the TestChanelFactory
+     * @return the Bootstrap instance we will be using to initialize the channel.
+     */
+    protected Bootstrap createBootstrap() {
+        return new Bootstrap();
+    }
+
+    /**
      * This Method is used to modify the Bootstrap Element of Netty, if one wishes to do so.
      * E.g. for Protocol Specific extension.
      * For TCP e.g.
@@ -85,7 +92,7 @@ public abstract class NettyChannelFactory implements ChannelFactory {
     @Override
     public Channel createChannel(ChannelHandler channelHandler) throws PlcConnectionException {
         try {
-            Bootstrap bootstrap = new Plc4xBootstrap();
+            Bootstrap bootstrap = createBootstrap();
 
             final EventLoopGroup workerGroup = getEventLoopGroup();
             if(workerGroup != null) {
diff --git a/plc4j/spi/src/main/java/io/netty/bootstrap/Plc4xBootstrap.java b/plc4j/transports/test/src/main/java/io/netty/bootstrap/EmbeddedBootstrap.java
similarity index 78%
rename from plc4j/spi/src/main/java/io/netty/bootstrap/Plc4xBootstrap.java
rename to plc4j/transports/test/src/main/java/io/netty/bootstrap/EmbeddedBootstrap.java
index c30e401..ea99a21 100644
--- a/plc4j/spi/src/main/java/io/netty/bootstrap/Plc4xBootstrap.java
+++ b/plc4j/transports/test/src/main/java/io/netty/bootstrap/EmbeddedBootstrap.java
@@ -20,18 +20,14 @@ package io.netty.bootstrap;
 
 import io.netty.channel.Channel;
 
-public class Plc4xBootstrap extends Bootstrap {
+public class EmbeddedBootstrap extends Bootstrap {
 
     @Override
     public Bootstrap validate() {
         if(channelFactory() != null) {
-             if(channelFactory().toString().contains("EmbeddedChannel")) {
-                 if (config().handler() == null) {
-                     throw new IllegalStateException("handler not set");
-                 }
-             } else {
-                 return super.validate();
-             }
+            if (config().handler() == null) {
+                throw new IllegalStateException("handler not set");
+            }
         } else {
             return super.validate();
         }
diff --git a/plc4j/spi/src/main/java/io/netty/bootstrap/EventLoopProvider.java b/plc4j/transports/test/src/main/java/io/netty/bootstrap/EventLoopProvider.java
similarity index 100%
rename from plc4j/spi/src/main/java/io/netty/bootstrap/EventLoopProvider.java
rename to plc4j/transports/test/src/main/java/io/netty/bootstrap/EventLoopProvider.java
diff --git a/plc4j/transports/test/src/main/java/org/apache/plc4x/java/transport/test/TestChannelFactory.java b/plc4j/transports/test/src/main/java/org/apache/plc4x/java/transport/test/TestChannelFactory.java
index e7b206f..573416c 100644
--- a/plc4j/transports/test/src/main/java/org/apache/plc4x/java/transport/test/TestChannelFactory.java
+++ b/plc4j/transports/test/src/main/java/org/apache/plc4x/java/transport/test/TestChannelFactory.java
@@ -19,10 +19,9 @@ under the License.
 package org.apache.plc4x.java.transport.test;
 
 import io.netty.bootstrap.Bootstrap;
+import io.netty.bootstrap.EmbeddedBootstrap;
 import io.netty.channel.Channel;
-import io.netty.channel.DefaultEventLoop;
 import io.netty.channel.EventLoopGroup;
-import io.netty.channel.embedded.EmbeddedChannel;
 import io.netty.channel.embedded.Plc4xEmbeddedChannel;
 import org.apache.plc4x.java.spi.configuration.HasConfiguration;
 import org.apache.plc4x.java.spi.connection.NettyChannelFactory;
@@ -52,6 +51,11 @@ public class TestChannelFactory extends NettyChannelFactory implements HasConfig
     }
 
     @Override
+    protected Bootstrap createBootstrap() {
+        return new EmbeddedBootstrap();
+    }
+
+    @Override
     public EventLoopGroup getEventLoopGroup() {
         return null;
     }