"Use of Visibroker for Delphi" (4)

zhaozj2021-02-16  43

"Use of Visibroker for Delphi"

-CORBA technology practice (1)

Yichang City Center People's Hospital Zhao Pu

Email: 3boy@sohu.com

4, instance design and analysis

Last time I would like to introduce a small program that uses Pooler in CORBA. This code uses a more advanced writing method. Before analyzing this instance, I want to talk to you to the application of a design tool, of course I will be In the subsequent article in this article, in-depth discussion on these auxiliary means, I only want to describe the corresponding knowledge reserves in the true engineering project.

As far as I introduced some of the more basic language elements of the interface description language (IDL), if only the actual Visibroker-based ORB multi-layer application system, the basic application of the actual Visibroker-based ORB multi-layer application system can be bold enough (if someone opposes me is not Medium), CORBA is a standard for constant supplementary development, and each ORB product will make its own description of CORBA, so some of the previous IDLs have a certain difference with the definition of OMG, but this will not affect To us understand CORBA, of course, the previous IDL description must be fully compliant with the Visibroker specification. Among the programming of the C / S mode, most people we will not consider the interface design, and occasionally do not use our model to develop multi-layer systems, so they have just contacted multi-layer systems. The programmer has to pay more energy than the C / S mode to design it, and will delay the development cycle, I have been thinking about a problem can I avoid such a thing? Or do you seek a good way to improve our design? In my opinion, the problem of delaying period is mainly based on our determination of the interface, the uncertainty of the interface is reflected in the addition of interface, modifying the interface, abolishing the interface, etc., designing interface I feel similar to us in design ER Like the relationship between the entities in the figure, how to balance [service --- mediation --- customers] The relationship between the three is the top priority of multiple layers, but also makes us repeated culprit, here I want to recommend it to everyone Powerful Rational Radium Series (Rose, Soda, Clearcase ............................................ .. Friends in the development kit can use the Virtual Moduler tool to design (this tool is Microsoft bundled Rose products, is a standard multi-layer system) here I don't describe how to use them to design CORBA interface, only one this is one Advanced topics are not in the category of , I will discuss with you in "design practices for CORBA".

When I gossip, I will talk here, and I will start the status below.

I remember that I mentioned CORBA DATAMOUDEL OBJECT in the first section of this article. If the friend who has used this object must know the single-threaded mode and multi-thread mode, it is Corba 3.3 provides two comments to TDATAMOUDEL objects. Overall package, now the current CRB4.0 provides greater flexibility for programmers

Let us write such two different objects, obviously the latter can make us more extensive application faces, the last routine is an example of multi-thread mode, I think so before explaining multithreading mode. Let's take a look at the example of single line mode:

/ * Id1 * /

Module TypeLibcrb

{

Interface interfaceCRB;

Interface InterfaceCRB

{

Any getSqldata (in wstring script, in boolean executoractive);

/ / Define a SQL that sends a customer execution, returns an ANY type

}

//Xxx_impl.pas

Interface

Uses

SYSUTILS,

Corba,

Typelibcrb_i,

TypeLibCRB_C

;

Type

TINTERFACECRB = Class;

TinterfaceCRB = Class (TinterFaceDObject, TypeLibcrb_i.InterfaceCrb)

protected

public

Constructor crete;

Function GetSqldata (Const Script: WideString)

Const ExecutorActive: boolean: any;

END;

IMPLEMENTATION

Ushes umcrbserver, uncrbserver;

Constructor TinterfaceCrb.create;

Begin

inherited;

END;

Function TinterfaceCrb.getsqldata (const script: wideString)

Const ExecutorActive: boolean: any;

Begin

Form1.Memo1.Lines.Text: = Script;

Result: = DataMcrb.getdata (Script, ExecutorActive);

// Method for calling the TDATAMOUDEL instance, please note that there is only one TDATAMOUDEL instance this place.

// The method of this instance will be described in the program below.

END;

INITIALIZATION

End.

/ ******************* /

/ * Dynamically create data instances * /

Unit umcrbserver;

Interface

Uses

SYSUTILS, CLASS, DB, DBTABLES, Province Download (PROVIDER)

Type

TDATAMCRB = Class (TDATAModule)

DataBCRB: TDATABASE;

QueryCRB: TQuery;

DataSetPCRB: TDataSetProvider;

Private

{Private Declarations}

public

Function getData (script: string; executeoracticve: boolean): olevariant; {public declarations}

END;

VAR

DataMCRB: TDATAMCRB;

Function Runsql (Queryx: TQuery; Script: String; ExecuteOractive: Boolean): boolean;

IMPLEMENTATION

// This code has not been used in this code, nor does it control the transaction. The next chapter gives a session // routine. What will be a bit and disadvant of the application of this method, if you want to talk Talk about please send your thoughts to me // mailbox

{$ R * .dfm}

Function Runsql (Queryx: TQuery; Script: String; ExecuteOractive: Boolean): boolean;

Begin

Result: = FALSE;

With queryx do

Begin

IF Active the Active: = FALSE;

SQL.CLEAR;

SQL.Text: = Script;

IF executeoractive thein

EXECSQL ELSE

Active: = True;

IF not isempty then

RESULT: = True; End;

END;

// I don't explain this code.

{TDATAMCRB}

Function TDataMcrb.getdata (Script: String)

ExecuteORACTICVE: BOOLEVARIANT;

VAR

MYQRY: TQUERY;

MyPRV: TDATASETPROVIDER;

Begin

Try

Myqry: = tQuery.create (Self);

MyPRV: = TDataSetProvider.create (Self);

Myqry.DatabaseName: = DATABCRB.DATABASENAME;

/ (Note If you use the TDatabase object, set ShareHandle to True;

MyPRV.DataSet: = myqry;

IF Runsql (Myqry, Script, ExecuteORACTICTICTICVE) THEN

Result: = myprv.data;

Finally

Myqry.free;

MYQRY: = NIL;

MYPRV.FREE;

MyPRV: = NIL;

END;

END;

// Dynamically create a data set and data provider object, and return the data to the client after the call interface to release the dynamically created two // objects. This avoids objects that have portable interfaces after the client in single-line mode.

End.

/ *************************************** /

/ Initialize CORBA instance, main unit

Unit UNCRBSERVER;

Interface

Uses

Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,

Corba, TypeLibcrb_c, TypeLibcrb_i, TypeLibcrb_impl, TypeLibcrb_s,

STDCTRLS;

Type

TFORM1 = Class (TFORM)

Procedure formcreate (Sender: TOBJECT);

Private

{Private Declarations}

protected

{Protected Declarations}

Mycrb: interfaceCrb;

Procedure Initcorba;

public

{public declarations}

END;

VAR

FORM1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TFORM1.INITCORBA;

Begin

Corbainitialize;

Mycrb: = TinterfaceCrbskeleton.create ('mycrbserver', tinterfacecrb.create);

Boa.objisready (mycrb as _object); // CORBA service Ready

END;

Procedure TFORM1.FormCreate (Sender: TOBJECT);

Begin

INitcorba; // Initialization

END;

End.

/ ************************************************** ***** /

/ Client program

Nit unclientmain;

Interface

Uses

Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,

Corba, TypeLibcrb_c, TypeLibcrb_i, Grids, DBGRIDS, DB, DBCLIENT, STDCTRLS;

Type

TFORM2 = Class (TFORM)

EDIT1: TEDIT;

Button1: Tbutton; ClientDataSet1: TclientDataSet;

DataSource1: TDataSource;

DBGRID1: TDBGRID;

Procedure Button1Click (Sender: TOBJECT);

Procedure formcreate (Sender: TOBJECT);

Private

{Private Declarations}

protected

/ Mycrb: interfaceCrb;

{Protected Declarations}

public

{public declarations}

END;

VAR

Form2: TFORM2;

IMPLEMENTATION

{$ R * .dfm}

Procedure TFORM2.BUTTON1CLICK (Sender: TOBJECT);

Begin

ClientDataSet1.Data :=mycrb.getsqldata(Edit1.Text, False);

END;

Procedure TFORM2.FORMCREATE (Sender: TOBJECT);

Begin

Mycrb: = TinterFacecrbhelper.bind ('mycrbserver', '127.0.0.1');

END;

End.

The above program allows you to use the ApplyUpdate method to update the data from the client. Class programs because your intermediate layer data set and data provider do not have persistent, which is the following code uses DMPOOLER's exquisite.

//

TDATAMODULECLASS = Class of TdataModule; // "Class" Reference

First, due to the uncertainty of the number of client requests, we must provide a possible request for possible requests, assuming that there may be five independent requests we consider at the same time have such a lasting object. Then we can set poolsize = 5, pay attention to define in the global const, because each object is an independent body, but it can also be included in the TLIST object, and of course there is a more advanced construction. Methods, these things are derived from programmers to Delphi's understanding, for example: you can use all instances using TCollection category, not use the following record type:

TPOOLEDMODULE = Record

Module: tdataModule;

INUSE: Boolean;

END;

Of course, the comparison of this place is used to handle each Item. This unit contains a TDATAMODULE instance, which means that the amount of switch that this instance is started (I am named, of course, this is just basic expression, According to the rules of business needs, you need yourself to define your better than this, and this thing is also from the understanding of OO concepts, and the accumulation of object-oriented programming).

Of course, because our customer objects are independent of each other and is indeed a lasting object, then tell us the entire object pool, it is a multi-threaded architecture (if you are the friends who are in the first time you are best to read Thread). So we must declare it in the construction method of the object.

Constructor TModulePooler.create;

Begin

Ismultithread: = true;

......

END;

If the request is interrupted by the customer, or the instance stops this instance to terminate this instance, release the instance object: Procedure TModulePooler.FreeModule; DataModule: TdataModule;

VAR

I: integer;

Begin

.........

For i: = 0 to Length (FModules) - 1 DO

IF fmodules [i] .Module = DATAMODULE THEN

Fmodules [i] .inuse: = false;

ReleaseSemaphore (FSemaphore, 1, NIL);

...... ..

END;

Then, how do we construct this unit's entity method after we write well?

Please see:

Function TModulePooler.getModule: TDATAMODULE;

VAR

I: integer;

Begin

Result: = NIL;

IF WaitforsingleObject (fsemaphore, 5000) = Wait_timeout then

// Set the delay response, assume the service timeout, then we will trigger an exception class, indicating that the server is too busy and failed to respond.

Raise Exception.create ('Server Too Bussy');

Try

if Length (FModules) = 0 THEN

// If this object record array is empty, we will create such a dynamic object record array, create a linked list, each object exists as one of the units, of course, I think this method is not the best in actual development. , I will use TStrings or TLIST and TCollections to save units, and I will give it to the next section.

Begin

SETLENGTH (FModules, poolsize);

For i: = 0 to poolsize - 1 do

Begin

Fmodules [i] .inuse: = false;

FModules [i] .Module: = fmoduleclass.create (Application);

END;

END;

For i: = 0 to Length (FModules) - 1 DO

IF not fModules [i] .inuse kil

Begin

Fmodules [i] .inuse: = true;

Result: = fmodules [i] .Module

Break;

END;

Finally

Fcsect.Leave;

END;

// Check if We ran out of connections

IF not assigned (result) THEN

Raise Exception.create ('Pool Is Out of Capacity');

END;

Create when loading

INITIALIZATION

ModulePooler: = TModulePooler.create;

Exit

Finalization

ModulePooler.Free;

Never remember if the detection object exists, be sure to release a lasting object when it is no longer used, otherwise it will constantly stack, and finally overflow!

It may be the reason for the work. I have always smoked too much time to write such an article. I seem to be based on

C / S

The software will be less and less, and most of them will gather in Microsoft.

COM

In the system, this is not saying

COM

Certainly

Corba

Excellent, but

COM

Don't have money, but just need a set of Win2000 / XP,

Of course it has always been

C

Friends who design language can refer to a lot of use

C

Write information,

Delphi

The friends' information is less pitiful, suggestions or learn a little

C

, I believe that "the real programmer used

C

, Smart programmers

Object Pascal

Master

[

Absolute excellent programmer

]

It is a "conditional" "" "

Corba

Because of cross-platform

),

No condition

COM

(because

Corba

toll

, COM

free)

".

The next section discusses more advanced topics (object positioning technology and interface abnormal processing)

转载请注明原文地址:https://www.9cbs.com/read-27062.html

New Post(0)