What does the method in MessageHandler do?

Can someone please explain me what are the functionalities of the method handleCommandLineArguments(…) in MessageHandler interface?

The method does exactly what it states, it handles command line arguments :wink:
A tip for finding out what a method does, show the call hierarchy and for interfaces or abstract classes you can check out the type hierarchy to find out where it is called and used.

And the reason why it’s an interface is that it can be easily mocked in tests (see RemoteCommunicationTest)

A bit of background: By default, JabRef only allows a single instance to be running at the same time. Therefore, a simple socket is set up. If you now try to start a second JabRef instance with command line arguments, the command line arguments will be passed on to the existing JabRef instance.

JabRef 1st instance is running with a socket listening on a port.
JabRef 2nd instance starts β†’ Is there already a running JabRef instance? β†’
Yes? β†’ Send any command line arguments to the existing instance
No? β†’ Start normally and setup socket listening

The JabRef-Browser Extension also indirectly (through native messaging) passes content to JabRef via command line arguments.

Here is the sending of the message:

And here the implementation of the Message Handler

1 Like