Skip to content

Commit

Permalink
Allow closing active proxy listeners (#1109)
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen1212055 authored Oct 27, 2023
1 parent b30802c commit b33d18a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public interface ProxyServer extends Audience {
*/
void shutdown();

/**
* Closes all listening endpoints for this server.
* This includes the main minecraft listener and query channel.
*/
void closeListeners();

/**
* Retrieves the player currently connected to this proxy by their Minecraft username. The search
* is case-insensitive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ public void shutdown() {
shutdown(true);
}

@Override
public void closeListeners() {
this.cm.closeEndpoints(false);
}

public AsyncHttpClient getAsyncHttpClient() {
return cm.getHttpClient();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ public void close(InetSocketAddress oldBind) {
}

/**
* Closes all endpoints.
* Closes all the currently registered endpoints.
*
* @param interrupt should closing forward interruptions
*/
public void shutdown() {
public void closeEndpoints(boolean interrupt) {
for (final Map.Entry<InetSocketAddress, Endpoint> entry : this.endpoints.entrySet()) {
final InetSocketAddress address = entry.getKey();
final Endpoint endpoint = entry.getValue();
Expand All @@ -223,14 +225,26 @@ public void shutdown() {
// should have a chance to be notified before the server stops accepting connections.
server.getEventManager().fire(new ListenerCloseEvent(address, endpoint.getType())).join();

try {
LOGGER.info("Closing endpoint {}", address);
endpoint.getChannel().close().sync();
} catch (final InterruptedException e) {
LOGGER.info("Interrupted whilst closing endpoint", e);
Thread.currentThread().interrupt();
LOGGER.info("Closing endpoint {}", address);
if (interrupt) {
try {
endpoint.getChannel().close().sync();
} catch (final InterruptedException e) {
LOGGER.info("Interrupted whilst closing endpoint", e);
Thread.currentThread().interrupt();
}
} else {
endpoint.getChannel().close().syncUninterruptibly();
}
}
this.endpoints.clear();
}

/**
* Closes all endpoints.
*/
public void shutdown() {
this.closeEndpoints(true);

this.resolver.shutdown();
}
Expand Down

0 comments on commit b33d18a

Please sign in to comment.