(1)TMTS基本架構

來源:互聯網
上載者:User

1、TMTS是一個服務器,類似COM+伺服器,在介面裏只有一個函數:   

IBizService=interface(IConnectionService)<br /> ['{11C672E9-6082-4ACD-93AB-3F3A18E44E6F}']<br /> //clone a interface for multi-thread<br /> function Clone:IBizService;<br /> //call business mehod in appserver<br /> //需要定義ClientContent,因為SOAPBroker.dll中轉會需要<br /> function Call(const AServiceName,AMethodName:string;<br /> const AParams:OLEVariant;const AServiceObjectStub:integer=-1;<br /> const ACallMode:TServiceCallMode=cmSyncCall;<br /> const AResultIsFile:Boolean=false;<br /> const AResultSaveDirectory:string='';<br /> const AClient:TClientContent=nil):OLEVariant;<br /> function CallSync(const AServiceName,AMethodName:string;<br /> const AParams:OLEVariant;const AServiceObjectStub:integer=-1;<br /> const AResultIsFile:Boolean=false;<br /> const AResultSaveDirectory:string='';<br /> const AClient:TClientContent=nil):OLEVariant;<br /> //必須有Client參數,因為存在SOAP/Http中轉模式<br /> //因為有了Client參數,不能再加eMail參數,因為SOAP中轉變時成了IIS電腦的本地資訊<br /> function CallAsync(const AServiceName,AMethodName:string;<br /> const AParams:OLEVariant;const AServiceObjectStub:integer=-1;<br /> const AResultSaveDirectory:string='';<br /> const AResultNotifier:IAsyncCallResultNotifier=nil;<br /> const AClient:TClientContent=nil;<br /> const AIsShowModalProgress:Boolean=false):TAsyncCallIdentifier;overload;<br /> function GetAsyncCallProgress(const AAsyncCallIdentifier:TAsyncCallIdentifier;<br /> const AAsyncContent:TAsyncCallContent;<br /> const AClient:TClientContent=nil):Boolean;<br /> procedure CancelAsyncCall(const AAsyncCallIdentifier:TAsyncCallIdentifier;<br /> const AClient:TClientContent=nil);<br /> function CombineConnectionString(AComputerName,AServerName,AServerGUID:string;APort:integer):string;<br /> function GetDefaultPort:integer;<br /> function GetDefaultComputerName:string;<br /> function IsServerPortReadOnly:Boolean;<br /> end;</p><p>function TServiceRepository.Call(<br /> const AInvokeContent:TInvokeContent): OLEVariant;<br />var<br /> Index:integer;<br /> i:integer;<br /> vMacs:string;<br /> vFound:Boolean;<br />begin<br />//來源不同的線程調用本call函數,DCOM的Apartment thread,TCP的Peerthread<br />//建立一個背景工作執行緒,這樣才能控制逾時,<br />//否則用TerminateThread API會資源泄漏,或者用戶端Hold住.<br />//有必要作一個背景工作執行緒的線程池嗎?<br />//開始一個Activity,根元件可能不需要transaction,故這裡不適合處理transaction<br /> Result:=null;<br /> ClientRepository.Lock;<br /> try<br /> if (ClientRepository.FUseAuthorizedIPList) and<br /> not ClientRepository.FAuthorizedIPList.Find(AInvokeContent.ClientContent.IP,Index) then<br /> Raise Exception.CreateFmt(S_ClientIPNotAuthorized,[AInvokeContent.ClientContent.IP]);<br /> if (ClientRepository.FUseAuthorizedCardList) and<br /> not ClientRepository.FAuthorizedCardList.Find(AInvokeContent.ClientContent.DogCardNo,Index) then<br /> Raise Exception.CreateFmt(S_ClientCardNotAuthorized,[AInvokeContent.ClientContent.DogCardNo]);<br /> if (ClientRepository.FUseAuthorizedMacList) then<br /> begin<br /> vFound:=false;<br /> for i:=0 to High(AInvokeContent.ClientContent.MACs) do<br /> begin<br /> if ClientRepository.FAuthorizedMacList.Find(AInvokeContent.ClientContent.Macs[i],Index) then<br /> begin<br /> vFound:=true;<br /> break;<br /> end;<br /> end;<br /> if not vFound then<br /> begin<br /> vMacs:='';<br /> for i:=0 to High(AInvokeContent.ClientContent.Macs) do<br /> vMacs:=vMacs+AInvokeContent.ClientContent.Macs[i]+';';<br /> if vMacs<>'' then Delete(vMacs,Length(vMacs),1);<br /> //記錄這個授權禁止錯誤<br /> ServiceLog.CallEnd(AInvokeContent,AInvokeContent.CallMode=cmAsyncCall,<br /> 0,false,false,WideFormat(S_ClientMacNotAuthorized,[vMacs]));<br /> Raise Exception.CreateFmt(S_ClientMacNotAuthorized,[vMacs]);<br /> end;<br /> end;<br /> finally<br /> ClientRepository.UnLock;<br /> end;<br /> case AInvokeContent.CallMode of<br /> cmSyncCall:<br /> Result:=SyncCall(AInvokeContent);<br /> cmAsyncCall:<br /> Result:=AsyncCall(AInvokeContent);<br /> cmLockObject:<br /> Result:=Integer(LockObject(AInvokeContent));<br /> cmUnLockObject:<br /> UnLockObject(AInvokeContent);<br /> cmGetAsyncCallStatus:<br /> Result:=GetAsyncCallStatus(AInvokeContent);<br /> cmCancelAsyncCall:<br /> CancelAsyncCall(AInvokeContent);<br /> end;<br />end;

這簡化了開發過程,並能使客戶端很容易的實現多種通訊協議的調用,如DCOM,Socket,TCP,SOAP,甚至RS232。一般的方式,如果程式員不停的撰寫新的COM或COM+元件,不停的在元件介面裏增加新的函數,如果需要改變調用協議,如換到SOAP,就需要在SOAP中將這些COM元件及介面函數再定義,會很麻煩。

2、服務器支援用bpl來作爲BusinessObject外掛程式。

3、數據庫的訪問定義了IDBService介面,可以實現不同引擎,如BDE、ADO、DBexpress。

4、BusinessObject的訪問定義了IBizService,客戶端同時擁有IDBServer和IBizServer,即數據庫的訪問可以是直接的數據庫訪問(C/S模式),也可以通過IBizService讓中間層服務器TMTS來訪問數據庫。

5、BusinessObject可以部署在客戶端,指在客戶端Exe進程裏,不是COM dll,因此不需要安裝和註冊。

6、有自己的UI介面,可以觀察ServiceObject執行情況。並能以外掛程式形式插入一些特別應用的UI畫面。

ServiceObject的方法都定義在published區段,調用時通過RTTI來尋找被調用函數。

TServiceProc1=function(const AParams:OLEVariant):OLEVariant of object;<br /> TServiceProc2=function(const AParams:OLEVariant;AASyncCallContent:TASyncCallContent):OLEVariant of object;<br /> TServiceProc3=function(const AParams:OLEVariant;AASyncCallContent:TASyncCallContent;const AClientContent:TClientContent):OLEVariant of object;</p><p>function TCustomServiceObject.CallMethod(<br /> const AMethodName: string; const AParams: OLEVariant;<br /> const AASyncCallContent:TASyncCallContent;<br /> const AClientContent:TClientContent): OLEVariant;<br />var<br /> AMethod:TServiceProc1;<br /> vCount:integer;<br />begin<br /> TMethod(AMethod).Data:=Self;<br /> TMethod(AMethod).Code:=Self.MethodAddress(AMethodName);<br /> if TMethod(AMethod).Code=nil then<br /> Raise Exception.CreateFmt(S_MethodNotFind,[AMethodName,FServiceName]);</p><p> vCount:=GetMethodParamCount2(Self,AMethodName);<br /> case vCount of<br /> 2:Result:=TServiceProc1(AMethod)(AParams);<br /> 3:Result:=TServiceProc2(AMethod)(AParams,AASyncCallContent);<br /> 4:Result:=TServiceProc3(AMethod)(AParams,AASyncCallContent,AClientContent);<br /> else Raise Exception.CreateFmt(S_NotFoundMethod,[ClassName+':'+AMethodName,InttoStr(vCount)]);<br /> end;<br />end;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.