public class SourceLogListenService extends Object implements Closeable
Listens for log messages produced by a Source Server.
NOTE: Ensure that the address of this service is registered to the source server, do this by registering it with 'logaddress_add [ip:port]'
to receive log
messages from the game server.
Make sure that the port specified is not being blocked by an external service or firewall
SourceLogListenService service = new SourceLogListenService(new InetSocketAddress(0));
service.setLogEventCallback(SourceLogEventHandler::handleLogMessages);
service.listen(); //non-blocking
service.listen().join(); //blocking (will wait until close() is called or until the service is closed)
public class SourceLogEventPrinter {
public static void handleLogMessages(SourceLogEntry logEntry) {
System.out.println(logEntry.getMessage());
}
}
Constructor and Description |
---|
SourceLogListenService()
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)
|
SourceLogListenService(InetSocketAddress listenAddress)
Creates a new listen service for the provided
InetSocketAddress . |
SourceLogListenService(InetSocketAddress listenAddress,
Consumer<SourceLogEntry> callback)
Creates a new listen service for the provided
InetSocketAddress . |
SourceLogListenService(InetSocketAddress listenAddress,
Consumer<SourceLogEntry> callback,
ExecutorService executorService,
int nThreads,
boolean useNative)
Creates a new listen service for the provided
InetSocketAddress . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
InetSocketAddress |
getListenAddress()
Getter for the field
listenAddress . |
CompletableFuture<Void> |
getListenFuture() |
Consumer<SourceLogEntry> |
getLogEventCallback()
Retrieve the callback assigned for Raw Log Events
|
boolean |
isListening() |
CompletableFuture<Void> |
listen()
Start listening for log messages.
|
CompletableFuture<Void> |
listen(InetSocketAddress address)
Start listening for log messages.
|
void |
setListenAddress(InetSocketAddress listenAddress)
Sets the listen address.
|
void |
setLogEventCallback(Consumer<SourceLogEntry> callback)
Sets the callback for listening on Raw Log Events
|
public SourceLogListenService()
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)
public SourceLogListenService(InetSocketAddress listenAddress)
Creates a new listen service for the provided InetSocketAddress
. You will need to explicitly call listen()
to start listening for source log events
listenAddress
- An InetSocketAddress
where the listen service will bind or listen onpublic SourceLogListenService(InetSocketAddress listenAddress, Consumer<SourceLogEntry> callback)
Creates a new listen service for the provided InetSocketAddress
. You will need to explicitly call listen()
to start listening for source log events
listenAddress
- The InetSocketAddress
to listen oncallback
- The Consumer
callback that will be notified once a log event has been receivedpublic SourceLogListenService(InetSocketAddress listenAddress, Consumer<SourceLogEntry> callback, ExecutorService executorService, int nThreads, boolean useNative)
Creates a new listen service for the provided InetSocketAddress
. You will need to explicitly call listen()
to start listening for source log events
listenAddress
- The InetSocketAddress
to listen oncallback
- The Consumer
callback that will be notified once a log event has been receivedexecutorService
- The ExecutorService
that will be used by the service. null
to use the global executor provided by the library.nThreads
- The number of threads that will be used by the underlying 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.useNative
- true
if you prefer to use netty's native transports over java's NIO (e.g. epoll on linux, kqueue on osx)public Consumer<SourceLogEntry> getLogEventCallback()
Retrieve the callback assigned for Raw Log Events
Consumer
representing the raw log event callbackpublic void setLogEventCallback(Consumer<SourceLogEntry> callback)
Sets the callback for listening on Raw Log Events
callback
- A Consumer
callback for raw log eventspublic InetSocketAddress getListenAddress()
Getter for the field listenAddress
.
InetSocketAddress
where the service is binded topublic void setListenAddress(InetSocketAddress listenAddress)
listenAddress
- The InetSocketAddress
to listen onIllegalStateException
- If the service has been started alreadypublic CompletableFuture<Void> listen()
CompletableFuture
that is notified once the connection is closed. This is notified either by an interrupt signal (SIGINT) or by invoking close()
setListenAddress(InetSocketAddress)
,
close()
public CompletableFuture<Void> listen(InetSocketAddress address)
address
- The InetSocketAddress
to listen onCompletableFuture
that is notified once the connection is closed. This is notified either by an interrupt signal (SIGINT) or by invoking close()
close()
public CompletableFuture<Void> getListenFuture()
listen(InetSocketAddress)
or null
if service is not bounded to an address yet.public boolean isListening()
true
if service is currently bounded to an addresspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2016–2024. All rights reserved.