All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.configcenter.client.domain.ServerNode Maven / Gradle / Ivy

The newest version!
/*
 * @(#)ServerNode.java	2021-10-19
 *
 * Copyright (c) 2021. All Rights Reserved.
 *
 */

package com.github.javaclub.configcenter.client.domain;

import com.alibaba.fastjson.JSON;
import com.github.javaclub.configcenter.client.util.Utils;

/**
 * ServerNode
 *
 * @author Gerald Chen
 * @version $Id: ServerNode.java 2021-10-19 11:31:57 Exp $
 */
public class ServerNode {
	
	private String ipAndPort;
	
	/**
	 * 检测到的最近宕机时间点(0代表最近/当前未曾宕机) 
	 */
	private long breakDownTime = 0L;

	public ServerNode() {
	}
	
	public ServerNode(String ipAndPort) {
		this.ipAndPort = ipAndPort;
	}
	
	public ServerNode(String ipAndPort, long breakDownTime) {
		this.ipAndPort = ipAndPort;
		this.breakDownTime = breakDownTime;
	}
	
	public void setBreakDownTime(long breakDownTime) {
		this.breakDownTime = breakDownTime;
	}
	
	public long getBreakDownTime() {
		return breakDownTime;
	}

	public String getIpAndPort() {
		return ipAndPort;
	}

	/**
	 * 是否能正常提供服务
	 */
	public boolean canWork() {
		if (Utils.isBlank(ipAndPort)) {
			return false;
		}
		if (breakDownTime == 0) {
			return true;
		}
		long breakInterval = Math.abs(System.currentTimeMillis() - breakDownTime);
		// 30s 内有过故障,暂不对外工作
		if (breakInterval < 30000L) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}
	

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy