summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/LocatorRegistryI.cpp
blob: c6e052758327fc572048dd20bd6a9e71a1eeec68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// **********************************************************************
//
// Copyright (c) 2002
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************

#include <Ice/Ice.h>
#include <IcePack/LocatorRegistryI.h>
#include <IcePack/AdapterI.h>

using namespace std;
using namespace IcePack;

IcePack::LocatorRegistryI::LocatorRegistryI(const AdapterRegistryPtr& registry, const Ice::ObjectAdapterPtr& adapter) :
    _registry(registry),
    _adapter(adapter)
{
}

void 
IcePack::LocatorRegistryI::setAdapterDirectProxy(const string& id, const Ice::ObjectPrx& proxy, const Ice::Current&)
{
    while(true)
    {
	try
	{
	    //
	    // Get the adapter from the registry and set its direct proxy.
	    //
	    _registry->findById(id)->setDirectProxy(proxy);
	    return;
	}
	catch(const AdapterNotExistException&)
	{
	}
	catch(const AdapterActiveException&)
	{
	    throw Ice::AdapterAlreadyActive();
	}
	catch(const Ice::ObjectNotExistException&)
	{
	    //
	    // Expected if the adapter was destroyed.
	    //
	}
	catch(const Ice::LocalException& ex)
	{
	    //
	    // TODO: We couldn't contact the adapter object. This
	    // is possibly because the IcePack node is down and
	    // the server is started manually for example. We
	    // should probably throw here to prevent the server
	    // from starting?
	    //
	    return;
	}

	//
	// TODO: Review this functionnality.
	//
	// Create a new standalone adapter. This adapter will be
	// destroyed when the registry is shutdown. Since it's not
	// persistent, it won't be restored when the registry startup
	// again. We could change this to make the adapter persistent
	// but then it's not clear when this adapter should be
	// destroyed.
	//
	// Also, is this really usefull? This allows a server (not
	// deployed or managed by an IcePack node) to use the location
	// mechanism (and avoid to share endpoints configuration
	// between the client and server). Maybe it would be less
	// confusing to just prevent servers to start if the server
	// didn't previously registered its object adapters (using the
	// IcePack deployment mechanism).
	//
	Ice::PropertiesPtr properties = _adapter->getCommunicator()->getProperties();
	if(properties->getPropertyAsInt("IcePack.Registry.DynamicRegistration") > 0)
	{
	    AdapterPrx adapter = AdapterPrx::uncheckedCast(_adapter->addWithUUID(new StandaloneAdapterI()));
	    try
	    {
		_registry->add(id, adapter);
	    }
	    catch(const AdapterExistsException&)
	    {
		_adapter->remove(adapter->ice_getIdentity());
	    }
	}
	else
	{
	    throw Ice::AdapterNotRegistered();
	}
    }
}