Archived

This forum has been archived. Please start a new discussion on GitHub.

FreezeMap lazy initialize

xdm
xdm La Coruña, Spain
Hi

I have a problem related to initialice a FreezeMap

I have a servant Implementation in c++ that has same persitent attributes defined in is the slice class and a Freeze::Connection and Freeze::Map defined in the servant implementation header.

i wan to store this servant using Freeze::Evictor and initialize the Freeze::Conection and Freeze::Map with a servant initializer

the problem i see to do this is that i don't know how create a default constructor for my class. and leave the inizialization of Connection and Map to the servant initializer.

any ideas ?

thanks in advance

Comments

  • bernard
    bernard Jupiter, FL
    Hi Jose,

    I don't see the issue with this initialization. Maybe you could illustrate with a code sample?

    Since you want to contruct the Freeze Map object later, you need to allocate it dynamically, e.g. use a auto_ptr<MapType> data member and in the initialize function write something like:
    servant->_map.reset(new MapType(servant->_connection, servant->mapName));

    Since Freeze connections are single-threaded, it's also very common to create your Connection and Map on the stack in each operation implementation. In this situation, you could also keep a Map data member to prevent Freeze from closing the underlying Berkeley DB database.

    Cheers,
    Bernard
  • xdm
    xdm La Coruña, Spain
    Thanks a lot bernard your coment about auto_ptr solve my problem.

    Now i want that tow services access the same FreezeMap

    one service is c++ and add new objects to the map, the other is a java service and retrieve the last object add it to a lucene index and erase it from the FreezeMap.

    first of all, is this posible?

    How the java service can know that are new objects in the map?
    i think in run it periodicaly but i don't know if there is a better way

    any considerations needed for serialized the access to the freeze map from tow services?

    thanks in advance
  • bernard
    bernard Jupiter, FL
    Hi Jose,

    With Freeze, you can't share the same database environment between several processes, whether C++ or Java.
    You could however use the same database environment from a C++ and a Java process--just not at the same time.

    If both processes are running the same time, the best solution is to have just one access the database environment and let the other process access the data through a Slice interface implemented by the first process.

    Cheers,
    Bernard