Skip to content

Commit

Permalink
update agones. (#96)
Browse files Browse the repository at this point in the history
Full implementation of Agones sdk.
  • Loading branch information
portlek authored Feb 15, 2024
1 parent 22caf89 commit 6686124
Show file tree
Hide file tree
Showing 25 changed files with 1,792 additions and 1,110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
if: "github.event.release.prerelease"
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'skip-snapshot') }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
Expand Down
76 changes: 64 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
# agones4j
[![idea](https://www.elegantobjects.org/intellij-idea.svg)](https://www.jetbrains.com/idea/)

![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/tr.com.infumia/agones4j?label=maven-central&server=https%3A%2F%2Foss.sonatype.org%2F)
![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/tr.com.infumia/agones4j?label=maven-central&server=https%3A%2F%2Foss.sonatype.org)
## How to Use (Developers)
### Code
```java
final class Server {

public static void main(
final String[] args
) {
final var sdk = new tr.com.infumia.agones4j.AgonesSdk();
}
}
```
```groovy
dependencies {
implementation "io.grpc:grpc-stub:1.47.0"
Expand All @@ -23,3 +11,67 @@ dependencies {
implementation "tr.com.infumia:agones4j:VERSION"
}
```
```java
import java.time.Duration;

void agones() {
final ExecutorService gameServerWatcherExecutor =
Executors.newSingleThreadExecutor();
final ScheduledExecutorService healthCheckExecutor =
Executors.newSingleThreadScheduledExecutor();
final Agones agones = Agones.builder()
// Address specification.
// If not specified, localhost:9357 will be used.
// All the following methods are creating a ManagedChannel with 'usePlaintext'
// If you need to use SSL, you can use 'withChannel(ManagedChannel)' method.
.withAddress("localhost", 9357)
.withAddress("localhost") // 9357
.withAddress(9357) // localhost
.withAddress() // localhost 9357
.withTarget("localhost:9357")
.withTarget() // localhost:9357
.withChannel(ManagedChannelBuilder
.forAddress("localhost", 9357)
.usePlaintext()
.build())
.withChannel() // localhost:9357
// Game server watcher executor specification.
.withGameServerWatcherExecutor(gameServerWatcherExecutor)
// Health checker executor specification.
// Check you game server's health check threshold and
// set the executor's delay and period accordingly.
.withHealthCheck(
/* delay */Duration.ofSeconds(1L),
/* period */Duration.ofSeconds(2L)
)
.withHealthCheckerExecutor(healthCheckExecutor)
.build();

// Health checking.
// Checks if the executor, delay and period are specified.
if (agones.canHealthCheck()) {
// Automatic health checking.
// Uses the health checker executor and the specified delay and period.
agones.startHealthChecking();
}

// Manual health checking.
final StreamObserver<Empty> requester = agones.healthCheck();
// onNext needs to be called continuously to keep the game server healthy.
requester.onNext(Empty.getDefaultInstance());

// Stopping the health checking.
agones.stopHealthChecking();

// Game server watching.
// Checks if the executor is specified.
if (agones.canWatchGameServer()) {
agones.addGameServerWatcher(gameServer ->
// This will be called when the game server is updated.
System.out.println("Game server updated: " + gameServer));
}

agones.allocate();
agones.shutdown();
}
```
57 changes: 22 additions & 35 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@ val signRequired = !rootProject.property("dev").toString().toBoolean()

group = "tr.com.infumia"

repositories {
mavenCentral()
}

dependencies {
compileOnlyApi(libs.protobuf)
compileOnlyApi(libs.grpc.protobuf)
compileOnlyApi(libs.grpc.stub)
compileOnlyApi(libs.annotationsapi)
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets {
Expand All @@ -33,11 +43,14 @@ sourceSets {
}

protobuf {
protoc { artifact = libs.protoc.get().toString() }

plugins {
id("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:${libs.versions.grpc.get()}"
}
}

generateProtoTasks {
all().forEach {
it.plugins {
Expand Down Expand Up @@ -76,40 +89,12 @@ tasks {
}

processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

build {
dependsOn(spotlessApply)
dependsOn(jar)
dependsOn(sourcesJar)
dependsOn(javadocJar)
}
}

repositories {
mavenCentral()
}

dependencies {
compileOnlyApi(libs.protobuf)
compileOnlyApi(libs.grpc.protobuf)
compileOnlyApi(libs.grpc.stub)
compileOnlyApi(libs.annotationsapi)

compileOnly(libs.lombok)
compileOnly(libs.annotations)

annotationProcessor(libs.lombok)
annotationProcessor(libs.annotations)

testAnnotationProcessor(libs.lombok)
testAnnotationProcessor(libs.annotations)
}

spotless {
lineEndings = LineEnding.UNIX
isEnforceCheck = false

java {
target("**/src/main/java/tr/com/infumia/agones4j/**")
Expand All @@ -120,14 +105,16 @@ spotless {
trimTrailingWhitespace()
prettier(
mapOf(
"prettier" to "2.7.1",
"prettier-plugin-java" to "1.6.2"
"prettier" to "3.2.5",
"prettier-plugin-java" to "2.5.0"
)
).config(
mapOf(
"parser" to "java",
"tabWidth" to 2,
"useTabs" to false
"useTabs" to false,
"printWidth" to 120,
"plugins" to listOf("prettier-plugin-java"),
)
)
}
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
grpc = "1.61.1"
protobuf = "3.25.2"

[libraries]
lombok = { module = "org.projectlombok:lombok", version = "1.18.30" }
annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
protobuf = { module = "com.google.protobuf:protobuf-java", version = "3.25.2" }
protobuf = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
protoc = { module = "com.google.protobuf:protoc", version.ref = "protobuf" }
grpc-stub = { module = "io.grpc:grpc-stub", version.ref = "grpc" }
grpc-protobuf = { module = "io.grpc:grpc-protobuf", version.ref = "grpc" }
annotationsapi = { module = "org.apache.tomcat:annotations-api", version = "6.0.53" }
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Loading

0 comments on commit 6686124

Please sign in to comment.