teragrep / rlp_01

Java Reliable Event Logging Protocol (RELP) Library RLP-01
Apache License 2.0
5 stars 5 forks source link

Open a connection in RelpConnection when sending messages #68

Open 51-code opened 2 weeks ago

51-code commented 2 weeks ago

Description

Currently opening a connection is handled in the connect() function. This could be refactored so that no explicit call to this function is needed. The commit() function would make sure that a connection is opened before the message is sent.

This would simplify using the object in other components. Now in some cases the connection has to be done in the constructor, which is bad design, but there really is no better alternative.

51-code commented 2 weeks ago

RelpConnection would also benefit from refactoring it to be immutable. Currently the status of the connection is kept inside a variable, it should return a new RelpConnection with the updated state instead. An interface for the object would also help with unit testing in other components, where fake objects are needed.