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

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

  • 管理传输和服务器类的创建和生存期。
  • 此DataSnap服务器组件管理传输和服务器类的创建和生存期。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 //管理传输和服务器的创建和生存期
  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 OnError: 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  更新时间:

posted on   滔Roy  阅读(361)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
历史上的今天:
2021-11-04 C[6] 预处理器
2021-11-04 PMI(采购经理人指数Purchasing Manager's Index)

导航

点击右上角即可分享
微信分享提示