Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 03-03-2008
sly596 sly596 is online now
Registered User
 
Name: Pete Sylvester
Organization: Coconaut Studios
Project: iPhone/iPod Game
 
Join Date: Feb 2008
Posts: 13
Async Subscriber

Is there a way to create an Async Subscriber with IceStorm?

Both the clock demo, and the documentation only demonstrate the blocking method communicator()->waitForShutdown();

Thanks,
Pete
Reply With Quote
  #2 (permalink)  
Old 03-03-2008
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Hi Peter,

An Ice application is not required to call waitForShutdown, it is simply a convenient way of blocking the calling thread until shutdown is invoked on the communicator. In a server context (such as an IceStorm subscriber), you only need to activate the object adapter to allow incoming requests to be dispatched.

Hope that helps,
Mark
Reply With Quote
  #3 (permalink)  
Old 03-03-2008
sly596 sly596 is online now
Registered User
 
Name: Pete Sylvester
Organization: Coconaut Studios
Project: iPhone/iPod Game
 
Join Date: Feb 2008
Posts: 13
It seems if I don't call that method it just seems like the subscriber closes right away:

Code:
[ 03/03/08 18:36:15.515 Subscriber: 97ec16db-daba-49ef-943e-18e53d850782: topic publish failed: Network.cpp:664: Ice::ConnectionRefusedException:connection refused: WSAECONNREFUSED ]
What I'm trying to do is just create a subscriber class, so I can just instantiate a subscriber object in my app:

Code:
    public class Subscriber : Ice.Application
    {
        private IceStorm.TopicPrx topic;
        private Ice.ObjectAdapter adapter;
        private Ice.ObjectPrx subscriber;
        private IceStorm.QoS qos;

        public class LimehouseI : LimehouseDisp_
        {
            public override void sendCommand(string date, Ice.Current current)
            {
                System.Console.Out.WriteLine(date);
            }
        }


        public override int run(string[] args)
        {
            IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast(
                communicator().propertyToProxy("IceStorm.TopicManager.Proxy"));
            if (manager == null)
            {
                Console.WriteLine("invalid proxy");
                return 1;
            }

            string topicName = "LimehouseCMD";
            bool datagram = false;
            bool twoway = false;
            bool ordered = false;
            bool batch = false;
            int optsSet = 0;
            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i].Equals("--datagram"))
                {
                    datagram = true;
                    ++optsSet;
                }
                else if (args[i].Equals("--twoway"))
                {
                    twoway = true;
                    ++optsSet;
                }
                else if (args[i].Equals("--ordered"))
                {
                    ordered = true;
                    ++optsSet;
                }
                else if (args[i].Equals("--oneway"))
                {
                    ++optsSet;
                }
                else if (args[i].Equals("--batch"))
                {
                    batch = true;
                }
                else if (args[i].StartsWith("--"))
                {
                    usage();
                    return 1;
                }
                else
                {
                    topicName = args[i];
                    break;
                }
            }

            if (batch && (twoway || ordered))
            {
                Console.WriteLine(appName() + ": batch can only be set with oneway or datagram");
                return 1;
            }

            if (optsSet > 1)
            {
                usage();
                return 1;
            }

            //
            // Retrieve the topic.
            //
            
            try
            {
                topic = manager.retrieve(topicName);
            }
            catch (IceStorm.NoSuchTopic)
            {
                try
                {
                    topic = manager.create(topicName);
                }
                catch (IceStorm.TopicExists)
                {
                    Console.WriteLine("temporary error. try again.");
                    return 1;
                }
            }

            adapter = communicator().createObjectAdapter("Limehouse.Subscriber");

            //
            // Add a Servant for the Ice Object.
            //
            subscriber = adapter.addWithUUID(new LimehouseI());

            qos = new IceStorm.QoS();

            //
            // Set up the proxy.
            //
            if (datagram)
            {
                subscriber = subscriber.ice_datagram();
            }
            else if (twoway)
            {
                // Do nothing to the subscriber proxy. Its already twoway.
            }
            else if (ordered)
            {
                // Do nothing to the subscriber proxy. Its already twoway.
                qos["reliability"] = "ordered";
            }
            else // if(oneway)
            {
                subscriber = subscriber.ice_oneway();
            }
            if (batch)
            {
                if (datagram)
                {
                    subscriber = subscriber.ice_batchDatagram();
                }
                else
                {
                    subscriber = subscriber.ice_batchOneway();
                }
            }

            topic.subscribeAndGetPublisher(qos, subscriber);
            adapter.activate();

            //shutdownOnInterrupt();
            //communicator().waitForShutdown();

            //
            // Unsubscribe all subscribed objects.
            //
            //topic.unsubscribe(subscriber);

            return 0;
        }

        public void unsubscribe()
        {
            topic.unsubscribe(subscriber);
        }

        public void usage()
        {
            Console.WriteLine("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]");
        }

    }
It is the Clock demo. I just changed a few things here and there. Am I going about this incorrectly?

Thanks,
Pete

Last edited by sly596 : 03-03-2008 at 08:38 PM.
Reply With Quote
  #4 (permalink)  
Old 03-03-2008
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Hi Pete,

If your main thread has nothing else to do, you should call waitForShutdown to prevent the subscriber from exiting immediately.

Take care,
Mark
Reply With Quote
  #5 (permalink)  
Old 03-04-2008
sly596 sly596 is online now
Registered User
 
Name: Pete Sylvester
Organization: Coconaut Studios
Project: iPhone/iPod Game
 
Join Date: Feb 2008
Posts: 13
My main thread is running a GUI, so the app is still running when I receive that message. If I was to call that method, my GUI would never get drawn.

Is it correct for the Subscriber to inherit from Ice.Application? This app also contains a Publisher class which also inherits from Ice.Application.

Thanks,
Pete
Reply With Quote
  #6 (permalink)  
Old 03-04-2008
matthew's Avatar
matthew matthew is online now
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,061
Quote:
My main thread is running a GUI, so the app is still running when I receive that message. If I was to call that method, my GUI would never get drawn.
Sorry, but what is your question here? If you don't want to block the caller until shutdown is called then don't call waitForShutdown.

Quote:
Is it correct for the Subscriber to inherit from Ice.Application? This app also contains a Publisher class which also inherits from Ice.Application.
I'm afraid I don't understand this question either. Ice.Application is only a convenience class and you certainly don't have to use it. If it doesn't do what you want then you don't have to use it. I suggest you take a look in the Ice manual for more information on what Ice::Application is, and what it does for you (section 8.3.1 covers this). For an example of a bare bones Ice application take a look at demo/Ice/minimal.

Last edited by matthew : 03-04-2008 at 02:42 AM.
Reply With Quote
  #7 (permalink)  
Old 03-04-2008
sly596 sly596 is online now
Registered User
 
Name: Pete Sylvester
Organization: Coconaut Studios
Project: iPhone/iPod Game
 
Join Date: Feb 2008
Posts: 13
Quote:
Originally Posted by matthew View Post
Sorry, but what is your question here? If you don't want to block the caller until shutdown is called then don't call waitForShutdown.
No question here, I was merely responding to Mark.

Quote:
Originally Posted by matthew View Post
I'm afraid I don't understand this question either. Ice.Application is only a convenience class and you certainly don't have to use it. If it doesn't do what you want then you don't have to use it. I suggest you take a look in the Ice manual for more information on what Ice::Application is, and what it does for you (section 8.3.1 covers this). For an example of a bare bones Ice application take a look at demo/Ice/minimal.
Thanks, you cleared up my confusion.
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
Publisher and Subscriber sly596 Help Center 6 08-13-2008 05:18 PM
Async bidirectional issue Kruppy Help Center 15 05-16-2007 11:44 AM
about Subscriber and Publisher terminate Help Center 1 04-27-2007 01:44 PM
Async retry mechanism garry Bug Reports 1 08-02-2005 12:31 PM
Server-Initiated Async acbell Help Center 7 02-28-2005 05:46 PM


All times are GMT -4. The time now is 12:52 PM.


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.