浏览代码

增加切换主备机时对备机端口非空判断

weiyigulu 3 年之前
父节点
当前提交
926e8cdd71
共有 1 个文件被更改,包括 58 次插入58 次删除
  1. 58 58
      protocol-core/src/main/java/wei/yigulu/netty/AbstractHSTcpMasterBuilder.java

+ 58 - 58
protocol-core/src/main/java/wei/yigulu/netty/AbstractHSTcpMasterBuilder.java

@@ -21,70 +21,70 @@ import lombok.experimental.Accessors;
 public abstract class AbstractHSTcpMasterBuilder extends AbstractTcpMasterBuilder {
 
 
-	/**
-	 * Hs master builder
-	 *
-	 * @param ip   ip
-	 * @param port port
-	 */
-	public AbstractHSTcpMasterBuilder(String ip, Integer port) {
-		super(ip, port);
-	}
+    /**
+     * Hs master builder
+     *
+     * @param ip   ip
+     * @param port port
+     */
+    public AbstractHSTcpMasterBuilder(String ip, Integer port) {
+        super(ip, port);
+    }
 
-	/**
-	 * Hs master builder
-	 *
-	 * @param ip        ip
-	 * @param port      port
-	 * @param spareIp   备 ip
-	 * @param sparePort 备 port
-	 */
-	public AbstractHSTcpMasterBuilder(String ip, Integer port, String spareIp, Integer sparePort) {
-		super(ip, port);
-		this.spareIp = spareIp;
-		this.sparePort = sparePort;
-	}
+    /**
+     * Hs master builder
+     *
+     * @param ip        ip
+     * @param port      port
+     * @param spareIp   备 ip
+     * @param sparePort 备 port
+     */
+    public AbstractHSTcpMasterBuilder(String ip, Integer port, String spareIp, Integer sparePort) {
+        super(ip, port);
+        this.spareIp = spareIp;
+        this.sparePort = sparePort;
+    }
 
-	/**
-	 * 备对端ip
-	 */
-	@Getter
-	@Setter
-	private String spareIp;
+    /**
+     * 备对端ip
+     */
+    @Getter
+    @Setter
+    private String spareIp;
 
-	/**
-	 * 备对端port
-	 */
-	@Getter
-	@Setter
-	private Integer sparePort;
+    /**
+     * 备对端port
+     */
+    @Getter
+    @Setter
+    private Integer sparePort;
 
 
-	@Override
-	public ChannelFutureListener getOrCreateConnectionListener() {
-		if (this.connectionListener == null) {
-			this.connectionListener = new HSConnectionListener(this);
-		}
-		return this.connectionListener;
-	}
+    @Override
+    public ChannelFutureListener getOrCreateConnectionListener() {
+        if (this.connectionListener == null) {
+            this.connectionListener = new HSConnectionListener(this);
+        }
+        return this.connectionListener;
+    }
 
-	/**
-	 * 切换主备机
-	 */
-	public void switchover() {
-		String temporaryIp;
-		int temporaryPort;
-		if (spareIp != null && !"".equals(spareIp)) {
-			temporaryIp = this.ip;
-			this.ip = this.spareIp;
-			this.spareIp = temporaryIp;
-		}
-		if (sparePort != 0) {
-			temporaryPort = this.port;
-			this.port = this.sparePort;
-			this.sparePort = temporaryPort;
-		}
-	}
+    /**
+     * 切换主备机
+     */
+    public void switchover() {
+        String temporaryIp;
+        int temporaryPort;
+        if (spareIp != null && !"".equals(spareIp)) {
+            temporaryIp = this.ip;
+            this.ip = this.spareIp;
+            this.spareIp = temporaryIp;
+        }
+        if (sparePort != null && sparePort != 0) {
+            temporaryPort = this.port;
+            this.port = this.sparePort;
+            this.sparePort = temporaryPort;
+        }
+    }
 
 
 }