Package app.l2nx.gs.adapter.core
Class NxAdapter
java.lang.Object
app.l2nx.gs.adapter.core.NxAdapter
Adapter entry point — singleton-style facade exposing the lifecycle to the host JVM.
Usage:
NxAdapter.onStateChange(s -> log.info("adapter state: {}", s)); // optional
NxAdapter.start(); // fire-and-forget
start() never propagates an exception to the host JVM. Any failure during
config resolution is caught here, logged via NxLog, and reflected in
state() as AdapterState.FAILED.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidhostExecutor(Executor executor) static voidonStateChange(Consumer<AdapterState> callback) Register a state-transition callback.voidshutdown()Idempotent shutdown — cancel heartbeat, cancel connect scheduler, shut down the Kafka client if alive, and transition toAdapterState.CLOSED.static NxAdapterstart()Resolve config and (if enabled) initiate the connect flow on a daemon scheduler.static AdapterStatestate()Current adapter state.
-
Method Details
-
onStateChange
Register a state-transition callback. May be called before or afterstart(). Replaces any previously registered callback. -
hostExecutor
Register the host's game-sideExecutorfor command-handlerctx.host().sync(...)/.async(...)hops. MUST be called beforestart()whencommandsTopicis configured.Typical bohpts wiring:
NxAdapter.hostExecutor(task -> ThreadPoolManager.getInstance().executeGeneral(task)); NxAdapter.start();
Calling without an executor when
commandsTopicis configured surfaces as a startup WARN; the firstctx.host().sync(...)call from any handler then throwsIllegalStateException. Read-only handlers (no game state mutation) keep working unaffected.May be called more than once — last write wins. Replacing while the adapter is already running is permitted but discouraged; the new executor takes effect on the next
ctx.host()call. -
state
Current adapter state. -
start
Resolve config and (if enabled) initiate the connect flow on a daemon scheduler. Non-blocking — returns immediately. Never throws into the host JVM. -
shutdown
public void shutdown()Idempotent shutdown — cancel heartbeat, cancel connect scheduler, shut down the Kafka client if alive, and transition toAdapterState.CLOSED. Safe to call from any thread; safe to call repeatedly.
-