Hello
I trying to implement the model view controller pattern using IceStorm to deliver messages or events fron model objects to client views. in oder to do it I add a new interface to my base object derived from Ice::Object, create and Event class to emcapsulate events that are send and create a listener inteface that must be implemented or agreate by View objects the definitios as are follow
Code:
module Oz
{
module Base
{
class Event
{
// the id of the object that send the event
Ice::Identity objectId;
// a name used for diference events
string name;
};
inteface EventPublisher
{
void eMit(Oz::Base::Event e);
};
interface EventListener
{
// this operation create a Ices::Storm subcriber
// for topic named objectId.name
idempotent void suscribe(Ice::Identity objectId);
// this operation unsuscribe object
// for topic objectId.name
idempotent void unsuscribe(Ice::Identity objectId);
// this opeartion is the contract betwen publisher
// and subscriber object
idempotent void notify(Event e);
};
};
};
my problem is that i need a diferent topic for each object and this topics must be created on demand with object creation like topics are not persistent and objects are persistents. I think to diferents ways to manage this situation are
1) try to retrive a topic in objectInitializer and if topic not exist creating it the code can be as folow
Code:
void
Oz::Base::ObjectInitializer::initializer(
const Ice::ObjectAdapterPtr&,
const Ice::Identity& objId,
const std::string& ,
const Ice::ObjectPtr& obj)
{
/** heare I initilize topic manager code not show for simplicy **/
try
{
obj->topic=topicManagerPx->retrieve(obj->getId().name);
}
catch(const IceStorm::NoSuchTopic& ex)
{
obj->topic=topicManagerPx->create(obj->getId().name);
}
}
2) can be a better aproach to do it this in the eMit operation if ObjectNoExistException is throw whe try to a call an operation on topic object
Code:
void Oz::Base::eMit(Oz::Base::Event e)
{
try
{
topic->notify(e);
}
catch(ObjectNoExistException& e)
{
/*retrive topic manager code not show*/
topic=topicManagerPx->create(id.name);
topic->notify(e);
}
}
In the client side i create a subscriber Proxy for each view and sucribe it to the correspoding model proxy.
My subscriber implementation can hold a pointer to the view object a when notifiy
operation is invoked in the subscriber in dispach the envet to the view.
can you say me if this a correct usage for IceStorm service?
what aproach can be better to ensure that s exist a topic for each object, or
any sugestion for do it in a diferent way?
In other to subscribe objects be accessible by IceStorm service is neceary configuring Glacier or Glacier2 are both valid?
it is posible to adquire topic manager via IcePack::Query i think yes but i'm not sure.
Thanks in advantage