Results 1 to 6 of 6

Thread: Question on proper way to signal problem in IceBox start

  1. #1
    grembo is offline Registered User
    Name: Michael Gmelin
    Organization: Grem Equity GmbH
    Project: E-Commerce platform
    Join Date
    Jan 2009
    Posts
    85

    Question on proper way to signal problem in IceBox start

    Hi,

    what is the proper way to signal an initialization problem on IceBox::Service::start? Checked the manual but couldn't really find any answers in there. According to the source code in case of an exception there will be a log message (and in case of an Ice::Exception the content of the exception will be logged as well).

    Is there any specific exception that you recommend to throw in such a scenario (in case of my example this is a missing property required when configuring the IceBox service, right now I write a log message and simply issue a return - which for IceBox seems to signal that all is ok). So I would prefer to throw a meaningful exception in that case, ideally the chapter on IceBox should cover this.

    So in my case imagine the following code snippet:
    Code:
    void MyServiceI::start(const std::string& name, 
    const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args)
    {
      if (communicator->getProperties()->getProperty("ImportantProperty").empty())  
      {
        throw Ice::WhichExceptionToThrow("ImportantPropertyNotSet");
      }
    
      _adapter = communicator->createObjectAdapter(name);
      _adapter->add(new MyFactoryI());  
      _adapter->activate();
    }
    For convenience I attached the source of the relevant part in ServiceManagerI.cpp below.

    cheers
    Michael

    Code:
        bool started = false;
        try
        {
            info.service->start(name, info.communicator == 0 ? _sharedCommunicator : info.communicator, info.args);
            started = true;
        }
        catch(const Ice::Exception& ex)
        {
            Warning out(_logger);
            out << "ServiceManager: exception in start for service " << info.name << ":\n";
            out << ex;
        }
        catch(...)
        {
            Warning out(_logger);
            out << "ServiceManager: unknown exception in start for service " << info.name;
        }
        
        {
            IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
    
            vector<ServiceInfo>::iterator p;
            for(p = _services.begin(); p != _services.end(); ++p)
            {
                if(p->name == name)
                {
                    if(started)
                    {
                        p->status = Started;
    
                        vector<string> services;
                        services.push_back(name);
                        servicesStarted(services, _observers);
                    }
                    else
                    {
                        p->status = Stopped;
                    }
                    break;
                }
            }
            _pendingStatusChanges = false;
            notifyAll();

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Hi,

    You can throw an IceBox::FailureException:
    Code:
    if (communicator->getProperties()->getProperty("ImportantProperty").empty())  
    {
        throw IceBox::FailureException(__FILE__, __LINE__, "invalid property");
    }
    Cheers,
    Benoit.

  3. #3
    grembo is offline Registered User
    Name: Michael Gmelin
    Organization: Grem Equity GmbH
    Project: E-Commerce platform
    Join Date
    Jan 2009
    Posts
    85
    Hi Benoit

    thanks for your answer, so would you recommend FailureException as best practice is that scenario? I think the IceBox manual could use a short paragraph on the topic.

    Thanks
    Michael

  4. #4
    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
    1,445
    Quote Originally Posted by grembo View Post
    thanks for your answer, so would you recommend FailureException as best practice is that scenario? I think the IceBox manual could use a short paragraph on the topic.
    Yes, using FailureException is the simplest solution. We'll update the manual accordingly.

    Mark

  5. #5
    grembo is offline Registered User
    Name: Michael Gmelin
    Organization: Grem Equity GmbH
    Project: E-Commerce platform
    Join Date
    Jan 2009
    Posts
    85
    Will do, thanks.

  6. #6
    grembo is offline Registered User
    Name: Michael Gmelin
    Organization: Grem Equity GmbH
    Project: E-Commerce platform
    Join Date
    Jan 2009
    Posts
    85
    Just realized, that FailureException is actually defined and documented in IceBox.ice

    Code:
    /**
     *
     * An application service managed by a {@link ServiceManager}.
     *
     **/
    local interface Service
    {
        /**
         *
         * Start the service. The given communicator is created by the
         * {@link ServiceManager} for use by the service. This communicator may
         * also be used by other services, depending on the service
         * configuration.
         *
         * <p class="Note">The {@link ServiceManager} owns this communicator, and is
         * responsible for destroying it.
         *
         * @param name The service's name, as determined by the
         * configuration.
         *
         * @param communicator A communicator for use by the service.
         *
         * @param args The service arguments that were not converted into
         * properties.
         *
         * @throws FailureException Raised if {@link #start} failed.
         *
         **/
        void start(string name, Ice::Communicator communicator, Ice::StringSeq args);
    
        /**
         *
         * Stop the service.
         *
         **/
        void stop();
    };
    I will make sure to consult the individual documentation in slices as well in the future.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How can I start icebox as a service?sos!~
    By liuruigong in forum Help Center
    Replies: 0
    Last Post: 03-10-2010, 08:57 PM
  2. IceBox service - start/stop
    By ngambek2003 in forum Help Center
    Replies: 3
    Last Post: 09-25-2009, 04:32 PM
  3. Replies: 1
    Last Post: 01-18-2007, 12:02 AM
  4. How to start the iceBox in java for the storm service
    By Jason Gao in forum Help Center
    Replies: 5
    Last Post: 10-20-2006, 05:32 AM
  5. problem when call another service at start function.
    By damingyipai in forum Bug Reports
    Replies: 2
    Last Post: 02-29-2004, 07:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •