diff --git a/.run/Source Log Listener.run.xml b/.run/Source Log Listener.run.xml new file mode 100644 index 0000000000..8a121bb8d9 --- /dev/null +++ b/.run/Source Log Listener.run.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.run/Source Rcon.run.xml b/.run/Source Rcon.run.xml new file mode 100644 index 0000000000..c3568f63c8 --- /dev/null +++ b/.run/Source Rcon.run.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/.run/Source Server Queries.run.xml b/.run/Source Server Queries.run.xml new file mode 100644 index 0000000000..cfd14dcad1 --- /dev/null +++ b/.run/Source Server Queries.run.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ba697a79c9..fa422c5cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ Changelog ------------- +1.1.0 - Bug fixes/enhancements + +- Enhancement #132: (source-log) Add method for checking if the log service has already been started + +1.0.8 - Bump dependency version + 1.0.7 - Bug fixes/enhancements - Bug #106: Game Server Port should be read as unsigned Short diff --git a/README.md b/README.md index 5b7858911c..3b75b4162d 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql - 1.0.8 + 1.1.0 ``` @@ -251,7 +251,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-steam-master - 1.0.8 + 1.1.0 ``` @@ -261,7 +261,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-source-query - 1.0.8 + 1.1.0 ``` @@ -272,7 +272,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-source-log - 1.0.8 + 1.1.0 ``` @@ -282,7 +282,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-source-rcon - 1.0.8 + 1.1.0 ``` @@ -292,7 +292,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-steam-webapi - 1.0.8 + 1.1.0 ``` @@ -302,7 +302,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-dota2-webapi - 1.0.8 + 1.1.0 ``` @@ -312,7 +312,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-csgo-webapi - 1.0.8 + 1.1.0 ``` @@ -324,7 +324,7 @@ Just add the following dependencies to your maven pom.xml. Only include the modu com.ibasco.agql agql-coc-webapi - 1.0.8 + 1.1.0 ``` diff --git a/examples/pom.xml b/examples/pom.xml index 88a24a43d5..5a80331ed2 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -93,17 +93,6 @@ maven-jar-plugin true - @@ -141,7 +130,7 @@ ch.qos.logback logback-core - 1.4.5 + 1.3.3 org.codehaus.janino @@ -151,37 +140,12 @@ ch.qos.logback logback-classic - 1.4.5 + 1.3.3 commons-cli commons-cli 1.5.0 - - \ No newline at end of file diff --git a/examples/src/main/java/com/ibasco/agql/examples/SourceLogListenerExample.java b/examples/src/main/java/com/ibasco/agql/examples/SourceLogListenerExample.java index 06f0036761..1d509992c7 100644 --- a/examples/src/main/java/com/ibasco/agql/examples/SourceLogListenerExample.java +++ b/examples/src/main/java/com/ibasco/agql/examples/SourceLogListenerExample.java @@ -19,11 +19,12 @@ import com.ibasco.agql.examples.base.BaseExample; import com.ibasco.agql.protocols.valve.source.query.logger.SourceLogEntry; import com.ibasco.agql.protocols.valve.source.query.logger.SourceLogListenService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** *

SourceLogListenerExample class.

@@ -41,8 +42,11 @@ public class SourceLogListenerExample extends BaseExample { public void run(String[] args) throws Exception { String address = promptInput("Please enter server address to listen on: ", true, null, "listenAddress"); int port = promptInputInt("Please enter the server port (default: 27500) : ", false, "27500"); - logService = new SourceLogListenService(new InetSocketAddress(address, port), SourceLogListenerExample::processLogData); + InetSocketAddress listenAddress = new InetSocketAddress(address, port); + logService = new SourceLogListenService(listenAddress, SourceLogListenerExample::processLogData); CompletableFuture f = logService.listen(); + System.out.printf("Listening on %s (listening: %s, future: %s)", listenAddress, logService.isListening(), logService.getListenFuture()); + assert logService.isListening(); f.join(); System.out.println("Log service has been closed"); } diff --git a/pom.xml b/pom.xml index b7419abb58..32757c1704 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 1.0.8 + 1.1.0 -SNAPSHOT 1.8 diff --git a/protocols/valve/source/log/src/main/java/com/ibasco/agql/protocols/valve/source/query/logger/SourceLogListenService.java b/protocols/valve/source/log/src/main/java/com/ibasco/agql/protocols/valve/source/query/logger/SourceLogListenService.java index 8411260b95..756cc12b3b 100644 --- a/protocols/valve/source/log/src/main/java/com/ibasco/agql/protocols/valve/source/query/logger/SourceLogListenService.java +++ b/protocols/valve/source/log/src/main/java/com/ibasco/agql/protocols/valve/source/query/logger/SourceLogListenService.java @@ -21,14 +21,12 @@ import com.ibasco.agql.core.util.Platform; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; +import io.netty.channel.*; import io.netty.channel.socket.DatagramChannel; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.Closeable; import java.io.IOException; import java.net.InetSocketAddress; @@ -38,8 +36,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** *

Listens for log messages produced by a Source Server.

@@ -86,6 +82,8 @@ public class SourceLogListenService implements Closeable { private volatile boolean started; + private volatile CompletableFuture listenFuture; + /** *

Creates a new service that will listen to any ip address * and bind to a random local port number (Similar to 0.0.0.0)

@@ -97,8 +95,7 @@ public SourceLogListenService() { /** *

Creates a new listen service for the provided {@link java.net.InetSocketAddress}. You will need to explicitly call {@link #listen()} to start listening for source log events

* - * @param listenAddress - * An {@link java.net.InetSocketAddress} where the listen service will bind or listen on + * @param listenAddress An {@link java.net.InetSocketAddress} where the listen service will bind or listen on */ public SourceLogListenService(InetSocketAddress listenAddress) { this(listenAddress, null); @@ -107,10 +104,8 @@ public SourceLogListenService(InetSocketAddress listenAddress) { /** *

Creates a new listen service for the provided {@link java.net.InetSocketAddress}. You will need to explicitly call {@link #listen()} to start listening for source log events

* - * @param listenAddress - * The {@link java.net.InetSocketAddress} to listen on - * @param callback - * The {@link java.util.function.Consumer} callback that will be notified once a log event has been received + * @param listenAddress The {@link java.net.InetSocketAddress} to listen on + * @param callback The {@link java.util.function.Consumer} callback that will be notified once a log event has been received */ public SourceLogListenService(InetSocketAddress listenAddress, Consumer callback) { this(listenAddress, callback, null, 0, true); @@ -119,16 +114,11 @@ public SourceLogListenService(InetSocketAddress listenAddress, ConsumerCreates a new listen service for the provided {@link java.net.InetSocketAddress}. You will need to explicitly call {@link #listen()} to start listening for source log events

* - * @param listenAddress - * The {@link java.net.InetSocketAddress} to listen on - * @param callback - * The {@link java.util.function.Consumer} callback that will be notified once a log event has been received - * @param executorService - * The {@link java.util.concurrent.ExecutorService} that will be used by the service. {@code null} to use the global executor provided by the library. - * @param nThreads - * The number of threads that will be used by the underlying {@link io.netty.channel.EventLoopGroup} (a special executor servicee used by netty). The value should normally be less than or equals to the core pool size of the executor service. - * @param useNative - * {@code true} if you prefer to use netty's native transports over java's NIO (e.g. epoll on linux, kqueue on osx) + * @param listenAddress The {@link java.net.InetSocketAddress} to listen on + * @param callback The {@link java.util.function.Consumer} callback that will be notified once a log event has been received + * @param executorService The {@link java.util.concurrent.ExecutorService} that will be used by the service. {@code null} to use the global executor provided by the library. + * @param nThreads The number of threads that will be used by the underlying {@link io.netty.channel.EventLoopGroup} (a special executor servicee used by netty). The value should normally be less than or equals to the core pool size of the executor service. + * @param useNative {@code true} if you prefer to use netty's native transports over java's NIO (e.g. epoll on linux, kqueue on osx) */ public SourceLogListenService(InetSocketAddress listenAddress, Consumer callback, ExecutorService executorService, int nThreads, boolean useNative) { EventLoopGroup group; @@ -175,8 +165,7 @@ public Consumer getLogEventCallback() { /** *

Sets the callback for listening on Raw Log Events

* - * @param callback - * A {@link java.util.function.Consumer} callback for raw log events + * @param callback A {@link java.util.function.Consumer} callback for raw log events */ public void setLogEventCallback(Consumer callback) { this.callbackRef.set(callback); @@ -194,11 +183,8 @@ public InetSocketAddress getListenAddress() { /** * Sets the listen address. * - * @param listenAddress - * The {@link java.net.InetSocketAddress} to listen on - * - * @throws java.lang.IllegalStateException - * If the service has been started already + * @param listenAddress The {@link java.net.InetSocketAddress} to listen on + * @throws java.lang.IllegalStateException If the service has been started already */ public void setListenAddress(InetSocketAddress listenAddress) { if (started) @@ -210,7 +196,6 @@ public void setListenAddress(InetSocketAddress listenAddress) { * Start listening for log messages. Please note that this is a non-blocking operation. If you need to block until the service is closed, then use the returned future which is notified once the underlying connection is closed. * * @return A {@link java.util.concurrent.CompletableFuture} that is notified once the connection is closed. This is notified either by an interrupt signal (SIGINT) or by invoking {@link #close()} - * * @see #setListenAddress(InetSocketAddress) * @see #close() */ @@ -222,11 +207,8 @@ public CompletableFuture listen() { /** * Start listening for log messages. Please note that this is a non-blocking operation. If you need to block until the service is closed, then use the returned future which is notified once the underlying connection is closed. * - * @param address - * The {@link java.net.InetSocketAddress} to listen on - * + * @param address The {@link java.net.InetSocketAddress} to listen on * @return A {@link java.util.concurrent.CompletableFuture} that is notified once the connection is closed. This is notified either by an interrupt signal (SIGINT) or by invoking {@link #close()} - * * @see #close() */ public CompletableFuture listen(InetSocketAddress address) { @@ -242,7 +224,21 @@ public CompletableFuture listen(InetSocketAddress address) { initialize(bindFuture, promise); else bindFuture.addListener((ChannelFutureListener) future -> initialize(future, promise)); - return promise.whenComplete((unused, throwable) -> bindInProgress = false); + return this.listenFuture = promise.whenComplete((unused, throwable) -> bindInProgress = false); + } + + /** + * @return The current future instance returned by {@link #listen(InetSocketAddress)} or {@code null} if service is not bounded to an address yet. + */ + public CompletableFuture getListenFuture() { + return this.listenFuture; + } + + /** + * @return {@code true} if service is currently bounded to an address + */ + public boolean isListening() { + return this.listenFuture != null && !this.listenFuture.isDone(); } private void initialize(ChannelFuture future, CompletableFuture promise) { @@ -276,7 +272,9 @@ private void notifyOnClose(ChannelFuture future, CompletableFuture promise } } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public void close() throws IOException { try {