-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split into two modules, document the differences
- Loading branch information
Showing
31 changed files
with
619 additions
and
350 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
target/ | ||
.idea/ | ||
*.iml | ||
*.iml | ||
.mvn/ | ||
logs/ |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
/build/ | ||
|
||
.mvn |
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,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>name.maxdeliso</groupId> | ||
<artifactId>teflon</artifactId> | ||
<version>1.0.5-SNAPSHOT</version> | ||
</parent> | ||
<groupId>name.maxdeliso.teflon</groupId> | ||
<artifactId>core</artifactId> | ||
<version>1.0.5-SNAPSHOT</version> | ||
<name>core</name> | ||
<description>core Teflon classes</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.5</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.dagger</groupId> | ||
<artifactId>dagger</artifactId> | ||
<version>${dagger.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.25</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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,10 @@ | ||
module name.maxdeliso.teflon.core { | ||
requires slf4j.api; | ||
requires gson; | ||
requires dagger; | ||
requires javax.inject; | ||
|
||
exports name.maxdeliso.teflon.core.data; | ||
exports name.maxdeliso.teflon.core.net; | ||
exports name.maxdeliso.teflon.core.di; | ||
} |
2 changes: 1 addition & 1 deletion
2
...so/teflon/data/JsonMessageMarshaller.java → ...flon/core/data/JsonMessageMarshaller.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
2 changes: 1 addition & 1 deletion
2
...a/name/maxdeliso/teflon/data/Message.java → ...e/maxdeliso/teflon/core/data/Message.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
3 changes: 2 additions & 1 deletion
3
...deliso/teflon/data/MessageMarshaller.java → ...o/teflon/core/data/MessageMarshaller.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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package name.maxdeliso.teflon.data; | ||
package name.maxdeliso.teflon.core.data; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Optional; | ||
|
||
public interface MessageMarshaller { | ||
Optional<Message> bufferToMessage(final byte[] buffer); | ||
|
||
ByteBuffer messageToBuffer(final Message message); | ||
} |
89 changes: 89 additions & 0 deletions
89
core/src/main/java/name/maxdeliso/teflon/core/di/TeflonCoreModule.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,89 @@ | ||
package name.maxdeliso.teflon.core.di; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import name.maxdeliso.teflon.core.data.JsonMessageMarshaller; | ||
import name.maxdeliso.teflon.core.data.Message; | ||
import name.maxdeliso.teflon.core.net.NetSelector; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import java.net.InetAddress; | ||
import java.net.NetworkInterface; | ||
import java.net.SocketAddress; | ||
import java.net.SocketException; | ||
import java.net.UnknownHostException; | ||
import java.nio.ByteBuffer; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Supplier; | ||
|
||
@Module | ||
public class TeflonCoreModule { | ||
private static final Logger LOG = LoggerFactory.getLogger(TeflonCoreModule.class); | ||
|
||
@Provides | ||
@Singleton | ||
BlockingQueue<Message> provideMessageQueue(@Named("teflon.backlogLength") final int backlogLength) { | ||
return new LinkedBlockingQueue<>(backlogLength); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
InetAddress provideInetAddress(@Named("teflon.host.address") final String hostAddress) { | ||
try { | ||
// NOTE: this causes a DNS Query to run | ||
return InetAddress.getByName(hostAddress); | ||
} catch (UnknownHostException uhe) { | ||
LOG.error("failed to process multicast group from config", uhe); | ||
throw new RuntimeException(uhe); | ||
} | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
NetworkInterface provideNetworkInterface(@Named("teflon.host.interface") final String hostInterface) { | ||
try { | ||
// NOTE: this invokes some platform specific code | ||
return NetworkInterface.getByName(hostInterface); | ||
} catch (final SocketException se) { | ||
LOG.error("failed to process interface name from config", se); | ||
throw new RuntimeException(se); | ||
} | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
NetSelector provideNetSelector(@Named("teflon.udp.port") final int udpPort, | ||
@Named("teflon.udp.bufferLength") final int bufferLength, | ||
final BiConsumer<SocketAddress, byte[]> incomingConsumer, | ||
final InetAddress multicastGroupAddress, | ||
final NetworkInterface multicastInterface, | ||
final Supplier<ByteBuffer> outgoingDataSupplier) { | ||
return new NetSelector( | ||
udpPort, | ||
bufferLength, | ||
incomingConsumer, | ||
multicastGroupAddress, | ||
multicastInterface, | ||
outgoingDataSupplier); | ||
|
||
} | ||
|
||
@Provides | ||
@Singleton | ||
Gson provideGSON() { | ||
return new GsonBuilder().create(); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
JsonMessageMarshaller provideJsonMessageMarshaller(final Gson gson) { | ||
return new JsonMessageMarshaller(gson); | ||
} | ||
} |
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.