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 async handler for netty and nio buffer
- Loading branch information
Showing
19 changed files
with
304 additions
and
204 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
45 changes: 45 additions & 0 deletions
45
...oot-autoconfigure/src/main/java/com/ardikars/jxnet/spring/boot/autoconfigure/Handler.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 @@ | ||
/** | ||
* Copyright (C) 2015-2018 Jxnet | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ardikars.jxnet.spring.boot.autoconfigure; | ||
|
||
import com.ardikars.common.annotation.Incubating; | ||
import com.ardikars.jxnet.PcapPktHdr; | ||
import com.ardikars.jxpacket.common.Packet; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Handler | ||
* @param <T> arg type. | ||
* @param <V> packet type. | ||
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.5.3 | ||
*/ | ||
@Incubating | ||
public interface Handler<T, V> { | ||
|
||
/** | ||
* Next available packet. | ||
* @param argument user argument. | ||
* @param packet a tuple of {@link PcapPktHdr} and {@link Packet}. | ||
* @throws ExecutionException execution exception. | ||
* @throws InterruptedException interrupted exception. | ||
*/ | ||
void next(T argument, V packet) throws ExecutionException, InterruptedException; | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
...nfigure/src/main/java/com/ardikars/jxnet/spring/boot/autoconfigure/HandlerConfigurer.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,82 @@ | ||
/** | ||
* Copyright (C) 2015-2018 Jxnet | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ardikars.jxnet.spring.boot.autoconfigure; | ||
|
||
import com.ardikars.common.annotation.Incubating; | ||
import com.ardikars.jxnet.DataLinkType; | ||
import com.ardikars.jxnet.context.Context; | ||
import com.ardikars.jxnet.spring.boot.autoconfigure.constant.JxnetObjectName; | ||
import com.ardikars.jxpacket.common.Packet; | ||
import com.ardikars.jxpacket.common.UnknownPacket; | ||
import com.ardikars.jxpacket.core.ethernet.Ethernet; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import java.nio.ByteBuffer; | ||
import java.util.concurrent.ExecutorService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
/** | ||
* | ||
* @param <T> type. | ||
* @param <V> packet type. | ||
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
*/ | ||
@Incubating | ||
public class HandlerConfigurer<T, V> { | ||
|
||
@Autowired | ||
@Qualifier(JxnetObjectName.EXECUTOR_SERVICE_BEAN_NAME) | ||
protected ExecutorService executorService; | ||
|
||
@Autowired | ||
@Qualifier(JxnetObjectName.CONTEXT_BEAN_NAME) | ||
protected Context context; | ||
|
||
@Autowired | ||
@Qualifier(JxnetObjectName.DATALINK_TYPE_BEAN_NAME) | ||
protected DataLinkType dataLinkType; | ||
|
||
@Autowired | ||
private Handler<T, V> handler; | ||
|
||
/** | ||
* Decode buffer. | ||
* @param bytes direct byte buffer. | ||
* @return returns {@link Packet}. | ||
*/ | ||
public Packet decode(ByteBuffer bytes) { | ||
ByteBuf buffer = Unpooled.wrappedBuffer(bytes); | ||
Packet packet; | ||
if (dataLinkType.getValue() == 1) { | ||
packet = Ethernet.newPacket(buffer); | ||
} else { | ||
packet = UnknownPacket.newPacket(buffer); | ||
} | ||
return packet; | ||
} | ||
|
||
/** | ||
* Get handler. | ||
* @return returns {@link Handler} implementation. | ||
*/ | ||
public Handler<T, V> getHandler() { | ||
return handler; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -21,24 +21,13 @@ | |
import com.ardikars.jxnet.PcapPktHdr; | ||
import com.ardikars.jxpacket.common.Packet; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Callback function used for capturing packets. | ||
* | ||
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.4.9 | ||
*/ | ||
public interface JxpacketAsyncHandler<T> { | ||
|
||
/** | ||
* Next available packet. | ||
* @param argument user argument. | ||
* @param packet a tuple of {@link PcapPktHdr} and {@link Packet}. | ||
* @throws ExecutionException execution exception. | ||
* @throws InterruptedException interrupted exception. | ||
*/ | ||
void next(T argument, CompletableFuture<Pair<PcapPktHdr, Packet>> packet) throws ExecutionException, InterruptedException; | ||
public interface JxpacketAsyncHandler<T> extends Handler<T, Pair<PcapPktHdr, Packet>> { | ||
|
||
} |
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 |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
import com.ardikars.jxnet.PcapPktHdr; | ||
import com.ardikars.jxpacket.common.Packet; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
|
||
/** | ||
|
@@ -30,15 +29,6 @@ | |
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.4.9 | ||
*/ | ||
public interface JxpacketHandler<T> { | ||
|
||
/** | ||
* Next available packet. | ||
* @param argument user argument. | ||
* @param packet a tuple of {@link PcapPktHdr} and {@link Packet}. | ||
* @throws ExecutionException execution exception. | ||
* @throws InterruptedException interrupted exception. | ||
*/ | ||
void next(T argument, Future<Pair<PcapPktHdr, Packet>> packet) throws ExecutionException, InterruptedException; | ||
public interface JxpacketHandler<T> extends Handler<T, Future<Pair<PcapPktHdr, Packet>>> { | ||
|
||
} |
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
import com.ardikars.common.tuple.Pair; | ||
import com.ardikars.jxnet.PcapPktHdr; | ||
import io.netty.buffer.ByteBuf; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
/** | ||
|
@@ -29,15 +29,6 @@ | |
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.4.9 | ||
*/ | ||
public interface NettyBufferHandler<T> { | ||
|
||
/** | ||
* Next available packet. | ||
* @param argument user argument. | ||
* @param packet a taple of {@link PcapPktHdr} and {@link ByteBuf}. | ||
* @throws ExecutionException execution exception. | ||
* @throws InterruptedException interrupted exception. | ||
*/ | ||
void next(T argument, Future<Pair<PcapPktHdr, ByteBuf>> packet) throws ExecutionException, InterruptedException; | ||
public interface NettyBufferHandler<T> extends Handler<T, Future<Pair<PcapPktHdr, ByteBuf>>> { | ||
|
||
} |
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 |
---|---|---|
|
@@ -19,8 +19,8 @@ | |
|
||
import com.ardikars.common.tuple.Pair; | ||
import com.ardikars.jxnet.PcapPktHdr; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
|
||
/** | ||
|
@@ -29,15 +29,6 @@ | |
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a> | ||
* @since 1.4.9 | ||
*/ | ||
public interface NioBufferHandler<T> { | ||
|
||
/** | ||
* Next available packet. | ||
* @param argument user argument. | ||
* @param packet a taple of {@link PcapPktHdr} and {@link ByteBuffer}. | ||
* @throws ExecutionException execution exception. | ||
* @throws InterruptedException interrupted exception. | ||
*/ | ||
void next(T argument, Future<Pair<PcapPktHdr, ByteBuffer>> packet) throws ExecutionException, InterruptedException; | ||
public interface NioBufferHandler<T> extends Handler<T, Future<Pair<PcapPktHdr, ByteBuffer>>> { | ||
|
||
} |
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
Oops, something went wrong.