|
|
|
|||||
|
specific design question
Hi,
I have a question regarding the design of an application with Ice... I need to first introduce a bit the context in which I am asking the question. Sometime before I knew Ice, I wrote a kind of "devlopement environnement" for my own use. It consists of a program that create c++ codes from definition files (a little bit like Ice but much more simpler). The code created is mainly class definitions that contains almost only data (from type and name found in the definition file). Using these class definitions together with a library it becomes easy to handle object contaning data in a multithreaded environnement and to create persistent images of the objects in a database (mysql). Objects can be created and destroyed, and each object can be loaded from the database using a unique id. Loading and saving is automated, and access to the data is synchronized object by object. For example, and to be quick, if I write a definition file containing the definition of a class named "CThing" containing a variable of type string named "name", I can write the following snippet of code:" { CThingP athing(12); athing->name="Blue thing"; } At the creating of the object "athing", the object number 12 will be loaded from database (if not already in a memory cache) and a mutex will be acquired for that object. Then the member variable "name" will be assigned. At the exit of the scope, athing is destroyed, saving the value of "name" in the database and releasing the mutex. Now I would like to add a touch if Ice in all that. I would like a client program to access the objects CThings living on a server. Basically, I would like the client to be able to get and set the value of the variable "name" of the object CThing number 12 from a server program running on another machine. It seems to me that I have mainly to approches: 1) I can drop my whole system and making the CThing objects Ice objects using the correct slice definition, instanciating one Ice object for each entry in the database and making these objects avalaible to client, for example through stringified proxies containing the id number. I will also need to write code for setting and getting the "name" variable through Ice operation that can handle the database stuff (or use Freeze, I don't know yet...). 2) I can keep my system, and create an Ice object that is some kind of "accessors": Let say a client can get a proxy "Things" to a unique Ice object of type "CThingAccessor" that is instanciated on the server, it can then do Things->get_name(12,the_name); The operation "get_name" of the Ice Object CThingAccessor will basically execute the code above and return the value of "name" to "the_name". Of course the benefit of this solution is that I can keep a lot of code already using succesfuly my system. But are there big drawbacks? What do you think is the best approach in the sens of using Ice at its best, and to create the most "professional" application? If a get really a lot of entries in my database, is there a problem to instanciate a lot of small objects for the whole time of the server activity? In the first approach if I want to get the name of all the CThings objects, I need to do a lot of server requests, but in the second approach I can add a "get_all_name" operation that return a sequence of string containing all the value at once... In the second approach, It seems that there is too much synchronizations: one for the object ThingAccessor and one for the CThings, is it right? In the fist approach, can a safely and quickly get the correct proxy for the correct id (I need to keep the unique relation object-id). Thank you very much in advance for any hint. |
|
|||||
|
Hi,
I preferer a mix of the two approaches, that preserves the existing system, adding an Ice layer in front of it. You can have a Things object that gives you operations such as: Iterator getAllNames() together with a "real" Thing Ice object with setter and getter. Things object would be equipped with a Thing *getById(..) that gives you a proxy to a Thing object with a particular id. On the server side the whole system could be represented by a single Ice Thing object, say IceThing, impersonating different implementation Thing object. If you decidee to have an entire ObjectAdapter devoted to Thing objects, you could have a single instance of IceThing (Servant) with a default ServantLocator returning always that instance. In turn, IceThing can select the right implementation for a particular request using the Ice object id of the Current argument of IceThing methods. It is worth to note that you can create, on the server side, the proxy without accessing the real object with: adapter.createProxy(Ice.Util.stringToIdentity(id)) ; where adapter is the ObjectAdapter where IceThing resides and id is the implementation Thing id. You could also consider the possibility to use category part of Ice object identity to represent Thing class. In this way the Ice identity of a Thing implementation object, say 35, would be: "35/thing" Then, the ServantLocator would be registered, in the ObjectAdapter, for category "thing". A final word on performances. It depends on the use you make of Thing object, but I think that IceThing object should have an accessor the gives you all the attributes in one call. Don't forget that, normally, each call on the proxy goes remote. If Thing has a lot of attributes..... Hope it helps, Guido. |
|
|||||
|
and about synchronisation
Thanks a lot Guido and Marc for your replies. It helps me a lot and gave me some (hopefuly good idea)
I get one more question regarding what you said Marc, in your post: Quote:
I am sure there is a mechanism to prevent this. Could you explain it to me quickly? Quote:
Thank you. |
|
||||||
|
Re: and about synchronisation
Quote:
Take care, - Mark |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Newbie's question: wondering how to design to make this work... | sjinny | Help Center | 6 | 06-05-2006 11:15 AM |
| Provide language specific documentations of Ice | vermorel | Comments | 2 | 12-08-2005 05:24 AM |
| IcePatch design question | stephan | Help Center | 1 | 09-28-2004 04:00 PM |
| dll specific question | xdm | Help Center | 1 | 09-02-2004 01:08 PM |
| force use of specific Slice libs (cross compiling) | rbx | Help Center | 1 | 12-09-2003 02:14 PM |