简体   繁体   中英

Netty - How best to architecture client/server for desktop app with lots of POJO's

I have a desktop client that will be using Netty to connect to a server (your basic client/server setup). The client has many objects (POJO's) to not only CRUD on, but also to do some complex business logic which is why I can't just have the clients talk directly to the database. As well, I don't want to place all the SQL logic in the clients.

So for example I have:

boolean RaceTrackDAO.saveTrack(Track track);
int RaceTrackDAO.getFastestLapTime(Track track);
Driver[] RaceTrackDAO.getTopDriversForTrack(int trackID)
...

boolean DriverDAO.saveDriver(Driver driver);
bollean DriverDAO.updateDriver(Driver driver);
Driver[] DriverDAO.getTopTenDrivers(Driver driver);
...

and so on...

In the client, I have:

someUICode()
{
  ...
  Driver[] topTenDrivers = DriverDAO.getTopTenDrivers();
  ...
}

The question is how do I architecture/implement the DriverDAO layer to use Netty in the client/server system?

I understand you can send POJO's through the Channel , but the documentation only really talks about sending one type of POJO. I've done some research and find there's all kinds of options. There's the command and state patterns which look interesting.

The key for me is avoiding as much boilerplate coding as possible. I know Netty has built-in tools to marhsall and unmarshall POJO's through serialization. That's the easier part. I just don't want to be stuck with a million if statements to deal with all the possible pojo's (and to know which backend calls to make).

The key for me is to keep the whole very maintainable. Performance is nice to have, but the system is never going to need to handle thousands of connections at once, so there's a bit of leeway here.

With all that in mind, what's the best architecture to design such a system using Netty at the DAO layer?

If you want to keep things simple you can use RMI(?) or serialize your object over Netty. That way you don't need to be able to handle all the possible objects. (You should still try to keep them to a manageable level)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM