WebSocketCommandController.java 1.74 KB
Newer Older
TongZuu committed
1 2 3 4 5 6 7 8
package com.csc.library.controller;

import com.csc.library.command.CscCommand;
import com.csc.library.factory.CommandFactory;
import com.csc.library.factory.PropertiesFactory;
import com.csc.library.factory.ResponseFactory;
import com.csc.library.factory.ThreadsPoolsFactory;
import com.csc.library.properties.CscSession;
TongZuu committed
9
import com.csc.library.request.CommandState;
TongZuu committed
10 11 12 13 14 15 16 17 18 19 20 21
import com.csc.library.request.RequestWebsocket;
import com.csc.library.response.ResponseStatus;
import com.csc.library.task.CommandTask;
import com.csc.library.task.TaskCommand;

public class WebSocketCommandController {
	private static WebSocketCommandController instance;
	//private Map<CscSession , Map<String , RequestWebsocket>> currentCommand = new HashMap<CscSession , Map<String , RequestWebsocket>>();
	private ResponseFactory responseFact;
	private PropertiesFactory propFact;
	private CommandFactory commandFact;
	private ThreadsPoolsFactory threadsFact;
TongZuu committed
22

TongZuu committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	
	private WebSocketCommandController(){
	}
	
	public static WebSocketCommandController getInstance(){
		try{
			if(instance == null){
				instance = new WebSocketCommandController();
				instance.responseFact = ResponseFactory.getInstance();
				instance.commandFact = CommandFactory.getInstance();
				instance.threadsFact = ThreadsPoolsFactory.getInstance();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return instance;
	}
	
	public void executeCommand(final CscSession session, final RequestWebsocket req){
		responseFact.sendResponseWebsocket(session, req,
TongZuu committed
43
				CommandState.noAction,
TongZuu committed
44 45 46 47 48 49
				ResponseStatus.Receive,
				ResponseStatus.Receive.getDescription());
		
		final CscCommand command = commandFact.getCommand(session , req);
		CommandTask task = new TaskCommand(session , req , command); 
		threadsFact.execute(task);
TongZuu committed
50
		
TongZuu committed
51 52
	}
}