最近維護(hù)的系統(tǒng)切換了網(wǎng)絡(luò)環(huán)境贾节,由聯(lián)通換成了電信網(wǎng)絡(luò),因為某些過濾規(guī)則導(dǎo)致系統(tǒng)連不上zookeeper服務(wù)器(應(yīng)用系統(tǒng)機(jī)器在深圳,網(wǎng)絡(luò)為電信線路,zookeeper服務(wù)器在北京稀轨,網(wǎng)絡(luò)為聯(lián)通線路),因為我不是運(yùn)維人員也不懂運(yùn)維相關(guān)的技術(shù)岸军,所以排查了很久也不知道原因奋刽,最后無奈之下把深圳這邊的網(wǎng)絡(luò)切回了聯(lián)通,系統(tǒng)恢復(fù)正常艰赞。
但是因為本次事故體現(xiàn)了一個很嚴(yán)重的問題杨名,即當(dāng)zookeeper注冊中心連不上時dubbo的線程會無限等待,因為系統(tǒng)有一些定時任務(wù)會比較頻繁地開啟新線程連接dubbo猖毫,所以導(dǎo)致的結(jié)果是tomcat一會兒線程池就滿了台谍,其它的不依賴dubbo的功能也被阻塞無法使用。
所以需要解決一個問題吁断,即在斷網(wǎng)的情況下要保證應(yīng)用程序可以運(yùn)行(有很多功能不依賴外網(wǎng))趁蕊,一開始我以為dubbo應(yīng)該有對ZKClient連接相關(guān)的超時時間配置,結(jié)果找了很久也沒發(fā)現(xiàn)仔役,后來debug了dubbo的源代碼發(fā)現(xiàn)根本就沒有設(shè)置超時時間掷伙,ZKClient默認(rèn)的超時時間是Integer.MAX_VALUE,幾乎等于無限等待又兵,所以無奈之下只好重寫了dubbo的ZookeeperClient實現(xiàn)任柜,好在dubbo的擴(kuò)展性非常好,基于SPI的擴(kuò)展非常方便沛厨,下面是我的擴(kuò)展代碼:
1宙地、增加一個文件com.alibaba.dubbo.remoting.zookeeper.ZookeeperTransporter放置于項目的META-INF/dubbo/internal文件夾下,dubbo便會自動掃描到這個文件逆皮。文件內(nèi)容很簡單就一句話:zkclient=com.gwall.zookeeper.ZkclientZookeeperTransporter
即把dubbo原來的默認(rèn)實現(xiàn)替換為我的實現(xiàn)宅粥。
2、ZkclientZookeeperTransporter并不是我想替換的代碼电谣,我要替換的是ZkclientZookeeperTransporter的成員變量ZookeeperClient秽梅,只是dubbo只在ZookeeperTransporter上加了SPI注解,所以只好這樣辦了剿牺,ZkclientZookeeperTransporter代碼照抄過來企垦。
3、在ZkclientZookeeperTransporter里面使用自己的ZkclientZookeeperClient晒来,代碼如下:
package com.gwall.zookeeper;
import java.util.List;
import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.IZkStateListener;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.exception.ZkNoNodeException;
import org.I0Itec.zkclient.exception.ZkNodeExistsException;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.zookeeper.ChildListener;
import com.alibaba.dubbo.remoting.zookeeper.StateListener;
import com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient;
/** * 修改dubbo提供的ZkclientZookeeperClient * 主要目的是增加一個連接zookeeper的超時時間,避免ZkClient默認(rèn)的無限等待 * @author long.zr * */
public class ZkclientZookeeperClient extends AbstractZookeeperClient {
private final ZkClient client;
private volatile KeeperState state = KeeperState.SyncConnected;
public ZkclientZookeeperClient(URL url) {
super(url);
//設(shè)置超時時間為5000毫秒
client = new ZkClient(url.getBackupAddress(),5000);
client.subscribeStateChanges(new IZkStateListener() {
public void handleStateChanged(KeeperState state) throws Exception {
ZkclientZookeeperClient.this.state = state;
if (state == KeeperState.Disconnected) {
stateChanged(StateListener.DISCONNECTED);
} else if (state == KeeperState.SyncConnected) {
stateChanged(StateListener.CONNECTED);
}
}
public void handleNewSession() throws Exception {
stateChanged(StateListener.RECONNECTED);
}
});
}
public void createPersistent(String path) {
try {
client.createPersistent(path, true);
} catch (ZkNodeExistsException e) {
}
}
public void createEphemeral(String path) {
try {
client.createEphemeral(path);
} catch (ZkNodeExistsException e) {
}
}
public void delete(String path) {
try {
client.delete(path);
} catch (ZkNoNodeException e) {
}
}
public List getChildren(String path) {
try {
return client.getChildren(path);
} catch (ZkNoNodeException e) {
return null;
}
}
public boolean isConnected() {
return state == KeeperState.SyncConnected;
}
public void doClose() {
client.close();
}
public IZkChildListener createTargetChildListener(String path, final ChildListener listener) {
return new IZkChildListener() {
public void handleChildChange(String parentPath, List currentChilds)
throws Exception {
listener.childChanged(parentPath, currentChilds);
}
};
}
public List addTargetChildListener(String path, final IZkChildListener listener) {
return client.subscribeChildChanges(path, listener);
}
public void removeTargetChildListener(String path, IZkChildListener listener) {
client.unsubscribeChildChanges(path,? listener);
}
}
框架/平臺構(gòu)成:
Maven+Springmvc + Mybatis + Shiro(權(quán)限)+ Tiles(模板) +ActiveMQ(消息隊列) + Rest(服務(wù)) + WebService(服務(wù))+ EHcache(緩存) + Quartz(定時調(diào)度)+ Html5(支持PC钞诡、IOS、Android)
用戶權(quán)限系統(tǒng):
組織結(jié)構(gòu):角色、用戶臭增、用戶組懂酱、組織機(jī)構(gòu);權(quán)限點(diǎn):頁面誊抛、方法列牺、按鈕、數(shù)據(jù)權(quán)限拗窃、分級授權(quán)
項目管理新體驗:
快速出原型系統(tǒng)瞎领、組件樹、版本控制随夸、模塊移植九默、協(xié)同開發(fā)、實時監(jiān)控宾毒、發(fā)布管理
可持續(xù)集成:
所有組件可移植驼修、可定制、可擴(kuò)充诈铛,開發(fā)成果不斷積累乙各,形成可持續(xù)發(fā)展的良性循環(huán)
支持平臺平臺:
Windows XP、Windows 7 幢竹、Windows 10 耳峦、 Linux 、 Unix
服務(wù)器容器:
Tomcat 5/6/7 焕毫、Jetty蹲坷、JBoss、WebSphere 8.5