org.tio.server.ServerTioConfig Java Examples

The following examples show how to use org.tio.server.ServerTioConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WsServerStarter.java    From t-io with Apache License 2.0 6 votes vote down vote up
public WsServerStarter(WsServerConfig wsServerConfig, IWsMsgHandler wsMsgHandler, TioUuid tioUuid, SynThreadPoolExecutor tioExecutor, ThreadPoolExecutor groupExecutor)
        throws IOException {
	if (tioExecutor == null) {
		tioExecutor = Threads.getTioExecutor();
	}

	if (groupExecutor == null) {
		groupExecutor = Threads.getGroupExecutor();
	}

	this.wsServerConfig = wsServerConfig;
	this.wsMsgHandler = wsMsgHandler;
	wsServerAioHandler = new WsServerAioHandler(wsServerConfig, wsMsgHandler);
	wsServerAioListener = new WsServerAioListener();
	serverTioConfig = new ServerTioConfig("Tio Websocket Server", wsServerAioHandler, wsServerAioListener, tioExecutor, groupExecutor);
	serverTioConfig.setHeartbeatTimeout(0);
	serverTioConfig.setTioUuid(tioUuid);
	serverTioConfig.setReadBufferSize(1024 * 30);
	tioServer = new TioServer(serverTioConfig);
}
 
Example #2
Source File: FlashPolicyServerStarter.java    From t-io with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param ip 可以为null
 * @param port 如果为null,则用默认的端口
 * @param tioExecutor
 * @param groupExecutor
 * @author tanyaowu
 */
public static void start(String ip, Integer port, SynThreadPoolExecutor tioExecutor, ThreadPoolExecutor groupExecutor) {
	if (port == null) {
		port = Const.PORT;
	}
	aioHandler = new FlashPolicyServerAioHandler();
	serverTioConfig = new ServerTioConfig("tio flash policy server", aioHandler, aioListener, tioExecutor, groupExecutor);
	serverTioConfig.setHeartbeatTimeout(Const.HEARTBEAT_TIMEOUT);
	tioServer = new TioServer(serverTioConfig);

	try {
		tioServer.start(ip, port);
	} catch (Throwable e) {
		log.error(e.toString(), e);
		System.exit(1);
	}

	checkAllChannels();
}
 
Example #3
Source File: Tio.java    From t-io with Apache License 2.0 6 votes vote down vote up
/**
 *  删除clientip为指定值的所有连接
 * @param serverTioConfig
 * @param ip
 * @param remark
 * @param closeCode
 */
public static void remove(ServerTioConfig serverTioConfig, String ip, String remark, CloseCode closeCode) {
	SetWithLock<ChannelContext> setWithLock = serverTioConfig.ips.clients(serverTioConfig, ip);
	if (setWithLock == null) {
		return;
	}

	setWithLock.handle(new ReadLockHandler<Set<ChannelContext>>() {
		@Override
		public void handler(Set<ChannelContext> set) {
			for (ChannelContext channelContext : set) {
				Tio.remove(channelContext, remark, closeCode);
			}
		}
	});
}
 
Example #4
Source File: IpBlacklist.java    From t-io with Apache License 2.0 6 votes vote down vote up
public boolean add(String ip) {
	//先添加到黑名单列表
	cache.put(ip, SystemTimer.currTime);

	if (serverTioConfig != null) {
		//删除相关连接
		Tio.remove(serverTioConfig, ip, "ip[" + ip + "]被加入了黑名单, " + serverTioConfig.getName());
	} else {
		TioConfig.ALL_SERVER_GROUPCONTEXTS.stream().forEach(new Consumer<ServerTioConfig>() {
			@Override
			public void accept(ServerTioConfig tioConfig) {
				Tio.remove(tioConfig, ip, "ip[" + ip + "]被加入了黑名单, " + tioConfig.getName());

			}
		});
	}

	return true;
}
 
Example #5
Source File: TioServerBootstrap.java    From t-io with Apache License 2.0 5 votes vote down vote up
private void initTioServerTioConfig()
{
    serverTioConfig = new ServerTioConfig(GROUP_CONTEXT_NAME, serverAioHandler, serverAioListener);
    if (ipStatListener != null) {
        serverTioConfig.setIpStatListener(ipStatListener);
        // fixed bug for IpStatListener not work
        serverTioConfig.ipStats.addDurations(serverProperties.getIpStatDurations());
    }
    if(serverAioListener != null) {
        serverTioConfig.setServerAioListener(serverAioListener);
    }
    if (groupListener != null) {
        serverTioConfig.setGroupListener(groupListener);
    }
    if (serverProperties.getHeartbeatTimeout() > 0) {
        serverTioConfig.setHeartbeatTimeout(serverProperties.getHeartbeatTimeout());
    }
    //cluster config
    if (clusterConfig != null) {
        serverTioConfig.setTioClusterConfig(clusterConfig);
    }
    //ssl config
    if (serverSslProperties.isEnabled()){
        try {
            serverTioConfig.useSsl(serverSslProperties.getKeyStore(), serverSslProperties.getTrustStore(), serverSslProperties.getPassword());
        }catch (Exception e){
            //catch and log
            logger.error("init ssl config error",e);
        }
    }
}
 
Example #6
Source File: HttpServerStarter.java    From t-io with Apache License 2.0 5 votes vote down vote up
private void init(HttpConfig httpConfig, HttpRequestHandler requestHandler, SynThreadPoolExecutor tioExecutor, ThreadPoolExecutor groupExecutor) {
	String system_timer_period = System.getProperty("tio.system.timer.period");
	if (StrUtil.isBlank(system_timer_period)) {
		System.setProperty("tio.system.timer.period", "50");
	}

	this.httpConfig = httpConfig;
	this.httpRequestHandler = requestHandler;
	httpConfig.setHttpRequestHandler(this.httpRequestHandler);
	this.httpServerAioHandler = new HttpServerAioHandler(httpConfig, requestHandler);
	httpServerAioListener = new HttpServerAioListener();
	String name = httpConfig.getName();
	if (StrUtil.isBlank(name)) {
		name = "Tio Http Server";
	}
	serverTioConfig = new ServerTioConfig(name, httpServerAioHandler, httpServerAioListener, tioExecutor, groupExecutor);
	serverTioConfig.setHeartbeatTimeout(1000 * 20);
	serverTioConfig.setShortConnection(true);
	serverTioConfig.setReadBufferSize(TcpConst.MAX_DATA_LENGTH);
	//		serverTioConfig.setAttribute(TioConfigKey.HTTP_SERVER_CONFIG, httpConfig);
	serverTioConfig.setAttribute(TioConfigKey.HTTP_REQ_HANDLER, this.httpRequestHandler);

	tioServer = new TioServer(serverTioConfig);

	HttpUuid imTioUuid = new HttpUuid();
	serverTioConfig.setTioUuid(imTioUuid);
}
 
Example #7
Source File: TioConfig.java    From t-io with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param tioExecutor
 * @param groupExecutor
 * @author: tanyaowu
 */
public TioConfig(SynThreadPoolExecutor tioExecutor, ThreadPoolExecutor groupExecutor) {
	super();
	ALL_GROUPCONTEXTS.add(this);
	if (this instanceof ServerTioConfig) {
		ALL_SERVER_GROUPCONTEXTS.add((ServerTioConfig) this);
	} else {
		ALL_CLIENT_GROUPCONTEXTS.add((ClientTioConfig) this);
	}

	if (ALL_GROUPCONTEXTS.size() > 20) {
		log.warn("已经产生{}个TioConfig对象,t-io作者怀疑你在误用t-io", ALL_GROUPCONTEXTS.size());
	}
	this.id = ID_ATOMIC.incrementAndGet() + "";

	this.ipStats = new IpStats(this, null);

	this.tioExecutor = tioExecutor;
	if (this.tioExecutor == null) {
		this.tioExecutor = Threads.getTioExecutor();
	}

	this.groupExecutor = groupExecutor;
	if (this.groupExecutor == null) {
		this.groupExecutor = Threads.getGroupExecutor();
	}

	closeRunnable = new CloseRunnable(this.tioExecutor);
}
 
Example #8
Source File: WsServerStarter.java    From t-io with Apache License 2.0 4 votes vote down vote up
/**
 * @return the serverTioConfig
 */
public ServerTioConfig getServerTioConfig() {
	return serverTioConfig;
}
 
Example #9
Source File: TioServerAutoConfiguration.java    From t-io with Apache License 2.0 4 votes vote down vote up
@Bean
public ServerTioConfig serverTioConfig(TioServerBootstrap bootstrap){
    return bootstrap.getServerTioConfig();
}
 
Example #10
Source File: TioServerBootstrap.java    From t-io with Apache License 2.0 4 votes vote down vote up
public ServerTioConfig getServerTioConfig() {
    return serverTioConfig;
}
 
Example #11
Source File: TioWebSocketServerBootstrap.java    From t-io with Apache License 2.0 4 votes vote down vote up
public ServerTioConfig getServerTioConfig() {
    return serverTioConfig;
}
 
Example #12
Source File: TioWebSocketServerAutoConfiguration.java    From t-io with Apache License 2.0 4 votes vote down vote up
@Bean
public ServerTioConfig wsServerTioConfig(TioWebSocketServerBootstrap bootstrap){
    return bootstrap.getServerTioConfig();
}
 
Example #13
Source File: HttpServerStarter.java    From t-io with Apache License 2.0 4 votes vote down vote up
/**
 * @return the serverTioConfig
 */
public ServerTioConfig getServerTioConfig() {
	return serverTioConfig;
}
 
Example #14
Source File: IpBlacklist.java    From t-io with Apache License 2.0 4 votes vote down vote up
public IpBlacklist(String id, ServerTioConfig serverTioConfig) {
	this.id = id;
	this.serverTioConfig = serverTioConfig;
	this.cacheName = CACHE_NAME_PREFIX + this.id;
	this.cache = CaffeineCache.register(this.cacheName, TIME_TO_LIVE_SECONDS, TIME_TO_IDLE_SECONDS, null);
}
 
Example #15
Source File: Tio.java    From t-io with Apache License 2.0 2 votes vote down vote up
/**
 * 删除clientip为指定值的所有连接
 * @param serverTioConfig
 * @param ip
 * @param remark
 */
public static void remove(ServerTioConfig serverTioConfig, String ip, String remark) {
	remove(serverTioConfig, ip, remark, (CloseCode) null);
}