Port Unification Overview(端口統(tǒng)一)
針對(duì)在一個(gè)端口上開放多種協(xié)議的服務(wù),類似下圖:

通過Port unification Filter去判斷三種協(xié)議,然后針對(duì)不同協(xié)議傳遞到下一個(gè)Filter執(zhí)行后續(xù)工作。
其中Finder的Grizzly官方給了一個(gè)簡(jiǎn)單用例,針對(duì)協(xié)議包頭是"add"的Finder
-
/**
-
* {@link ProtocolFinder}, responsible to determine if incoming byte buffer
-
* represents ADD-service request.
-
*/
-
public class AddProtocolFinder implements ProtocolFinder {
-
-
private final static byte [] magic = { 'a' , 'd' , 'd' };
-
-
/**
-
* {@inheritDoc}
-
*/
-
@Override
-
public Result find ( final PUContext puContext , final FilterChainContext ctx ) {
-
// Get the input Buffer
-
final Buffer inputBuffer = ctx . getMessage ();
-
-
final int bytesToCompare = Math . min ( magic . length , inputBuffer . remaining ());
-
-
final int bufferStart = inputBuffer . position ();
-
-
// Compare incoming bytes with ADD-service protocol magic
-
for ( int i = 0 ; i < bytesToCompare ; i ++) {
-
if ( magic [ i ] != inputBuffer . get ( bufferStart + i )) {
-
// If at least one byte doesn't match - it's not ADD-service protocol
-
return Result . NOT_FOUND ;
-
}
-
}
-
-
// if we check entire magic - return FOUND, or NEED_MORE_DATA otherwise
-
return bytesToCompare == magic . length ?
-
Result . FOUND : Result . NEED_MORE_DATA ;
-
}
-
-
}
這個(gè)簡(jiǎn)單例子應(yīng)該明白怎么判斷了吧,然后就是轉(zhuǎn)到對(duì)應(yīng)的協(xié)議
?
-------------------------------
理論學(xué)習(xí)暫且到此為止,水平實(shí)在有限,本人僅使用了基礎(chǔ)功能,所以大部分?jǐn)U展都沒有去學(xué)習(xí),希望有高人可以補(bǔ)充
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
