This repository has been archived by the owner on Nov 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add netty buffer and nio buffer spring configuration
- Loading branch information
Showing
17 changed files
with
194 additions
and
193 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
package com.ardikars.jxnet.spring.boot.autoconfigure; | ||
|
||
import com.ardikars.common.tuple.Pair; | ||
import com.ardikars.jxnet.PcapPktHdr; | ||
import com.ardikars.jxpacket.common.Packet; | ||
|
||
|
@@ -27,18 +28,17 @@ | |
* Callback function used for capturing packets. | ||
* | ||
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.4.8 | ||
* @since 1.4.9 | ||
*/ | ||
public interface PacketHandler<T> { | ||
public interface JxpacketHandler<T> { | ||
|
||
/** | ||
* Next available packet. | ||
* @param argument user argument. | ||
* @param header pcap header. | ||
* @param packet {@link Packet} object. | ||
* @param packet a tuple of {@link PcapPktHdr} and {@link Packet}. | ||
* @throws ExecutionException execution exception. | ||
* @throws InterruptedException interrupted exception. | ||
*/ | ||
void next(T argument, PcapPktHdr header, Future<Packet> packet) throws ExecutionException, InterruptedException; | ||
void next(T argument, Future<Pair<PcapPktHdr, Packet>> packet) throws ExecutionException, InterruptedException; | ||
|
||
} |
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
43 changes: 0 additions & 43 deletions
43
...gure/src/main/java/com/ardikars/jxnet/spring/boot/autoconfigure/ReactorPacketHandler.java
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,12 @@ | |
|
||
package com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket; | ||
|
||
import com.ardikars.common.tuple.Pair; | ||
import com.ardikars.common.tuple.Tuple; | ||
import com.ardikars.jxnet.DataLinkType; | ||
import com.ardikars.jxnet.PcapHandler; | ||
import com.ardikars.jxnet.PcapPktHdr; | ||
import com.ardikars.jxnet.spring.boot.autoconfigure.PacketHandler; | ||
import com.ardikars.jxnet.spring.boot.autoconfigure.JxpacketHandler; | ||
import com.ardikars.jxpacket.common.Packet; | ||
import com.ardikars.jxpacket.common.UnknownPacket; | ||
import com.ardikars.jxpacket.core.ethernet.Ethernet; | ||
|
@@ -42,7 +44,7 @@ | |
* Jxpacket handler. | ||
* | ||
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.4.8 | ||
* @since 1.4.9 | ||
*/ | ||
@ConditionalOnClass({Packet.class, ByteBuf.class}) | ||
@Configuration("com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket.jxpacketHandler") | ||
|
@@ -51,7 +53,7 @@ public class JxpacketHandlerConfiguration<T> implements PcapHandler<T> { | |
private static final Log LOG = LogFactory.getLog(JxpacketHandlerConfiguration.class.getName()); | ||
|
||
private final int rawDataLinkType; | ||
private final PacketHandler<T> packetHandler; | ||
private final JxpacketHandler<T> packetHandler; | ||
private final ExecutorService executorService; | ||
|
||
/** | ||
|
@@ -62,17 +64,17 @@ public class JxpacketHandlerConfiguration<T> implements PcapHandler<T> { | |
*/ | ||
public JxpacketHandlerConfiguration(@Qualifier("com.ardikars.jxnet.spring.boot.autoconfigure.executorService") ExecutorService executorService, | ||
DataLinkType dataLinkType, | ||
PacketHandler<T> packetHandler) { | ||
JxpacketHandler<T> packetHandler) { | ||
this.rawDataLinkType = dataLinkType != null ? dataLinkType.getValue() : 1; | ||
this.packetHandler = packetHandler; | ||
this.executorService = executorService; | ||
} | ||
|
||
@Override | ||
public void nextPacket(final T user, final PcapPktHdr h, final ByteBuffer bytes) { | ||
Future<Packet> packet = executorService.submit(new Callable<Packet>() { | ||
Future<Pair<PcapPktHdr, Packet>> packet = executorService.submit(new Callable<Pair<PcapPktHdr, Packet>>() { | ||
@Override | ||
public Packet call() throws Exception { | ||
public Pair<PcapPktHdr, Packet> call() throws Exception { | ||
ByteBuf buffer = ByteBufAllocator.DEFAULT.directBuffer(bytes.capacity()); | ||
buffer.setBytes(0, bytes); | ||
Packet packet; | ||
|
@@ -81,11 +83,11 @@ public Packet call() throws Exception { | |
} else { | ||
packet = UnknownPacket.newPacket(buffer); | ||
} | ||
return packet; | ||
return Tuple.of(h, packet); | ||
} | ||
}); | ||
try { | ||
packetHandler.next(user, h, packet); | ||
packetHandler.next(user, packet); | ||
} catch (ExecutionException | InterruptedException e) { | ||
LOG.warn(e.getMessage()); | ||
} | ||
|
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
Oops, something went wrong.