-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring(plc4j): split up the raw socket transport into a "raw" an…
…d "raw-passive" transport, where the raw-passive is equivalent to the previous raw transport.
- Loading branch information
Showing
8 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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: 78 additions & 0 deletions
78
...java/org/apache/plc4x/java/transport/rawsocketpassive/RawSocketPassiveChannelFactory.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,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.plc4x.java.transport.rawsocketpassive; | ||
|
||
import io.netty.bootstrap.Bootstrap; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.EventLoopGroup; | ||
import io.netty.channel.ThreadPerChannelEventLoop; | ||
import io.netty.channel.oio.OioEventLoopGroup; | ||
import org.apache.plc4x.java.spi.configuration.HasConfiguration; | ||
import org.apache.plc4x.java.spi.connection.NettyChannelFactory; | ||
import org.apache.plc4x.java.utils.pcap.netty.config.PcapChannelOption; | ||
import org.apache.plc4x.java.utils.rawsockets.netty.RawSocketChannel; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.SocketAddress; | ||
|
||
public class RawSocketPassiveChannelFactory extends NettyChannelFactory implements HasConfiguration<RawSocketPassiveTransportConfiguration> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(RawSocketPassiveChannelFactory.class); | ||
|
||
private RawSocketPassiveTransportConfiguration configuration; | ||
|
||
public RawSocketPassiveChannelFactory(SocketAddress address) { | ||
super(address); | ||
} | ||
|
||
@Override | ||
public void setConfiguration(RawSocketPassiveTransportConfiguration configuration) { | ||
this.configuration = configuration; | ||
} | ||
|
||
@Override | ||
public Class<? extends Channel> getChannel() { | ||
return RawSocketChannel.class; | ||
} | ||
|
||
@Override | ||
public boolean isPassive() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public EventLoopGroup getEventLoopGroup() { | ||
return new ThreadPerChannelEventLoop(new OioEventLoopGroup()); | ||
} | ||
|
||
@Override | ||
public void configureBootstrap(Bootstrap bootstrap) { | ||
if(configuration != null) { | ||
logger.info("Configuring Bootstrap with {}", configuration); | ||
/*bootstrap.option(RawSocketChannelOption.PORT, configuration.getDefaultPort()); | ||
bootstrap.option(RawSocketChannelOption.PROTOCOL_ID, configuration.getProtocolId()); | ||
bootstrap.option(RawSocketChannelOption.SPEED_FACTOR, configuration.getReplaySpeedFactor());*/ | ||
if(configuration.getPcapPacketHandler() != null) { | ||
bootstrap.option(PcapChannelOption.PACKET_HANDLER, configuration.getPcapPacketHandler()); | ||
} | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...main/java/org/apache/plc4x/java/transport/rawsocketpassive/RawSocketPassiveTransport.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,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.plc4x.java.transport.rawsocketpassive; | ||
|
||
import org.apache.plc4x.java.spi.connection.ChannelFactory; | ||
import org.apache.plc4x.java.spi.transport.Transport; | ||
import org.apache.plc4x.java.utils.rawsockets.netty.address.RawSocketPassiveAddress; | ||
|
||
public class RawSocketPassiveTransport implements Transport { | ||
|
||
public static final String TRANSPORT_CODE = "raw-passive"; | ||
|
||
@Override | ||
public String getTransportCode() { | ||
return TRANSPORT_CODE; | ||
} | ||
|
||
@Override | ||
public String getTransportName() { | ||
return "Passive Raw Ethernet Transport"; | ||
} | ||
|
||
@Override | ||
public ChannelFactory createChannelFactory(String transportConfig) { | ||
RawSocketPassiveAddress address = new RawSocketPassiveAddress(transportConfig); | ||
return new RawSocketPassiveChannelFactory(address); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
.../apache/plc4x/java/transport/rawsocketpassive/RawSocketPassiveTransportConfiguration.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,25 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
package org.apache.plc4x.java.transport.rawsocketpassive; | ||
|
||
import org.apache.plc4x.java.transport.pcap.PcapTransportConfiguration; | ||
|
||
public interface RawSocketPassiveTransportConfiguration extends PcapTransportConfiguration { | ||
|
||
} |
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