How to trigger an action (in the plugin) with a network event, by listening to TCP server?

I am modifying a JetBrains plugin. I want to add a possibility to trigger an action in the plugin (which at the time being can be triggered manually, from the “Tools” menu) with a network event, by listening to a local TCP server, and when it send an event that matches specific patter, trigger the action.

What would be the best way of implementing this? The code that I want to trigger is currently implemented as a part of an action (class that subclasses AnAction class).

I guess I should start the server with

ApplicationManager.getApplication().executeOnPooledThread(() -> { /* ... */ });

or would you recommend to use

EventQueue.invokeLater(new Thread(() -> { /* ... /* }));

instead?

The TCP client (that connect to above mentioned TCP server, and listens for a specified event) currently uses java.nio.channels.AsynchronousSocketChannel - is there a better solution for creating a non-blocking TCP client?

The TCP client currently accepts a Consumer, that is intended to invoke the mentioned action.

The work in progress code can be found in my fork: GitHub - jnareb/CodeGRITS at add-imotions-support

IntelliJ Platform has a built-in server, so, you don’t need (and should not) create your own.

See org.jetbrains.ide.HttpRequestHandler and org.jetbrains.ide.RestService inheritors

<httpRequestHandler implementation="org.jetbrains.ide.AboutHttpService"

Thank you for the answer.

However, the TCP server in question is not a HTTP server, so no REST either. This server is something like logging service, and it simply spits out lines of event data in JSON Lines format.