
package org.tio.sitexxx.im.server.ws;

import org.tio.core.intf.TioUuid;
import org.tio.server.TioServerConfig;
import org.tio.sitexxx.im.server.PacketDispatcher;
import org.tio.sitexxx.service.utils.AppThreads;
import org.tio.websocket.server.WsServerConfig;
import org.tio.websocket.server.WsServerStarter;

import java.io.IOException;

/**
 * @author tanyaowu
 * 2016年6月28日 下午5:34:04
 */
public class ImWsStarter {
	private WsServerStarter wsServerStarter;
	private TioServerConfig tioServerConfig;

	/**
	 *
	 * @author tanyaowu
	 */
	public ImWsStarter(int port, TioUuid tioUuid, PacketDispatcher packetDispatcher) throws IOException {
		WsServerConfig wsServerConfig = new WsServerConfig(port);
		wsServerStarter = new WsServerStarter(wsServerConfig, new ImWsMsgHandler(packetDispatcher), tioUuid,
				AppThreads.getExecutor(), AppThreads.getGroupExecutor());
		tioServerConfig = wsServerStarter.getTioServerConfig();
		ImWsGroupListener imWsGroupListener = ImWsGroupListener.me;
		tioServerConfig.setGroupListener(imWsGroupListener);
		tioServerConfig.setTioServerListener(ImWsTioServerListener.me);

	}

	public WsServerStarter getWsServerStarter() {
		return wsServerStarter;
	}

	public void start() throws IOException {
		wsServerStarter.start();
	}

	/**
	 * @return the tioServerConfig
	 */
	public TioServerConfig getTioServerConfig() {
		return tioServerConfig;
	}

}
