I asked a few questions about adapting the command protocol for use in my client server environment. However, after some experiments, I came to the conclusion that this would not work for me. It is not intended for this scenario. I thus lost the end.
I implemented a kind of RPC mechanism before I got a class called "Operation". I also had an enumeration called "Action", which gave names for actions that could be called on the server.
Now, in my old project, every time the client wanted to trigger an action on the server, he created an instance of "Operation" and set the action variable with the value from the "Action" enumeration. for instance
Operation serverOpToInvoke = new Operation();
serverOpToInvoke.setAction(Action.CREATE_TIME_TABLE);
serverOpToInvoke.setParameters(Map params);
ServerReply reply = NetworkManager.sendOperation(serverOpToInvoke);
...
On the server side, I had to do the terrible task of determining which method to call, examining the value of the "Action" enumeration with a load of "if / else" statements. When a match was found, I would call the appropriate method.
The problem was that it was dirty, hard to maintain and was ultimately a poor design.
So my question is: is there some kind of template that I can execute to implement a beautiful, clean and supported rpc mechanism through a TCP socket in java? RMI is not for me, because the client (android) does not support RMI. At this stage, I have exhausted all the possibilities. The only other option would be a REST service. Any advice would be very helpful.
Thanks a lot
source
share