dubbo 原始碼解析 2 5 3版本

2021-09-26 19:55:31 字數 3706 閱讀 9757

1.  channeleventrunnable類

通道訊息執行緒

所有的訊息都在此處理,包含訊息的收,發,斷開連線,異常等

public class channeleventrunnable implements runnable 

public channeleventrunnable(channel channel, channelhandler handler, channelstate state, object message)

public channeleventrunnable(channel channel, channelhandler handler, channelstate state, throwable t)

public channeleventrunnable(channel channel, channelhandler handler, channelstate state, object message, throwable exception)

public void run() catch (exception e)

break;

case disconnected:

trycatch (exception e)

break;

case sent:

trycatch (exception e)

break;

case received:

trycatch (exception e)

break;

case caught:

trycatch (exception e)

break;

default:

logger.warn("unknown state: " + state + ", message is " + message);}}

}

2. defaultfuture類 (在這裡打斷點,找到收發訊息的源頭)

public class defaultfuture implements responsefuture

通過每個channel[有channle id]發訊息後,然後用defaultfuture來接收返回的結果(同步返回乙個空結果)。具體的結果等到需要用時,直接調defaultfuture的get()方法,可以同步獲取呼叫結果

public object get() throws remotingexception 

// 獲取真正的呼叫結果

public object get(int timeout) throws remotingexception

if (! isdone())

}} catch (interruptedexception e) finally

if (! isdone())

}return returnfromresponse();

}

3. 具體通道裡的訊息收發 

public class headerexchangehandler implements channelhandlerdelegate 

this.handler = handler;

}void handlerevent(channel channel, request req) throws remotingexception

}// response handlerequest(exchangechannel channel, request req) throws remotingexception

// find handler by message class.

object msg = req.getdata();

try catch (throwable e)

return res;

}static void handleresponse(channel channel, response response) throws remotingexception

}public void connected(channel channel) throws remotingexception finally

}public void disconnected(channel channel) throws remotingexception finally

}public void sent(channel channel, object message) throws remotingexception finally

} catch (throwable t)

if (message instanceof request)

if (exception != null) else if (exception instanceof remotingexception) else }}

private static boolean isclientside(channel channel)

public void received(channel channel, object message) throws remotingexception else else

}} else if (message instanceof response) else if (message instanceof string) else

}} else

} finally

}public void caught(channel channel, throwable exception) throws remotingexception }}

exchangechannel exchangechannel = headerexchangechannel.getoraddchannel(channel);

try finally

}public channelhandler gethandler() else

}}

4. com.alibaba.dubbo.remoting.exchange.support.header.headerexchangehandler 處理訊息收發

(1) 傳送dubbo請求訊息

// 傳送訊息

public void sent(channel channel, object message) throws remotingexception finally

} catch (throwable t)

if (message instanceof request)

if (exception != null) else if (exception instanceof remotingexception) else

}}

(2) 接收dubbo響應訊息 

// 接收訊息   

public void received(channel channel, object message) throws remotingexception else else

}} else if (message instanceof response) else if (message instanceof string) else

}} else

} finally

}

jquery原始碼分析(2)(2 0版本)

1.引數為什麼傳window和undefined function window,undefined window 1.1 根據作用域鏈的原理,傳入window引數之後,能提高查詢速度。2 便於壓縮。2.傳入undefined,防止undefined在外部被修改。2.變數rootjquery,cor...

深究1 8版本HashMap原始碼

public v put k key,v value 在putval方法之前,對 key 進行了 hash 計算。static final inthash object key 通過 hashcode 方法和無符號左移16後的 hashcode 進行異或計算。進行了一次擾動計算。再看 putval ...

dubbo原始碼解析(dubbo容器部分)

dubbo 解析 dubbo中也有內建的容器介面就是類 com.alibaba.dubbo.container.container 如下所示 spi spring public inte ce container 也同樣是 spi擴充套件點。而且介面非常的簡單,乾淨,在 dubbo 框架中一共出現了...