mercredi 2 décembre 2015

Server, local server communication over websocket design hint

I am coding Java Web Application that has image scanning screen. This screen is connecting a local websocket server to send some scanning related commands such as 'getAvailableScanners', 'scan'. Local Server return results of commands to browser and browser send these results to server. I am using RequestModel object to send command which has two variable one is command and another is value.

Server -> Browser(JS directly sends commands to local server) -> Local Server -> Browser(JS directly sends commands to server) -> Server

I designed like these (Request Model):

{command:'getAvailableScanners', value:'null'} (Sent object)

{command:'getAvailableScanners', value:'List of scanners (Serializable)' (Return object which has available scanners)

{command:'scan', value:'Scanner (Serializable)'} (Sent object, it says scan with this scanner)
{command:'scan', value:'Scanned page (Serializable)' (Return object, which has scanned page)

I am checking commands using if/else statement. For example;

if(requestModel.command == scan)
   doWork(requestModel.value)
else if(requestModel.command == getAvailableScanners)
   doWork()

I didn't like my design and code. Can I use any other way? Can I use command pattern instead of if/else?

Aucun commentaire:

Enregistrer un commentaire