~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to src/IceGrid/IceGridNode.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francisco Moya
  • Date: 2008-02-12 16:28:20 UTC
  • mfrom: (4.1.5 hardy)
  • Revision ID: james.westby@ubuntu.com-20080212162820-x3e046s7nmabeswv
Tags: 3.2.1-8
Added -g to global compilation flags (Closes: #465074).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
16
16
#include <IceGrid/RegistryI.h>
17
17
#include <IceGrid/FileUserAccountMapperI.h>
18
18
#include <IceGrid/NodeI.h>
 
19
#include <IceGrid/NodeSessionManager.h>
19
20
#include <IceGrid/TraceLevels.h>
20
 
#include <IceGrid/DescriptorParser.h>
21
21
#ifdef __BCPLUSPLUS__
22
22
#  include <IceGrid/ServerI.h>
23
23
#  include <IceGrid/AdminSessionI.h>
24
24
#  include <IceGrid/ReapThread.h>
25
25
#  include <IceGrid/Database.h>
 
26
#  include <IceGrid/WellKnownObjectsManager.h>
26
27
#endif
 
28
#include <IceGrid/DescriptorParser.h>
27
29
#include <IcePatch2/Util.h>
28
30
 
29
31
#ifdef _WIN32
46
48
namespace IceGrid
47
49
{
48
50
 
49
 
class KeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
50
 
{
51
 
public:
52
 
 
53
 
    KeepAliveThread(const NodeIPtr& node, int timeout) : 
54
 
        _node(node), 
55
 
        _timeout(IceUtil::Time::seconds(timeout)), 
56
 
        _shutdown(false)
57
 
    {
58
 
    }
59
 
 
60
 
    virtual void
61
 
    run()
62
 
    {
63
 
        Lock sync(*this);
64
 
        while(!_shutdown)
65
 
        {
66
 
            int timeout = _node->keepAlive();
67
 
            if(timeout > 0)
68
 
            {
69
 
                _timeout = IceUtil::Time::seconds(timeout);
70
 
            }
71
 
            if(!_shutdown)
72
 
            {
73
 
                timedWait(_timeout);
74
 
            }
75
 
        }
76
 
    }
77
 
 
78
 
    virtual void
79
 
    terminate()
80
 
    {
81
 
        Lock sync(*this);
82
 
        _shutdown = true;
83
 
        notifyAll();
84
 
    }
85
 
 
86
 
private:
87
 
 
88
 
    const NodeIPtr _node;
89
 
    IceUtil::Time _timeout;
90
 
    bool _shutdown;
91
 
};
92
 
typedef IceUtil::Handle<KeepAliveThread> KeepAliveThreadPtr;
93
 
 
94
51
class ProcessI : public Process
95
52
{
96
53
public:
124
81
private:
125
82
 
126
83
    void usage(const std::string&);
 
84
    string trim(const string&);
127
85
 
128
86
    ActivatorPtr _activator;
129
87
    WaitQueuePtr _waitQueue;
130
88
    RegistryIPtr _registry;
131
89
    NodeIPtr _node;
132
 
    KeepAliveThreadPtr _keepAliveThread;
 
90
    NodeSessionManager _sessions;
133
91
    Ice::ObjectAdapterPtr _adapter;
134
92
};
135
93
 
148
106
} // End of namespace IceGrid
149
107
 
150
108
CollocatedRegistry::CollocatedRegistry(const CommunicatorPtr& communicator, const ActivatorPtr& activator) :
151
 
    RegistryI(communicator), 
 
109
    RegistryI(communicator, new TraceLevels(communicator, "IceGrid.Registry")), 
152
110
    _activator(activator)
153
111
{
154
112
}
174
132
{
175
133
    switch(fd)
176
134
    {
177
 
        case 1:
178
 
        {
179
 
            cout << message << endl;
180
 
            break;
181
 
        }
182
 
        case 2:
183
 
        {
184
 
            cerr << message << endl;
185
 
            break;
186
 
        }
 
135
        case 1:
 
136
        {
 
137
            cout << message << endl;
 
138
            break;
 
139
        }
 
140
        case 2:
 
141
        {
 
142
            cerr << message << endl;
 
143
            break;
 
144
        }
187
145
    }
188
146
}
189
147
 
196
154
{
197
155
    assert(_activator);
198
156
    _activator->shutdown();
 
157
    _sessions.terminate(); // Unblock the main thread if it's blocked on waitForCreate()
199
158
    return true;
200
159
}
201
160
 
237
196
                targets.push_back(argv[i]);
238
197
            }
239
198
        }
240
 
        else
241
 
        {
242
 
            error("invalid option: `" + string(argv[i]) + "'");
243
 
            usage(argv[0]);
244
 
            return false;
245
 
        }
 
199
        else
 
200
        {
 
201
            error("invalid option: `" + string(argv[i]) + "'");
 
202
            usage(argv[0]);
 
203
            return false;
 
204
        }
246
205
    }
247
206
 
248
207
    PropertiesPtr properties = communicator()->getProperties();
263
222
    //
264
223
    if(!nowarn && properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 0) > 0)
265
224
    {
266
 
        Warning out(communicator()->getLogger());
267
 
        out << "setting `Ice.ThreadPool.Server.Size' is not useful,\n";
268
 
        out << "you should set individual adapter thread pools instead.";
 
225
        Warning out(communicator()->getLogger());
 
226
        out << "setting `Ice.ThreadPool.Server.Size' is not useful, ";
 
227
        out << "you should set individual adapter thread pools instead.";
269
228
    }
270
229
    
271
230
    int size = properties->getPropertyAsIntWithDefault("IceGrid.Node.ThreadPool.Size", 0);
272
231
    if(size <= 0)
273
232
    {
274
 
        properties->setProperty("IceGrid.Node.ThreadPool.Size", "1");
275
 
        size = 1;
 
233
        properties->setProperty("IceGrid.Node.ThreadPool.Size", "1");
 
234
        size = 1;
276
235
    }
 
236
 
277
237
    int sizeMax = properties->getPropertyAsIntWithDefault("IceGrid.Node.ThreadPool.SizeMax", 0);
278
238
    if(sizeMax <= 0)
279
239
    {
280
 
        if(size >= sizeMax)
281
 
        {
282
 
            sizeMax = size * 10;
283
 
        }
284
 
        
285
 
        ostringstream os;
286
 
        os << sizeMax;
287
 
        properties->setProperty("IceGrid.Node.ThreadPool.SizeMax", os.str());
 
240
        if(size >= sizeMax)
 
241
        {
 
242
            sizeMax = size * 10;
 
243
        }
 
244
        
 
245
        ostringstream os;
 
246
        os << sizeMax;
 
247
        properties->setProperty("IceGrid.Node.ThreadPool.SizeMax", os.str());
 
248
    }
 
249
 
 
250
    size = properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Client.Size", 0);
 
251
    if(size <= 0)
 
252
    {
 
253
        properties->setProperty("Ice.ThreadPool.Client.Size", "1");
 
254
        size = 1;
 
255
    }
 
256
    sizeMax = properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Client.SizeMax", 0);
 
257
    if(sizeMax <= 0)
 
258
    {
 
259
        if(size >= sizeMax)
 
260
        {
 
261
            sizeMax = size * 10;
 
262
        }
 
263
        if(sizeMax < 100)
 
264
        {
 
265
            sizeMax = 100;
 
266
        }
 
267
        ostringstream os;
 
268
        os << sizeMax;
 
269
        properties->setProperty("Ice.ThreadPool.Client.SizeMax", os.str());
288
270
    }
289
271
 
290
272
    //
291
273
    // Create the activator.
292
274
    //
293
 
    TraceLevelsPtr traceLevels = new TraceLevels(properties, communicator()->getLogger(), true);
294
 
    _activator = new Activator(traceLevels, properties);
 
275
    TraceLevelsPtr traceLevels = new TraceLevels(communicator(), "IceGrid.Node");
 
276
    _activator = new Activator(traceLevels);
295
277
 
296
278
    //
297
279
    // Collocate the IceGrid registry if we need to.
305
287
        }
306
288
 
307
289
        //
308
 
        // Set the Ice.Default.Locator property to point to the
309
 
        // collocated locator (this property is passed by the
310
 
        // activator to each activated server).
 
290
        // Set the default locator property to point to the collocated
 
291
        // locator (this property is passed by the activator to each
 
292
        // activated server). The default locator is also needed by
 
293
        // the node session manager.
311
294
        //
312
 
        const string instanceNameProperty = "IceGrid.InstanceName";
313
 
        Identity locatorId;
314
 
        locatorId.category = properties->getPropertyWithDefault(instanceNameProperty, "IceGrid");
315
 
        locatorId.name = "Locator";
316
 
        string locatorPrx = "\"" + communicator()->identityToString(locatorId) + "\" :" + 
317
 
                            properties->getProperty("IceGrid.Registry.Client.Endpoints");
318
 
        properties->setProperty("Ice.Default.Locator", locatorPrx);
 
295
        if(properties->getProperty("Ice.Default.Locator").empty())
 
296
        {
 
297
            Identity locatorId;
 
298
            locatorId.category = properties->getPropertyWithDefault("IceGrid.InstanceName", "IceGrid");
 
299
            locatorId.name = "Locator";
 
300
            string endpoints = properties->getProperty("IceGrid.Registry.Client.Endpoints");
 
301
            string locatorPrx = "\"" + communicator()->identityToString(locatorId) + "\" :" + endpoints;
 
302
            communicator()->setDefaultLocator(LocatorPrx::uncheckedCast(communicator()->stringToProxy(locatorPrx)));
 
303
            properties->setProperty("Ice.Default.Locator", locatorPrx);
 
304
        }
319
305
    }
320
306
    else if(properties->getProperty("Ice.Default.Locator").empty())
321
307
    {
339
325
        struct _stat filestat;
340
326
        if(::_stat(dataPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode))
341
327
        {
342
 
            ostringstream os;
343
 
            FileException ex(__FILE__, __LINE__);
344
 
            ex.path = dataPath;
345
 
            ex.error = getSystemErrno();
346
 
            os << ex;
 
328
            ostringstream os;
 
329
            FileException ex(__FILE__, __LINE__);
 
330
            ex.path = dataPath;
 
331
            ex.error = getSystemErrno();
 
332
            os << ex;
347
333
            error("property `IceGrid.Node.Data' is set to an invalid path:\n" + os.str());
348
 
            return false;
 
334
            return false;
349
335
        }            
350
336
#else
351
337
        struct stat filestat;
352
338
        if(::stat(dataPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode))
353
339
        {
354
 
            ostringstream os;
355
 
            FileException ex(__FILE__, __LINE__);
356
 
            ex.path = dataPath;
357
 
            ex.error = getSystemErrno();
358
 
            os << ex;
 
340
            ostringstream os;
 
341
            FileException ex(__FILE__, __LINE__);
 
342
            ex.path = dataPath;
 
343
            ex.error = getSystemErrno();
 
344
            os << ex;
359
345
            error("property `IceGrid.Node.Data' is set to an invalid path:\n" + os.str());
360
 
            return false;
 
346
            return false;
361
347
        }            
362
348
#endif
363
349
 
369
355
            dataPath += "/"; 
370
356
        }
371
357
 
372
 
        IcePatch2::createDirectory(dataPath + "servers");
373
 
        IcePatch2::createDirectory(dataPath + "tmp");
374
 
        IcePatch2::createDirectory(dataPath + "distrib");
 
358
        IcePatch2::createDirectory(dataPath + "servers");
 
359
        IcePatch2::createDirectory(dataPath + "tmp");
 
360
        IcePatch2::createDirectory(dataPath + "distrib");
375
361
    }
376
362
 
377
363
    //
386
372
    string name = properties->getProperty("IceGrid.Node.Name");
387
373
    if(name.empty())
388
374
    {
389
 
        char host[1024 + 1];
390
 
        string hostname;
391
 
        if(gethostname(host, 1024) != -1)
392
 
        {
393
 
            hostname = host;
394
 
        }
395
 
        if(hostname.empty())
396
 
        {
397
 
            error("property `IceGrid.Node.Name' is not set and hostname is empty");
398
 
            return false;
399
 
        }
400
 
        if(!nowarn)
401
 
        {
402
 
            warning("property `IceGrid.Node.Name' is not set, using hostname: " + hostname);
403
 
        }
404
 
        properties->setProperty("IceGrid.Node.Name", hostname);
405
 
        name = hostname;
 
375
        error("property `IceGrid.Node.Name' is not set");
 
376
        return false;
406
377
    }
407
378
 
408
379
    //
421
392
    //
422
393
    // Setup the user account mapper if configured.
423
394
    //
424
 
    string mapperProperty = properties->getProperty("IceGrid.Node.UserAccountMapper");
 
395
    string mapperProperty = "IceGrid.Node.UserAccountMapper";
 
396
    string mapperPropertyValue = properties->getProperty(mapperProperty);
425
397
    UserAccountMapperPrx mapper;
426
 
    if(!mapperProperty.empty())
 
398
    if(!mapperPropertyValue.empty())
427
399
    {
428
 
        try
429
 
        {
430
 
            mapper = UserAccountMapperPrx::uncheckedCast(communicator()->stringToProxy(mapperProperty));
431
 
        }
432
 
        catch(const Ice::LocalException& ex)
433
 
        {
434
 
            ostringstream os;
435
 
            os << "user account mapper `" << mapperProperty << "' is invalid:\n" << ex;
436
 
            error(os.str());
437
 
            return false;
438
 
        }
 
400
        try
 
401
        {
 
402
            mapper = UserAccountMapperPrx::uncheckedCast(communicator()->propertyToProxy(mapperProperty));
 
403
        }
 
404
        catch(const Ice::LocalException& ex)
 
405
        {
 
406
            ostringstream os;
 
407
            os << "user account mapper `" << mapperProperty << "' is invalid:\n" << ex;
 
408
            error(os.str());
 
409
            return false;
 
410
        }
439
411
    }
440
412
    else
441
413
    {
442
 
        string userAccountFileProperty = properties->getProperty("IceGrid.Node.UserAccounts");
443
 
        if(!userAccountFileProperty.empty())
444
 
        {
445
 
            try
446
 
            {
447
 
                Ice::ObjectPrx object = _adapter->addWithUUID(new FileUserAccountMapperI(userAccountFileProperty));
448
 
                object = object->ice_collocationOptimized(true);
449
 
                mapper = UserAccountMapperPrx::uncheckedCast(object);
450
 
            }
451
 
            catch(const std::string& msg)
452
 
            {
453
 
                error(msg);
454
 
                return false;
455
 
            }
456
 
        }
 
414
        string userAccountFileProperty = properties->getProperty("IceGrid.Node.UserAccounts");
 
415
        if(!userAccountFileProperty.empty())
 
416
        {
 
417
            try
 
418
            {
 
419
                Ice::ObjectPrx object = _adapter->addWithUUID(new FileUserAccountMapperI(userAccountFileProperty));
 
420
                object = object->ice_collocationOptimized(true);
 
421
                mapper = UserAccountMapperPrx::uncheckedCast(object);
 
422
            }
 
423
            catch(const std::string& msg)
 
424
            {
 
425
                error(msg);
 
426
                return false;
 
427
            }
 
428
        }
457
429
    }
458
430
 
459
431
    //
463
435
    _waitQueue->start();
464
436
 
465
437
    //
 
438
    // The IceGrid instance name.
 
439
    //
 
440
    const string instanceName = communicator()->getDefaultLocator()->ice_getIdentity().category;
 
441
 
 
442
    //
466
443
    // Create the server factory. The server factory creates persistent objects
467
444
    // for the server and server adapter. It also takes care of installing the
468
445
    // evictors and object factories necessary to store these objects.
469
446
    //
470
 
    Identity id = communicator()->stringToIdentity(IceUtil::generateUUID());
 
447
    Identity id = communicator()->stringToIdentity(instanceName + "/Node-" + name);
471
448
    NodePrx nodeProxy = NodePrx::uncheckedCast(_adapter->createProxy(id));
472
 
    _node = new NodeI(_adapter, _activator, _waitQueue, traceLevels, nodeProxy, name, mapper);
 
449
    _node = new NodeI(_adapter, _sessions, _activator, _waitQueue, traceLevels, nodeProxy, name, mapper);
473
450
    _adapter->add(_node, nodeProxy->ice_getIdentity());
474
451
 
475
452
    //
476
 
    // Start the keep alive thread. By default we start the thread
477
 
    // with a 5s timeout, then we'll use the registry node session
478
 
    // timeout / 2.
479
 
    //
480
 
    _keepAliveThread = new KeepAliveThread(_node, 5);
481
 
    _keepAliveThread->start();
 
453
    // Start the platform info thread if needed.
 
454
    //
 
455
    _node->getPlatformInfo().start();
 
456
 
 
457
    //
 
458
    // Create the node sessions with the registries.
 
459
    //
 
460
    _sessions.create(_node);
482
461
 
483
462
    //
484
463
    // Add a process servant to allow shutdown through the process
486
465
    //
487
466
    if(!properties->getProperty("Ice.ServerId").empty() && communicator()->getDefaultLocator())
488
467
    {
489
 
        try
490
 
        {
491
 
            ProcessPrx proxy = ProcessPrx::uncheckedCast(_adapter->addWithUUID(new ProcessI(_activator)));
492
 
            LocatorRegistryPrx locatorRegistry = communicator()->getDefaultLocator()->getRegistry();
493
 
            locatorRegistry->setServerProcessProxy(properties->getProperty("Ice.ServerId"), proxy);
494
 
        }
495
 
        catch(const ServerNotFoundException&)
496
 
        {
497
 
        }
498
 
        catch(const LocalException&)
499
 
        {
500
 
        }
 
468
        try
 
469
        {
 
470
            ProcessPrx proxy = ProcessPrx::uncheckedCast(_adapter->addWithUUID(new ProcessI(_activator)));
 
471
            LocatorRegistryPrx locatorRegistry = communicator()->getDefaultLocator()->getRegistry();
 
472
            locatorRegistry->setServerProcessProxy(properties->getProperty("Ice.ServerId"), proxy);
 
473
        }
 
474
        catch(const ServerNotFoundException&)
 
475
        {
 
476
        }
 
477
        catch(const LocalException&)
 
478
        {
 
479
        }
501
480
    }
502
481
 
503
482
    //
511
490
    _adapter->activate();
512
491
 
513
492
    //
 
493
    // Notify the node session manager that the node can start
 
494
    // accepting incoming connections.
 
495
    //
 
496
    _sessions.activate();
 
497
 
 
498
    string bundleName = properties->getProperty("IceGrid.Node.PrintServersReady");
 
499
    if(!bundleName.empty() || !desc.empty())
 
500
    {
 
501
        enableInterrupt();
 
502
        if(!_sessions.waitForCreate())
 
503
        {
 
504
            //
 
505
            // Create was interrupted, return true as if the service was
 
506
            // correctly initiliazed to make sure it's properly stopped.
 
507
            //
 
508
            return true;
 
509
        }
 
510
        disableInterrupt();
 
511
    }
 
512
 
 
513
    //
514
514
    // Deploy application if a descriptor is passed as a command-line option.
515
515
    //
516
516
    if(!desc.empty())
517
517
    {
518
 
        AdminPrx admin;
519
518
        try
520
519
        {
521
 
            const string instanceNameProperty = "IceGrid.InstanceName";
522
 
            Identity adminId;
523
 
            adminId.category = properties->getPropertyWithDefault(instanceNameProperty, "IceGrid");
524
 
            adminId.name = "Admin";
525
 
            admin = AdminPrx::checkedCast(
526
 
                        communicator()->stringToProxy("\"" + communicator()->identityToString(adminId) + "\""));
 
520
            Ice::Identity registryId;
 
521
            registryId.category = instanceName;
 
522
            registryId.name = "Registry";
 
523
            
 
524
            RegistryPrx registry = RegistryPrx::checkedCast(
 
525
                communicator()->stringToProxy("\"" + communicator()->identityToString(registryId) + "\""));
 
526
            if(!registry)
 
527
            {
 
528
                throw "invalid registry";
 
529
            }
 
530
        
 
531
            //
 
532
            // Use SSL if available.
 
533
            //
 
534
            try
 
535
            {
 
536
                registry = RegistryPrx::checkedCast(registry->ice_secure(true));
 
537
            }
 
538
            catch(const Ice::NoEndpointException&)
 
539
            {
 
540
            }
 
541
            
 
542
            IceGrid::AdminSessionPrx session;
 
543
            if(communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.AuthenticateUsingSSL"))
 
544
            {
 
545
                session = registry->createAdminSessionFromSecureConnection();
 
546
            }
 
547
            else
 
548
            {
 
549
                string id = communicator()->getProperties()->getProperty("IceGridAdmin.Username");
 
550
                string password = communicator()->getProperties()->getProperty("IceGridAdmin.Password");
 
551
                while(id.empty())
 
552
                {
 
553
                    cout << "user id: " << flush;
 
554
                    getline(cin, id);
 
555
                    id = trim(id);
 
556
                }
 
557
                
 
558
                if(password.empty())
 
559
                {
 
560
                    cout << "password: " << flush;
 
561
                    getline(cin, password);
 
562
                    password = trim(password);
 
563
                }
 
564
                
 
565
                session = registry->createAdminSession(id, password);
 
566
            }
 
567
            assert(session);
 
568
 
 
569
            AdminPrx admin = session->getAdmin();
 
570
            map<string, string> vars;
 
571
            ApplicationDescriptor app = DescriptorParser::parseDescriptor(desc, targets, vars, communicator(), admin);
 
572
 
 
573
            try
 
574
            {
 
575
                admin->syncApplication(app);
 
576
            }
 
577
            catch(const ApplicationNotExistException&)
 
578
            {
 
579
                admin->addApplication(app);
 
580
            }
 
581
        }
 
582
        catch(const DeploymentException& ex)
 
583
        {
 
584
            ostringstream ostr;
 
585
            ostr << "failed to deploy application `" << desc << "':\n" << ex << ": " << ex.reason;
 
586
            warning(ostr.str());
 
587
        }
 
588
        catch(const AccessDeniedException& ex)
 
589
        {
 
590
            ostringstream ostr;
 
591
            ostr << "failed to deploy application `" << desc << "':\n" 
 
592
                 << "registry database is locked by `" << ex.lockUserId << "'";
 
593
            warning(ostr.str());
527
594
        }
528
595
        catch(const LocalException& ex)
529
596
        {
530
597
            ostringstream ostr;
531
 
            ostr << "couldn't contact IceGrid admin interface to deploy application `" << desc << "':\n" << ex;
 
598
            ostr << "failed to deploy application `" << desc << "':\n" << ex;
532
599
            warning(ostr.str());
533
600
        }
534
 
 
535
 
        if(admin)
 
601
        catch(const string& reason)
536
602
        {
537
 
            try
538
 
            {
539
 
                map<string, string> vars;
540
 
                ApplicationDescriptor app;
541
 
                app = DescriptorParser::parseDescriptor(desc, targets, vars, communicator(), admin);
542
 
                try
543
 
                {
544
 
                    admin->syncApplication(app);
545
 
                }
546
 
                catch(const ApplicationNotExistException&)
547
 
                {
548
 
                    admin->addApplication(app);
549
 
                }
550
 
            }
551
 
            catch(const DeploymentException& ex)
552
 
            {
553
 
                ostringstream ostr;
554
 
                ostr << "failed to deploy application `" << desc << "':\n" << ex << ": " << ex.reason;
555
 
                warning(ostr.str());
556
 
            }
557
 
            catch(const LocalException& ex)
558
 
            {
559
 
                ostringstream ostr;
560
 
                ostr << "failed to deploy application `" << desc << "':\n" << ex;
561
 
                warning(ostr.str());
562
 
            }
 
603
            ostringstream ostr;
 
604
            ostr << "failed to deploy application `" << desc << "':\n" << reason;
 
605
            warning(ostr.str());
563
606
        }
564
607
    }
565
608
 
566
 
    string bundleName = properties->getProperty("IceGrid.Node.PrintServersReady");
567
609
    if(!bundleName.empty())
568
610
    {
569
 
        //
570
 
        // We wait for the node to be registered with the registry
571
 
        // before to claim it's ready.
572
 
        //
573
 
        _node->waitForSession();
574
 
        print(bundleName + " ready");
 
611
        print(bundleName + " ready");
575
612
    }
576
613
 
577
614
    return true;
598
635
    }
599
636
    catch(...)
600
637
    {
601
 
        assert(false);
 
638
        assert(false);
602
639
    }
603
640
 
604
641
    //
608
645
    try
609
646
    {
610
647
        _waitQueue->destroy();
611
 
        _waitQueue = 0;
 
648
        _waitQueue = 0;
612
649
    }
613
650
    catch(...)
614
651
    {
615
 
        assert(false);
616
 
    }
617
 
 
618
 
    //
619
 
    // Terminate the registration thread if it was started.
620
 
    //
621
 
    if(_keepAliveThread)
622
 
    {
623
 
        _keepAliveThread->terminate();
624
 
        _keepAliveThread->getThreadControl().join();
625
 
        _keepAliveThread = 0;
 
652
        assert(false);
626
653
    }
627
654
 
628
655
    _activator = 0;
632
659
    //
633
660
    try
634
661
    {
635
 
        _adapter->deactivate();
636
 
        _adapter = 0;
 
662
        _adapter->deactivate();
 
663
        _adapter = 0;
637
664
    }
638
665
    catch(const Ice::LocalException& ex)
639
666
    {
640
 
        ostringstream ostr;
641
 
        ostr << "unexpected exception while shutting down node:\n" << ex;
642
 
        warning(ostr.str());
 
667
        ostringstream ostr;
 
668
        ostr << "unexpected exception while shutting down node:\n" << ex;
 
669
        warning(ostr.str());
643
670
    }
644
671
 
645
672
    //
646
 
    // Stop the node (this unregister the node session with the
647
 
    // registry.)
648
 
    //
649
 
    _node->stop();
 
673
    // Terminate the node sessions with the registries.
 
674
    //
 
675
    _sessions.destroy();
 
676
 
 
677
    //
 
678
    // Stop the platform info thread.
 
679
    //
 
680
    _node->getPlatformInfo().stop();
 
681
 
 
682
    //
 
683
    // Break cylic reference counts.
 
684
    //
 
685
    _node->destroy();
650
686
    _node = 0;
651
687
 
652
688
    //
659
695
    }
660
696
    catch(const Ice::LocalException& ex)
661
697
    {
662
 
        ostringstream ostr;
663
 
        ostr << "unexpected exception while shutting down node:\n" << ex;
664
 
        warning(ostr.str());
 
698
        ostringstream ostr;
 
699
        ostr << "unexpected exception while shutting down node:\n" << ex;
 
700
        warning(ostr.str());
665
701
    }
666
702
 
667
703
    //
669
705
    //
670
706
    if(_registry)
671
707
    {
672
 
        _registry->stop();
673
 
        _registry = 0;
 
708
        _registry->stop();
 
709
        _registry = 0;
674
710
    }
675
711
 
676
712
    return true;
678
714
 
679
715
CommunicatorPtr
680
716
NodeService::initializeCommunicator(int& argc, char* argv[], 
681
 
                                    const InitializationData& initializationData)
 
717
                                    const InitializationData& initializationData)
682
718
{
683
719
    InitializationData initData = initializationData;
684
720
    initData.properties = createProperties(argc, argv, initData.properties);
697
733
NodeService::usage(const string& appName)
698
734
{
699
735
    string options =
700
 
        "Options:\n"
701
 
        "-h, --help           Show this message.\n"
702
 
        "-v, --version        Display the Ice version.\n"
703
 
        "--nowarn             Don't print any security warnings.\n"
704
 
        "\n"
705
 
        "--deploy DESCRIPTOR [TARGET1 [TARGET2 ...]]\n"
706
 
        "                     Add or update descriptor in file DESCRIPTOR, with\n"
707
 
        "                     optional targets.\n";
 
736
        "Options:\n"
 
737
        "-h, --help           Show this message.\n"
 
738
        "-v, --version        Display the Ice version.\n"
 
739
        "--nowarn             Don't print any security warnings.\n"
 
740
        "\n"
 
741
        "--deploy DESCRIPTOR [TARGET1 [TARGET2 ...]]\n"
 
742
        "                     Add or update descriptor in file DESCRIPTOR, with\n"
 
743
        "                     optional targets.\n";
708
744
#ifdef _WIN32
709
745
    if(checkSystem())
710
746
    {
711
747
        options.append(
712
 
        "\n"
713
 
        "\n"
714
 
        "--service NAME       Run as the Windows service NAME.\n"
715
 
        "\n"
716
 
        "--install NAME [--display DISP] [--executable EXEC] [args]\n"
717
 
        "                     Install as Windows service NAME. If DISP is\n"
718
 
        "                     provided, use it as the display name,\n"
719
 
        "                     otherwise NAME is used. If EXEC is provided,\n"
720
 
        "                     use it as the service executable, otherwise\n"
721
 
        "                     this executable is used. Any additional\n"
722
 
        "                     arguments are passed unchanged to the\n"
723
 
        "                     service at startup.\n"
724
 
        "--uninstall NAME     Uninstall Windows service NAME.\n"
725
 
        "--start NAME [args]  Start Windows service NAME. Any additional\n"
726
 
        "                     arguments are passed unchanged to the\n"
727
 
        "                     service.\n"
728
 
        "--stop NAME          Stop Windows service NAME."
 
748
        "\n"
 
749
        "\n"
 
750
        "--service NAME       Run as the Windows service NAME.\n"
 
751
        "\n"
 
752
        "--install NAME [--display DISP] [--executable EXEC] [args]\n"
 
753
        "                     Install as Windows service NAME. If DISP is\n"
 
754
        "                     provided, use it as the display name,\n"
 
755
        "                     otherwise NAME is used. If EXEC is provided,\n"
 
756
        "                     use it as the service executable, otherwise\n"
 
757
        "                     this executable is used. Any additional\n"
 
758
        "                     arguments are passed unchanged to the\n"
 
759
        "                     service at startup.\n"
 
760
        "--uninstall NAME     Uninstall Windows service NAME.\n"
 
761
        "--start NAME [args]  Start Windows service NAME. Any additional\n"
 
762
        "                     arguments are passed unchanged to the\n"
 
763
        "                     service.\n"
 
764
        "--stop NAME          Stop Windows service NAME."
729
765
        );
730
766
    }
731
767
#else
734
770
        "\n"
735
771
        "--daemon             Run as a daemon.\n"
736
772
        "--noclose            Do not close open file descriptors.\n"
737
 
        "--nochdir            Do not change the current working directory."
 
773
        "--nochdir            Do not change the current working directory.\n"
 
774
        "--pidfile FILE       Write process ID into FILE."
738
775
    );
739
776
#endif
740
777
    print("Usage: " + appName + " [options]\n" + options);
741
778
}
742
779
 
 
780
string
 
781
NodeService::trim(const string& s)
 
782
{
 
783
    static const string delims = "\t\r\n ";
 
784
    string::size_type last = s.find_last_not_of(delims);
 
785
    if(last != string::npos)
 
786
    {
 
787
        return s.substr(s.find_first_not_of(delims), last+1);
 
788
    }
 
789
    return s;
 
790
}
 
791
 
743
792
int
744
793
main(int argc, char* argv[])
745
794
{