Skip to content

Commit

Permalink
Update to latest gradle, remove shadow jar, updated copyright, genera…
Browse files Browse the repository at this point in the history
…l tidy-up
  • Loading branch information
eleventy7 committed Feb 18, 2023
1 parent a20e837 commit 20c4ca5
Show file tree
Hide file tree
Showing 218 changed files with 1,704 additions and 1,453 deletions.
7 changes: 3 additions & 4 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
direnv 2.32.1
java zulu-17.38.21
docker-compose 1.29.2
gradle 7.6
direnv 2.32.2
java zulu-17.40.19
gradle 8.0.1
70 changes: 70 additions & 0 deletions aeron-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

plugins {
application
checkstyle
}

val generatedDir = file("${buildDir}/generated/src/main/java")
val codecGeneration = configurations.create("codecGeneration")

dependencies {
"codecGeneration"(libs.sbe)
checkstyle(libs.checkstyle)
implementation(libs.agrona)
implementation(libs.aeron)
implementation(libs.slf4j)
implementation(libs.logback)
}

sourceSets {
main {
java.srcDirs("src/main/java", generatedDir)
}
}

tasks {

task ("uberJar", Jar::class) {
group = "uber"
manifest {
attributes["Main-Class"]="io.aeron.samples.admin.Admin"
}
archiveClassifier.set("uber")
from(sourceSets.main.get().output)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}

task("generateCodecs", JavaExec::class) {
group = "sbe"
val codecsFile = "src/main/resources/messages.xml"
val sbeFile = "src/main/resources/sbe/sbe.xsd"
inputs.files(codecsFile, sbeFile)
outputs.dir(generatedDir)
classpath = codecGeneration
mainClass.set("uk.co.real_logic.sbe.SbeTool")
args = listOf(codecsFile)
systemProperties["sbe.output.dir"] = generatedDir
systemProperties["sbe.target.language"] = "Java"
systemProperties["sbe.validation.xsd"] = sbeFile
systemProperties["sbe.validation.stop.on.error"] = "true"
outputs.dir(generatedDir)
}

compileJava {
dependsOn("generateCodecs")
}
}

testing {
suites {
// Configure the built-in test suite
val test by getting(JvmTestSuite::class) {
// Use JUnit Jupiter test framework
useJUnitJupiter(libs.versions.junitVersion.get())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@

public class Client
{
public static void main(String[] args)
public static void main(final String[] args)
{
final IdleStrategy idleStrategyClient = new SleepingMillisIdleStrategy();
final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
Expand All @@ -49,8 +49,8 @@ public static void main(String[] args)
System.out.println(mediaDriver.aeronDirectoryName());

//Construct the client agent
ClientAgent clientAgent = new ClientAgent(aeron, barrier);
AgentRunner clientAgentRunner = new AgentRunner(idleStrategyClient, Throwable::printStackTrace,
final ClientAgent clientAgent = new ClientAgent(aeron, barrier);
final AgentRunner clientAgentRunner = new AgentRunner(idleStrategyClient, Throwable::printStackTrace,
null, clientAgent);
AgentRunner.startOnThread(clientAgentRunner);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,7 @@ public class ClientAgent implements Agent
private ExclusivePublication publication;
private Subscription subscription;

public ClientAgent(Aeron aeron, ShutdownSignalBarrier barrier)
public ClientAgent(final Aeron aeron, final ShutdownSignalBarrier barrier)
{
this.demuxer = new ClientDemuxer(barrier);
this.aeron = aeron;
Expand Down Expand Up @@ -150,18 +150,19 @@ public String roleName()
return "client";
}

private void send(DirectBuffer buffer, int length)
private void send(final DirectBuffer buffer, final int length)
{
int retries = 3;

do
{
//in this example, the offset it always zero. This will not always be the case.
long result = publication.offer(buffer, 0, length);
final long result = publication.offer(buffer, 0, length);
if (result > 0)
{
break;
} else
}
else
{
log.info("aeron returned {} on offer", result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,23 +34,23 @@ public class ClientDemuxer implements FragmentHandler
private final MessageHeaderDecoder headerDecoder;
private final ShutdownSignalBarrier barrier;

public ClientDemuxer(ShutdownSignalBarrier barrier)
public ClientDemuxer(final ShutdownSignalBarrier barrier)
{
this.barrier = barrier;
this.responseEvent = new RpcResponseEventDecoder();
this.headerDecoder = new MessageHeaderDecoder();
}

@Override
public void onFragment(DirectBuffer buffer, int offset, int length, Header header)
public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header)
{
headerDecoder.wrap(buffer, offset);

switch (headerDecoder.templateId())
{
case RpcResponseEventEncoder.TEMPLATE_ID:
responseEvent.wrap(buffer, offset + headerDecoder.encodedLength(),
headerDecoder.blockLength(), headerDecoder.version());
headerDecoder.blockLength(), headerDecoder.version());
logger.info("Received {}", responseEvent.result());
barrier.signal();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,7 +32,7 @@ public class Server
{
private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);

public static void main(String[] args)
public static void main(final String[] args)
{
final IdleStrategy idleStrategy = new SleepingMillisIdleStrategy();
final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
Expand All @@ -53,13 +53,11 @@ public static void main(String[] args)

LOGGER.info("Dir {}", mediaDriver.aeronDirectoryName());
//Construct the server agent
ServerAgent serverAgent = new ServerAgent(aeron, barrier);
AgentRunner serverAgentRunner = new AgentRunner(idleStrategy, Throwable::printStackTrace,
final ServerAgent serverAgent = new ServerAgent(aeron, barrier);
final AgentRunner serverAgentRunner = new AgentRunner(idleStrategy, Throwable::printStackTrace,
null, serverAgent);
AgentRunner.startOnThread(serverAgentRunner);



//Await shutdown signal
barrier.await();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ public class ServerAgent implements Agent
private final ServerDemuxer demuxer;
private Subscription subscription;

public ServerAgent(Aeron aeron, ShutdownSignalBarrier barrier)
public ServerAgent(final Aeron aeron, final ShutdownSignalBarrier barrier)
{
this.aeron = aeron;
this.demuxer = new ServerDemuxer(aeron, barrier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Shaun Laurens.
* Copyright 2019-2023 Shaun Laurens.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,7 +46,7 @@ public class ServerDemuxer implements FragmentHandler
private final ExpandableDirectByteBuffer buffer;
private Publication publication;

public ServerDemuxer(Aeron aeron, ShutdownSignalBarrier barrier)
public ServerDemuxer(final Aeron aeron, final ShutdownSignalBarrier barrier)
{
this.connectRequest = new RpcConnectRequestDecoder();
this.requestMethod = new RpcRequestMethodDecoder();
Expand All @@ -59,7 +59,7 @@ public ServerDemuxer(Aeron aeron, ShutdownSignalBarrier barrier)
}

@Override
public void onFragment(DirectBuffer buffer, int offset, int length, Header header)
public void onFragment(final DirectBuffer buffer, final int offset, final int length, final Header header)
{
headerDecoder.wrap(buffer, offset);
final int headerLength = headerDecoder.encodedLength();
Expand All @@ -70,14 +70,14 @@ public void onFragment(DirectBuffer buffer, int offset, int length, Header heade
{
case RpcConnectRequestDecoder.TEMPLATE_ID:
connectRequest.wrap(buffer, offset + headerLength,
actingLength, actingVersion);
actingLength, actingVersion);
final int streamId = connectRequest.returnConnectStream();
final String uri = connectRequest.returnConnectUri();
blockingOpenConnection(streamId, uri);
break;
case RpcRequestMethodDecoder.TEMPLATE_ID:
requestMethod.wrap(buffer, offset + headerLength,
actingLength, actingVersion);
actingLength, actingVersion);
final String parameters = requestMethod.parameters();
final String correlation = requestMethod.correlation();
respond(parameters, correlation);
Expand All @@ -87,7 +87,7 @@ public void onFragment(DirectBuffer buffer, int offset, int length, Header heade
}
}

private void respond(String parameters, String correlation)
private void respond(final String parameters, final String correlation)
{
final String returnValue = parameters.toUpperCase();

Expand All @@ -100,21 +100,23 @@ private void respond(String parameters, String correlation)
int retries = 3;
do
{
long result = publication.offer(buffer, 0, headerEncoder.encodedLength() + responseEvent.encodedLength());
final long result = publication.offer(buffer, 0, headerEncoder.encodedLength() +
responseEvent.encodedLength());
if (result > 0)
{
//shutdown once the result is sent
barrier.signal();
break;
} else
}
else
{
log.warn("aeron returned {}", result);
}
}
while (--retries > 0);
}

private void blockingOpenConnection(int streamId, String uri)
private void blockingOpenConnection(final int streamId, final String uri)
{
log.info("Received connect request with response URI {} stream {}", uri, streamId);
publication = aeron.addExclusivePublication(uri, streamId);
Expand Down
2 changes: 1 addition & 1 deletion aeron-core/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright 2019-2022 Shaun Laurens.
~ Copyright 2019-2023 Shaun Laurens.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion aeron-core/src/main/resources/messages.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright 2019-2022 Shaun Laurens.
~ Copyright 2019-2023 Shaun Laurens.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion aeron-core/src/main/resources/sbe/sbe.xsd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019-2022 Shaun Laurens.
~ Copyright 2019-2023 Shaun Laurens.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion aeron-mdc/aeron-mdc-publisher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ ARG IMAGE_TAG=latest
FROM ${REPO_NAME}${IMAGE_NAME}:${IMAGE_TAG}
SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
WORKDIR /root/jar/
COPY --chmod=755 /build/libs/aeron-mdc-publisher-0.1-SNAPSHOT-all.jar /root/jar/aeron-mdc-publisher-0.1-SNAPSHOT-all.jar
COPY --chmod=755 /build/libs/aeron-mdc-publisher-uber.jar /root/jar/aeron-mdc-publisher-uber.jar
COPY --chmod=755 entrypoint.sh /root/jar/entrypoint.sh
ENTRYPOINT ["/root/jar/entrypoint.sh"]
41 changes: 41 additions & 0 deletions aeron-mdc/aeron-mdc-publisher/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

plugins {
application
checkstyle
}

dependencies {
checkstyle(libs.checkstyle)
implementation(libs.agrona)
implementation(libs.aeron)
implementation(libs.slf4j)
implementation(libs.logback)
}


tasks {

task("uberJar", Jar::class) {
group = "uber"
manifest {
attributes["Main-Class"] = "com.aeroncookbook.aeron.mdc.MultiDestinationPublisher"
}
archiveClassifier.set("uber")
from(sourceSets.main.get().output)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}
}

testing {
suites {
// Configure the built-in test suite
val test by getting(JvmTestSuite::class) {
// Use JUnit Jupiter test framework
useJUnitJupiter(libs.versions.junitVersion.get())
}
}
}
2 changes: 1 addition & 1 deletion aeron-mdc/aeron-mdc-publisher/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ java --add-opens java.base/sun.nio.ch=ALL-UNNAMED \
-javaagent:/root/aeron/aeron-agent-1.40.0.jar \
-Djava.net.preferIPv4Stack=true \
-Daeron.event.log=admin \
-jar /root/jar/aeron-mdc-publisher-0.1-SNAPSHOT-all.jar
-jar /root/jar/aeron-mdc-publisher-uber.jar
Loading

0 comments on commit 20c4ca5

Please sign in to comment.