• 读DataSnap源代码(六)


    具体分析一下DataSanp App与Rest, WebBroker App的不同,先看TDSHTTPService。

     ***********************************************************************************************

    TDSHTTPService = class(TCustomDSHTTPServerTransport) 

    继承体系:

    TDSHTTPService -> TCustomDSHTTPServerTransport -> TCustomDSRESTServerTransport -> TDSServerTransport ...

    ************************************************************************************************

    TDSHTTPWebDispatcher = class(TDSHTTPServerTransport, IWebDispatch)

    继承体系:

    TDSHTTPWebDispatcher -> TDSHTTPServerTransport -> TCustomDSHTTPServerTransport  ...

    ************************************************************************************************

    都是TCustomDSHTTPServerTransport的后代.  目前来看,如果没有意外,后续的请求处理方式应该是一样的。

    那么DataSanp App的WEB请求又是从哪开始的呢?

     1   TCustomDSHTTPServerTransport = class(TCustomDSRESTServerTransport)
     2   strict protected
     3     FHttpServer: TDSHTTPServer;
     4   strict private
     5     { Private declarations }
     6     FCredentialsPassthrough: Boolean;
     7     FDSAuthPassword: string;
     8     FDSAuthUser: string;
     9     FDSPort: Integer;
    10     FDSHostName: string;
    11     FDSCacheContext: string;
    12     function IsCacheContextStored: Boolean;
    13   private
    14     function GetHttpServer: TDSHTTPServer;
    15     function IsDSHostnameStored: Boolean;
    16     procedure SetCacheContext(const Ctx: string);
    17     function GetCacheContext: string;
    18   protected
    19     function CreateHttpServer: TDSHTTPServer; virtual; abstract;

    上面是TCustomDSHTTPServerTransport类的部分定义,可以看到第19行处,有一个abstract的方法,意味着TCustomDSHTTPServerTransport的子类必须实现这个方法 。

     1 function TDSHTTPService.CreateHttpServer: TDSHTTPServer;
     2 var
     3   LHTTPServer: TDSHTTPServerIndy;
     4 begin
     5   if Assigned(FCertFiles) then
     6     LHTTPServer := TDSHTTPSServerIndy.Create(Self.Server, IPImplementationID)
     7   else
     8     LHTTPServer := TDSHTTPServerIndy.Create(Self.Server, IPImplementationID);
     9   Result := LHTTPServer;
    10   LHTTPServer.HTTPOtherContext := HTTPOtherContext;
    11 end;
    1 function TDSHTTPWebDispatcher.CreateHttpServer: TDSHTTPServer;
    2 begin
    3   Result := TDSHTTPServerWebBroker.Create;
    4 end;

    果然是不一样的,但都是一个父类继承下来的:

      TDSHTTPServerIndy= class(TDSHTTPServer)

      TDSHTTPServerWebBroker = class(TDSHTTPServer)

     1   TDSHTTPServerIndy = class(TDSHTTPServer)
     2   strict private
     3     FHTTPOtherContext: TDSHTTPOtherContextEvent;
     4   private
     5     FServer: IIPHTTPServer;
     6     FDefaultPort: Word;
     7     FServerSoftware: string;
     8     FIPImplementationID: string;
     9     FPeerProcs: IIPPeerProcs;
    10     function PeerProcs: IIPPeerProcs;
    11     function GetActive: Boolean;
    12     function GetDefaultPort: Word;
    13     procedure SetActive(const Value: Boolean);
    14     procedure SetDefaultPort(const Value: Word);
    15     procedure DoIndyCommand(AContext: IIPContext;
    16       ARequestInfo: IIPHTTPRequestInfo; AResponseInfo: IIPHTTPResponseInfo);
    17     function GetServerSoftware: string;
    18     procedure SetServerSoftware(const Value: string);
    19     property HTTPOtherContext: TDSHTTPOtherContextEvent read FHTTPOtherContext write FHTTPOtherContext;
    20   protected
    21     function Decode(Data: string): string; override;
    22     procedure DoCommandOtherContext(AContext: TDSHTTPContext;
    23       ARequestInfo: TDSHTTPRequest; AResponseInfo: TDSHTTPResponse;
    24       const ARequest: string); override;
    25     procedure InitializeServer; virtual;
    26   public
    27     constructor Create(const ADSServer: TDSCustomServer; const AIPImplementationID: string = ''); override;
    28     destructor Destroy; override;
    29     property Server: IIPHTTPServer read FServer;
    30     property DefaultPort: Word read GetDefaultPort write SetDefaultPort;
    31     property Active: Boolean read GetActive write SetActive;
    32     property ServerSoftware: string read GetServerSoftware write SetServerSoftware;
    33   end;


     

     1 procedure TDSHTTPServerIndy.SetActive(const Value: Boolean);
     2 begin
     3   if Value and (FServer = nil) then
     4   begin
     5     FServer := PeerFactory.CreatePeer(FIPImplementationID, IIPHTTPServer, nil) as IIPHTTPServer;
     6     InitializeServer;
     7   end;
     8   if FServer <> nil then
     9     FServer.Active := Value;
    10 end;
  • 相关阅读:
    离线数仓 建模、表的类型分类
    获取每个部门中当前员工薪水最高的相关信息
    dwd层 维度退化 的作用
    单例模式懒汉式
    反汇编命令使用
    RabbitMQ实战高级特性
    初步理解MySQL的gap锁
    【java并发系列】Controller是线程安全吗_ 安全方式如何
    mysql_14_count(*)为什么这么慢
    MySQL 通过Docker搭建主从同步
  • 原文地址:https://www.cnblogs.com/Jiaojiawang/p/4819236.html
Copyright © 2020-2023  润新知