I have around 50 types of servers each providing different API/SDK for connection and control.
Given only a server's address, my mission is to write a client program to determine the server's type reasonably quickly.
The tricky part is each of those servers provides drastically different API/SDK for identification. Those API are out of my control. In order to detect the server type, I would naively do something like this:
function detectServerType(String address) {
bool isServerTypeA = proprietaryRoutineToCheckIfTypeA(address);
if (isServerTypeA) {
return "A";
}
bool isServerTypeB = proprietaryRoutineToCheckIfTypeB(address);
if (isServerTypeB) {
return "B";
}
...
bool isServerTypeZ = proprietaryRoutineToCheckIfTypeZ(address);
if (isServerTypeZ) {
return "Z";
}
} /* This routine takes a long time! */
Those servers and proprietaryRoutines are made by different manufacturers and all out of my control. Each server type has to be detected by its unique procedure.
To shorten the time, we may run these checks in parallel.
function detectServerType(String address, Callback callbackIfSuccess) {
callProprietaryRoutineToCheckIfTypeAInNewThread(address, callbackIfSuccess);
callProprietaryRoutineToCheckIfTypeBInNewThread(address, callbackIfSuccess);
...
callProprietaryRoutineToCheckIfTypeZInNewThread(address, callbackIfSuccess);
}
This way, I can quickly start checking for all 50 types of servers and run callbackIfSuccess as soon as one successful result comes in.
Is there more tried-and-true design pattern when it comes to device identification scenario like this?
Aucun commentaire:
Enregistrer un commentaire