motan原始碼分析十一 部分特性

2021-07-29 18:53:16 字數 3686 閱讀 3882

本章將描述motan部分的特性並對原始碼進行分析。

1.requestid的維護,使用了當前時間左移20位,再和乙個自增變數組合

public

class

requestidgenerator

}count =offset.incrementandget();

}return (currenttime << bits) +count;

}public

static

long

getrequestidfromclient()

}

2.限流,motan支援簡單的限流,是利用filter來實現的

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

@spimeta(name ="active")

@activation(sequence =1)

publicclassactivelimitfilterimplementsfilter

}

longstarttime = system.currenttimemillis();

rpcstats.beforecall(caller.geturl(), request);

trycatch(runtimeexception re)

}

}

3.對於連續失敗的client進行不可用操作

void

increrrorcount() }}

}void

reseterrorcount()

synchronized (

this

)

//如果節點是unalive才進行設定,而如果是 close 或者 uninit,那麼直接忽略

if(state.isunalivestate()) }}

}

4.支援多註冊中心,因此cluster的refer集合是所有註冊中心包含伺服器的集合,如果同乙個伺服器在不同的註冊中心註冊,則cluster中當作兩個伺服器

5.服務端的採用boss執行緒池+工作執行緒池+業務執行緒池的處理方式

1

2

3

4

5

6

7

8

9

10

11

12

13

privatefinalstaticchannelfactory channelfactory =newnioserversocketchannelfactory(//boss執行緒池和工作執行緒池,主要負責接收訊息

executors.newcachedthreadpool(newdefaultthreadfactory("nettyserverboss",true)),

executors.newcachedthreadpool(newdefaultthreadfactory("nettyserverworker",true)));

privatestandardthreadexecutor standardthreadexecutor =null;//業務執行緒池,負責具體的業務處理

standardthreadexecutor = (standardthreadexecutor !=null&& !standardthreadexecutor.isshutdown()) ? standardthreadexecutor

:newstandardthreadexecutor(minworkerthread, maxworkerthread, workerqueuesize,

newdefaultthreadfactory("nettyserver-"+ url.getserverportstr(),true));

standardthreadexecutor.prestartallcorethreads();

finalnettychannelhandler handler =newnettychannelhandler(nettyserver.this, messagehandler,

standardthreadexecutor);//handler使用業務執行緒池今天處理具體的業務

JSON原始碼分析(第一部分)

一 json簡介 1 json資料結構 1 json的資料結構只有兩種 object是以 表示,array是以 表示 2 可以相互巢狀表示,不同語言之中的物件 記錄 結構 字典 雜湊表等都可以作為轉換的物件基礎結構。2 json儲存結構 cjson設計的核心是採用了雙向鍊錶 其儲存結構有點像廣義表。...

redux原始碼分析(三) 原始碼部分

下面是每個部分的一些解讀 createstore apicreatestore reducer,initialstate enhancer 曾經非常好奇這個函式的第二個引數到底是initialstate還是enhancer,因為見過兩種寫法都有的,以為是版本問題。看了原始碼才發現,都可以的。如果你不...

motan原始碼分析七 序列化

motan的序列化支援兩種協議,一種是json,另一種是hessian2。主要涉及到的類和介面是是 fastjsonserialization hessian2serialization serialization codec abstractcodec nettydecoder nettyenco...