Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 06-19-2005
bterwijn bterwijn is offline
Registered User
 
Name: Bas Terwijn
Organization: University of Amsterdam
Project: distributed systems
 
Join Date: May 2005
Location: Haarlem, The Netherlands, Europe
Posts: 9
simplifing building ICE applications

Dear Zeroc people,

I have three questions that require some context resulting on a long posting, my apologies.

I'm trying to simplify writing Ice programs by hiding most of the complexity in a class which I call 'IAS_Application' and is derived of Ice::Application. This class exposes (among others) the following four functions.

Ice::ObjectPrx registerObject(Ice::ObjectPtr object,string name);
Ice::ObjectPrx getRegisteredObject(string name);
Ice::ObjectPrx publishTopic(string topicName);
Ice::ObjectPrx subscribeToTopic(Ice::ObjectPtr object,string topicName);

With these I'm able to write both client/server and publish/subscribe programs like below (where I only show all the lines of code in the IAS_Application::run() function):


# Server
---------
registerObject(new HelloI(communicator()),"hello1");
waitForShutdown();


# Client
---------
HelloPrx hello = HelloPrx::checkedCast(getRegisteredObject("hello1" ));
hello->sayHello();


# Subscriber
------------
subscribeToTopic(new HelloI(),"hello2");
waitForShutdown();


# Publisher
------------
HelloPrx hello = HelloPrx::uncheckedCast(publishTopic("hello2"));
hello->sayHello();


Ofcourse simplifying like this has the advantage that writing programs is easiers but has the disadvantage that you have less control. However, it seems very helpfull for people that quickly want to write (simple) distributed systems and don't care about the underlaying details. If you are interested I'm happy to share my code but it's pretty straightforward.

QUESTION 1: Why doesn't ICE supply a similar simplification in the distribution?



I have one problem with the approach described above. When the Subscriber receives a CTRL_C signal it should unsubscribe all subscribed objects automatically, similar to Ice-2.1.1/demo/IceStorm/clock/Subscriber.cpp. However, as I want to use the destroyOnInterrupt() in contrast to the shutdownOnInterrupt() it seems to me that I have to unsubscribe before the communicator is destroyed by the Ice::Application class. I have not yet succeeded in doing this.

QUESTION 2: How can I unsubscribe in the destroyOnInterrupt() mode before the communicator is destroyed (for example in Ice-2.1.1/demo/IceStorm/clock/Subscriber.cpp)?



I guess (and I could be wrong) the problem here is that the _ctrlCHandler of class Ice::Application has a callback to a static global function in contrast to a method of class Ice::Application that could be redefined/overloaded by any class inheriting from it. The code below shows how the callback of the IceUtil::CtrlCHandler class can be set to the cleanUp() method of the App class which can and is overloaded by class IAS_App. This would solve my problem I guess but I ran into difficulties rewritting the Ice::Application class, so before I continue I would like some expert advise to prevent wasting time.

QUESTION 3: Is there a good reason why Ice::Application doesn't provide such an overloadable cleanUp() method? If not, are you interested in such a rewrite of the Ice::Application class?



#include <Ice/Ice.h>
#include <IceUtil/CtrlCHandler.h>

using namespace std;

class App;

App *callbackObject;

void setCallbackObject(App *object)
{ callbackObject=object;}

App *getCallbackObject()
{ return callbackObject;}


class App
{
public:
App()
{
setCallbackObject(this);
IAS_ctrlCHandler.reset(new IceUtil::CtrlCHandler);
IAS_ctrlCHandler->setCallback(destroyOnInterruptCallback);
}

virtual ~App(){}

virtual void cleanUp()
{
cout<<"destroy communicator"<<endl;
}

static void destroyOnInterruptCallback(int signal)
{
getCallbackObject()->cleanUp();
}

private:
auto_ptr<IceUtil::CtrlCHandler> IAS_ctrlCHandler;
};


class IAS_App: virtual public App
{
public:

virtual ~IAS_App(){}

virtual void cleanUp()
{
cout<<"unsubscribe all objects"<<endl;
App::destroy();
}
};

int main()
{
IAS_App app;
cout<<"CTRL_C now!!"<<endl;
sleep(10);
cout<<"end"<<endl;
return 1;
}


Thank you for your time,

best regards,
Bas Terwijn
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Could it be overkill to use ICE for certain applications? mbylstra Help Center 6 02-08-2007 11:58 AM
Very, very strange problem with Ice-based applications! timeguest Help Center 1 01-17-2006 09:30 AM
How do I implment ThreadPool in web-based applications? mohamedriyaz Help Center 1 07-20-2005 06:48 AM
Ice with Graphical Applications spiff Help Center 3 03-25-2005 04:34 AM
How can I integrate fortran/C++ applications minifat Help Center 1 12-11-2004 07:44 AM


All times are GMT -4. The time now is 08:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.