示例#1
0
ServerEntryPtr
ServerCache::postUpdate(const ServerInfo& info, bool noRestart)
{
    Lock sync(*this);

    ServerEntryPtr entry = getImpl(info.descriptor->id);
    assert(entry);

    ServerInfo oldInfo = entry->getInfo();
    entry->update(info, noRestart);

    if(!noRestart)
    {
        _nodeCache.get(info.node, true)->addServer(entry);
        forEachCommunicator(AddCommunicator(*this, entry, info.application))(oldInfo.descriptor, info.descriptor);
    }

    if(_traceLevels && _traceLevels->server > 0)
    {
        Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
        out << "updated server `" << info.descriptor->id << "' (`" << info.uuid << "', `" << info.revision << "')";
    }

    return entry;
}
示例#2
0
ServerEntryPtr
ServerCache::add(const ServerInfo& info)
{
    Lock sync(*this);

    ServerEntryPtr entry = getImpl(info.descriptor->id);
    if(!entry)
    {
        entry = new ServerEntry(*this, info.descriptor->id);
        addImpl(info.descriptor->id, entry);
    }
    entry->update(info, false);

    _nodeCache.get(info.node, true)->addServer(entry);

    forEachCommunicator(AddCommunicator(*this, entry, info.application))(info.descriptor);

    if(_traceLevels && _traceLevels->server > 0)
    {
        Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
        out << "added server `" << info.descriptor->id << "' (`" << info.uuid << "', `" << info.revision << "')";
    }

    return entry;
}
示例#3
0
void
ServerCache::preUpdate(const ServerInfo& newInfo, bool noRestart)
{
    Lock sync(*this);

    const string& id = newInfo.descriptor->id;
    ServerEntryPtr entry = getImpl(id);
    assert(entry);

    if(!noRestart)
    {
        ServerInfo info = entry->getInfo();
        forEachCommunicator(RemoveCommunicator(*this, entry))(info.descriptor, newInfo.descriptor);
        _nodeCache.get(info.node)->removeServer(entry);
    }

    if(_traceLevels && _traceLevels->server > 0)
    {
        Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
        out << "updating server `" << id << "'";
        if(noRestart)
        {
            out << " with no restart";
        }
    }
}
示例#4
0
bool
ServerCache::has(const string& id) const
{
    Lock sync(*this);
    ServerEntryPtr entry = getImpl(id);
    return entry && !entry->isDestroyed();
}
示例#5
0
void SceneClientManager::init(const std::vector<ServerEntryPtr>& scenesentry)
{
	if (scenesentry.empty())
	{
		LOG(INFO)<<("can't find scene entry");
		return ;
	}
	else
	{
		LOG(INFO)<<"scene entry num="<<scenesentry.size();
	}

	for (size_t i=0;i<scenesentry.size(); ++i)
	{
		ServerEntryPtr e = scenesentry[i];
		connection_ptr conn(new connection(GatewayServer::instance().get_io_service(), std::string("sceneclient") + boost::lexical_cast<std::string>(i)));
		context_ptr client(new SceneClient(conn->get_io_service(), conn, e));
		conn->set_context(client);

		conn->set_compressor(std::shared_ptr<loki::compressor>(new loki::compressor_zlib()));

		char key[32]= {'a', 'b', 'c'};
		std::shared_ptr<loki::encryptor_aes> aes(new loki::encryptor_aes());
		aes->setkey((const unsigned char*)key,256);
		conn->set_encryptor(aes);
		/////////////////////

		conn->set_connected_handler(std::bind(&SceneClientManager::on_connected, this, std::placeholders::_1));
		conn->set_error_handler(std::bind(&SceneClientManager::on_error, this, std::placeholders::_1));

		//直接放入主逻辑线程处理
		conn->set_msg_handler(std::bind(&GatewayServer::on_msg, GatewayServer::getSingletonPtr(), std::placeholders::_1));

		conn->async_connect(e->ip(), e->port());

		//start timer
		//timer_.expires_from_now(boost::posix_time::seconds(5));
		//timer_.async_wait(boost::bind(&SceneClientManager::check_reconnect, SceneClientManager::instance_ptr(), _1, conn));
	}

}
示例#6
0
void
IceGrid::RegistryServerAdminRouter::ice_invoke_async(const AMD_Object_ice_invokePtr& cb,
                                                     const std::pair<const Ice::Byte*, const Ice::Byte*>& inParams,
                                                     const Current& current)
{
    ObjectPrx target = 0;

    try
    {
        ServerEntryPtr server = _database->getServer(current.id.name);
        try
        {
            target = server->getAdminProxy();
        }
        catch(const SynchronizationException&)
        {
            server->addSyncCallback(new SynchronizationCallbackI(this, cb, inParams, current));
            return; // Wait for the server synchronization to complete and retry.
        }
    }
    catch(const ServerNotExistException&)
    {
    }
    catch(const NodeUnreachableException&)
    {
    }
    catch(const DeploymentException&)
    {
    }

    if(target == 0)
    {
        throw ObjectNotExistException(__FILE__, __LINE__);
    }

    target = target->ice_facet(current.facet);

    invokeOnTarget(target, cb, inParams, current);
}
示例#7
0
ServerEntryPtr
ServerCache::remove(const string& id, bool noRestart)
{
    Lock sync(*this);

    ServerEntryPtr entry = getImpl(id);
    assert(entry);

    ServerInfo info = entry->getInfo();
    forEachCommunicator(RemoveCommunicator(*this, entry))(info.descriptor);

    _nodeCache.get(info.node)->removeServer(entry);

    entry->destroy(noRestart); // This must be done after otherwise some allocatable objects
                               // might allocate a destroyed server.

    if(_traceLevels && _traceLevels->server > 0)
    {
        Ice::Trace out(_traceLevels->logger, _traceLevels->serverCat);
        out << "removed server `" << id << "'";
    }

    return entry;
}
示例#8
0
void
ServerCache::addCommunicator(const CommunicatorDescriptorPtr& oldDesc,
                             const CommunicatorDescriptorPtr& newDesc,
                             const ServerEntryPtr& server,
                             const string& application)
{
    if(!newDesc)
    {
        return; // Nothing to add
    }
    for(AdapterDescriptorSeq::const_iterator q = newDesc->adapters.begin() ; q != newDesc->adapters.end(); ++q)
    {
        AdapterDescriptor oldAdpt;
        if(oldDesc)
        {
            for(AdapterDescriptorSeq::const_iterator p = oldDesc->adapters.begin() ; p != oldDesc->adapters.end(); ++p)
            {
                if(p->id == q->id)
                {
                    oldAdpt = *p;
                    break;
                }
            }
        }
        assert(!q->id.empty());
        _adapterCache.addServerAdapter(*q, server, application);

        for(ObjectDescriptorSeq::const_iterator r = q->objects.begin(); r != q->objects.end(); ++r)
        {
            _objectCache.add(toObjectInfo(_communicator, *r, q->id), application, server->getId());
        }
        for(ObjectDescriptorSeq::const_iterator r = q->allocatables.begin(); r != q->allocatables.end(); ++r)
        {
            ObjectDescriptorSeq::const_iterator s;
            for(s = oldAdpt.allocatables.begin(); s != oldAdpt.allocatables.end() && s->id != r->id; ++s);
            if(s == oldAdpt.allocatables.end() || *s != *r) // Only add new or updated allocatables
            {
                _allocatableObjectCache.add(toObjectInfo(_communicator, *r, q->id), server);
            }
        }
    }
}
示例#9
0
void
NodeEntry::removeServer(const ServerEntryPtr& entry)
{
    Lock sync(*this);
    _servers.erase(entry->getId());
}
示例#10
0
void
NodeEntry::addServer(const ServerEntryPtr& entry)
{
    Lock sync(*this);
    _servers.insert(make_pair(entry->getId(), entry));
}
示例#11
0
 DestroyCB(const TraceLevelsPtr& traceLevels, const ServerEntryPtr& server, const string& node) : 
     _traceLevels(traceLevels), _server(server), _id(server->getId()), _node(node)
 {
 }
示例#12
0
 LoadCB(const TraceLevelsPtr& traceLevels, const ServerEntryPtr& server, const string& node, int timeout) : 
     _traceLevels(traceLevels), _server(server), _id(server->getId()), _node(node), _timeout(timeout)
 {
 }
示例#13
0
bool GatewayServer::start_server()
{
	new LoginSessionManager();
	new GatewayTaskManager();
	new SceneClientManager();

	notify_login_server();

	//as client
	recordclient_.reset(new connection(pool_.get_io_service(),"recordclient"));
	recordclient_->set_msg_handler(std::bind(&GatewayServer::on_msg, this, std::placeholders::_1));
	recordclient_->set_error_handler(std::bind(&GatewayServer::handle_stop, this));			//TODO: change another handler
	ServerEntryPtr recordEntry = serverlist_.getEntryByType(RECORDSERVER);
	if (!recordEntry)
	{
		LOG(ERROR)<<("can't find record entry");
		return false;
	}
	if (!recordclient_->connect(recordEntry->ip(), recordEntry->port()))
	{
		LOG(ERROR)<<("can't find record entry");
		return false;
	}
	else
	{
		Record::t_LoginRecord send;
		send.set_id(myentry_->id());
		send.set_type(myentry_->type());
		codec_.send(recordclient_, &send);
	}
			
	//as client
	sessionclient_.reset(new connection(pool_.get_io_service(), "sessionclient"));
	sessionclient_->set_msg_handler(std::bind(&GatewayServer::on_msg, this, std::placeholders::_1));
	sessionclient_->set_error_handler(std::bind(&GatewayServer::handle_stop, this));			//TODO: change another handler
	ServerEntryPtr sessionEntry = serverlist_.getEntryByType(SESSIONSERVER);
	if (!sessionEntry)
	{
		LOG(INFO)<<("can't find session entry");
		return false;
	}
	if (!sessionclient_->connect(sessionEntry->ip(), sessionEntry->port()))
	{
		LOG(INFO)<<("connect session error");
		return false;
	}
	else
	{
		Session::t_LoginSession send;
		send.set_id(myentry_->id());
		send.set_type(myentry_->type());
		codec_.send(sessionclient_, &send);
	}

	//as client
	std::vector<ServerEntryPtr> scenesentry = serverlist_.getEntrysByType(SCENESERVER);
	if (scenesentry.empty())
	{
		LOG(INFO)<<("can't find scene entry");
		return false;
	}
	else
	{
		LOG(INFO)<<"scene entry num="<<scenesentry.size();
	}

	SceneClientManager::instance().init(scenesentry);

	started_ = true;

	one_second_timer_.expires_from_now(boost::posix_time::seconds(1));
	one_second_timer_.async_wait(boost::bind(&GatewayServer::one_second_callback, this, _1));

	return true;
}