首页 > 其他分享 >Delphi XE DataSnap.DSServer[2] TDSServer[1] 介绍

Delphi XE DataSnap.DSServer[2] TDSServer[1] 介绍

时间:2022-11-04 11:46:58浏览次数:54  
标签:function const string Delphi TDSServer DataSnap client ChannelName procedure

Delphi XE DataSnap.DSServer[2] TDSServer[1] 介绍

  • 管理传输和服务器类的创建和生存期。
  • 此DataSnap服务器组件管理传输和服务器类的创建和生存期。
 //管理传输和服务器的创建和生存期
  TDSServer = class(TDSCustomServer)
  private
    FAutoStart:       Boolean;
    FConnectEvent:    TDSConnectEvent;
    FPrepareEvent:    TDSPrepareEvent;
    FDisconnectEvent: TDSConnectEvent;
    FErrorEvent:      TDSErrorEvent;
    FCallbacks:       TObjectList<TDSCallbackTunnel>;

    FSetupConverterEvent: TDSSetupConverterEvent;
    FSetupReverterEvent:  TDSSetupReverterEvent;
    FRegConverters: TObjectDictionary<string, TConverterEvent>;
    FRegReverters:  TObjectDictionary<string, TReverterEvent>;

    FChannelQueueSize: Integer;

    FChannelResponseTimeout: Integer;

    class var
      FServerList:    TDBXArrayList;
    class procedure AddServer(Server: TDSCustomServer); static;
    class procedure RemoveServer(Server: TDSCustomServer); static;

    procedure ReadHideDSAdmin(Reader: TReader);
    procedure ShutdownCallbacks;
  protected
    /// <summary> Shutdown all the callbacks in the server before transport layer stops.</summary>
    procedure TransportStopping(const Sender: TDSServerTransport); override;
    procedure Loaded; override;
    procedure Connecting(const ConnectEventObject: TDSConnectEventObject); override;
    procedure Preparing(const PrepareEventObject: TDSPrepareEventObject); override;
    procedure Disconnecting(const ConnectEventObject: TDSConnectEventObject); override;
    procedure Error(const ErrorEventObject: TDSErrorEventObject); override;
    function  GetTraceInfoEvent: TDBXTraceEvent; virtual;
    procedure SetTraceInfoEvent(const TraceInfoEvent: TDBXTraceEvent); virtual;
    procedure DefineProperties(Filer: TFiler); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    ///<summary>
    ///  Find the instance of the server by its component name.
    ///</summary>
    class function FindServer(Name: string): TDSCustomServer; static;
    ///<summary>
    ///  Create an local, inprocess connection to this server with the connection
    ///  properties provided.
    ///</summary>
    function GetServerConnection(const Properties: TDBXProperties): TDBXConnection; overload; override;

    ///<summary>
    ///  Start the server.  This will call the Start method on all <c>TDSServerTransport</c>
    ///  component implementations and all <c>TDSServerClass</c> components that have set
    ///  their <c>Server</c> property to this instance.
    ///  This method is called automatically if/when the component is loaded if
    ///  the <c>AutoStart</c> property is set to true.
    ///
    ///</summary>
    procedure Start; override;
    ///<summary>
    ///  Stop the server.  This will call the Stop method on all <c>TDSServerTransport</c>
    ///  implementations and all <c>TDSServerClass</c> components that have set
    ///  their <c>Server</c> property to this instance.
    ///
    ///</summary>
    procedure Stop; override;

    ///  <summary>
    ///    Registers a channel callback with current instance and returns the communication tunnel
    ///  </summary>
    ///  <remarks>
    ///    It is expected that the callback is created per-need bases. When the first callback
    ///    registers with the client channel then and only then the callback tunnel is created. If
    ///    no client callback registers, no resources are allocated. Hence the need for CallbackId.
    ///
    ///    The function returns nil if there is already a channel created for the client id
    ///  </remarks>
    function CreateChannelTunnel(const ChannelName: string; const ClientId: string;
                                     const CallbackId: string; ChannelNames: TStringList;
                                     const SecurityToken: string): TDSCallbackTunnel;
    function RegisterChannelCallback(const ClientId: string; const CallbackId: string;
                                     ChannelNames: TStringList; const SecurityToken: string): Boolean;
    function GetCallbackTunnel(const ClientManagerId: string): TDSCallbackTunnel;
    function CallbackTunnelOf(const ClientManagerId: string): TDSCallbackTunnel;


    ///  <summary>
    ///    Returns true if there is a tunnel for a given client id. False otherwise.
    ///  </summary>
    function HasChannelCallback(const ClientId: string): Boolean;

    ///  <summary>
    ///    Unregisters the client channel based on channel name and client id
    ///  </summary>
    procedure UnregisterChannelCallback(const ClientId: string;
                                        const SecurityToken: string;
                                        Owner: Boolean = false); overload;
    ///  <summary>
    ///    Unregisters a client callback. No notification or broadcasts will be possible after that
    ///  </summary>
    procedure UnregisterChannelCallback(const ClientId: string;
                                        const CallbackId: string; const SecurityToken: string); overload;

    ///  <summary>
    ///    Unregisters a client callback. No notification or broadcasts will be possible after that
    ///  </summary>
    procedure UnregisterChannelCallback(Tunnel: TDSCallbackTunnel; DoBroadcast: Boolean = True); overload;

    ///  <summary> sends a message to all client callbacks </summary>
    function BroadcastMessage(const ChannelName: string; const Msg: TJSONValue;
                              const ArgType: Integer = TDBXCallback.ArgJson): Boolean; overload;
    function BroadcastObject(const ChannelName: string; const Msg: TObject): Boolean; overload;
    ///  <summary> sends a message to all client callbacks with a given registered callback id </summary>
    function BroadcastMessage(const ChannelName: string; const CallbackId: string;
                              const Msg: TJSONValue; const ArgType: Integer = TDBXCallback.ArgJson): Boolean; overload;
    function BroadcastObject(const ChannelName: string; const CallbackId: string;
                              const Msg: TObject): Boolean; overload;

{$IFNDEF NEXTGEN}
    ///  <summary>deprecated. ChannelName is no longer required</summary>
    ///  <remarks> Call the version of NotifyCallback that doesn't take a ChannelName. </remarks>
    function NotifyCallback(const ChannelName: string;
                            const ClientId: string;
                            const CallbackId: string;
                            const Msg: TJSONValue; out Response: TJSONValue;
                            Timeout: Cardinal = INFINITE;
                            const ArgType: Integer = TDBXCallback.ArgJson): Boolean; overload; deprecated 'ChannelName is no longer required';
    ///  <summary>deprecated. ChannelName is no longer required</summary>
    ///  <remarks> Call the version of NotifyObject that doesn't take a ChannelName. </remarks>
    function NotifyObject(const ChannelName: string;
                          const ClientId: string;
                          const CallbackId: string;
                          const Msg: TObject; out Response: TObject;
                          Timeout: Cardinal = INFINITE): Boolean; overload; deprecated 'ChannelName is no longer required';
{$ENDIF !NEXTGEN}

    ///  <summary>Synchroneous message delivery to a callback located in a client channel</summary>
    ///  <remarks> Returns false if the delivery fails </remarks>
    function NotifyCallback(const ClientId: string;
                            const CallbackId: string;
                            const Msg: TJSONValue; out Response: TJSONValue;
                            Timeout: Cardinal = INFINITE;
                            const ArgType: Integer = TDBXCallback.ArgJson): Boolean; overload;
    function NotifyObject(const ClientId: string;
                            const CallbackId: string;
                            const Msg: TObject; out Response: TObject;
                            Timeout: Cardinal = INFINITE): Boolean; overload;
    ///  <summary> Returns a list of all channel names</summary>
    function GetAllChannelNames: TList<string>;
    ///  <summary> Returns a list of all callbacks available on that channel</summary>
    function GetAllChannelCallbackId(const ChannelName: string): TList<string>;
    ///  <summary> Returns a list of all client channels registered with a given channel</summary>
    function GetAllChannelClientId(const ChannelName: string): TList<string>;
    ///  <summary> Returns the marshaler for TObject parameters</summary>
    function GetJSONMarshaler: TJSONMarshal;
    ///  <summary> Returns the un-marshaler for TObject parameters</summary>
    function GetJSONUnMarshaler: TJSONUnMarshal;
    ///  <summary> Marshal argument using local marshaler</summary>
    function MarshalData(Data: TObject): TJSONValue;
    ///  <summary> UnMarshal argument using local unmarshaler</summary>
    function UnMarshalJSON(Data: TJSONValue): TObject;
    property HideDSAdmin;
  published
    ///<summary>
    /// Use this event to receive notification that a server method is being
    ///  prepared for all <c>TDSServerClass</c> instances registered with
    ///  this server.  See <c>TDSServerClass.OnPrepare</c> for more information.
    ///</summary>
    property OnPrepare: TDSPrepareEvent read FPrepareEvent write FPrepareEvent;
    ///<summary>
    /// Use this event to receive notifcation when a connection is opened.
    ///  If an exception is raised, in this event handler, the connection
    ///  will be denied.
    ///</summary>
    property OnConnect: TDSConnectEvent read FConnectEvent write FConnectEvent;
    ///<summary>
    /// Use this event to receive notifcation when a connection is closed.
    ///</summary>
    property OnDisconnect: TDSConnectEvent read FDisconnectEvent write FDisconnectEvent;
    ///<summary>
    ///   Use this event to receive notifcation of execeptions that are raised
    ///  during the execution of a server method.
    ///</summary>
    property one rror: TDSErrorEvent read FErrorEvent write FErrorEvent;
    ///<summary>
    ///  When set to true, this causes the server to be automatically started when
    ///  the <c>TDSServer</c> component is loaded.
    ///</summary>
    [Default(True)]
    property AutoStart: Boolean read FAutoStart write FAutoStart default True;
    ///<returns>
    ///  Event handler used for receiving trace events.
    ///</returns>
    property OnTrace: TDBXTraceEvent read GetTraceInfoEvent write SetTraceInfoEvent;
    ///<summary>
    ///  The number of messages which can be queued for sending to a specific client at once.
    ///  If the queue reaches this size, all attempts to send to that client will fail until
    ///  the size of the queue decreases (one or more messages get sent.)
    ///</summary>
    [Default(100)]
    property ChannelQueueSize: Integer read FChannelQueueSize write FChannelQueueSize default 100;
    ///<summary>
    ///  The length in milliseconds to wait for a client's response to a heavyweight callback
    ///  message sent to them, before determining the client is lost or or disabled in some way,
    ///  and terminating the tunnel. Use a value of 0 to not automatically close a tunnel, unless
    ///  the session expires.
    ///</summary>
    [Default(30000)]
    property ChannelResponseTimeout: Integer read FChannelResponseTimeout write FChannelResponseTimeout default 30000;
  end;

  

 

 

 

 

创建时间:2022.11.04  更新时间:

标签:function,const,string,Delphi,TDSServer,DataSnap,client,ChannelName,procedure
From: https://www.cnblogs.com/guorongtao/p/16857199.html

相关文章

  • Delphi XE DataSnap.DSServer[1]介绍
    DelphiXEDataSnap.DSServer[1]介绍定义实现DataSnap回调隧道的类、要通过这些隧道发送的项、事件、隧道管理器、提供程序模块适配器、管理传输和服务器类的创建和生存......
  • Delphi获取Unix当前系统时间戳
    procedureTForm1.btn4Click(Sender:TObject); varStr:String; D:tDatetime; a:Double; functionDateTimeToUnixDate(constADate:TDateTime):Longint; c......
  • Delphi XE System.Generics.Collections[1] - 介绍
    DelphiXESystem.Generics.Collections[1]-介绍实现通用容器类以将数据项分组为数组、字典、列表、堆栈、队列等的单元。Package:rtl270.bpl ClassesTArrayCla......
  • delphi TscSplitView控件学习笔记(2)
    效果图:设计图:scSplitView设置:opened:false;openedwidth:150;(按你自己需求)compactwidth:35;(确保只能看到图标即可)设计技巧:compactwidth先设置成全尺......
  • delphi TscSplitView控件学习笔记
    一.先说效果吧,放置的位置不一样,显示出来的效果也不一样 然后效果是这样的:注意位置标记1按钮的位置.当DisplayMode:=scsvmOverlay时,会遮挡TscSplitView......
  • Delphi datasnap如何使用IPv6地址
    今天看到电信公司开始推广使用IPv6我也想着用datasnap中间件也使用IPv6,百度一下都是下面的说法: “有些人说DATASNAP不支持IPv6,只支持IPv4。这是不正确的。DATASNAP默......
  • Delphi 替换字符函数
    Delphi中的StringReplace函数是SysUtils单元中自带的函数:typeTReplaceFlags=setof(rfReplaceAll,rfIgnoreCase);functionStringReplace(constS,OldPattern,......
  • delphi TMS FlexCel 导出页面设置
    TMSFlexCel导出页面设置属性和方法TFlexCelHtmlExport.HidePrintObjectspropertyHidePrintObjects:SetofTHidePrintObjects选择哪些类型的对象不应该导出。导......
  • delphi 避免两个联动的COMBOBOX进入死循环
      当物料类型为刀具仓时,单位自动修改为粒 当物料类型为原料仓时,单位自动修改为公斤反之亦然.这是两个相互联动的控件,如果直接写的话,会直接死循环.如何......
  • Delphi获取程序版本号
    参考: http://www.delphitop.com/html/hanshu/4627.htmlprocedureGetVersionInfo(constFileName:string;varvs:string);varVerInfoSize,VerValueSize,Dummy:DWORD;......