Optimize replication messages.

This commit is contained in:
Gunnar Beutner 2013-04-05 14:05:00 +02:00
parent d9730f5b83
commit 1682ff2839
4 changed files with 19 additions and 16 deletions

View File

@ -181,6 +181,10 @@ void ReplicationComponent::FlushObjectHandler(double tx, const DynamicObject::Pt
if (!ShouldReplicateObject(object))
return;
/* Don't replicate objects that haven't had any local updates. */
if (object->GetLocalTx() < tx)
return;
RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", tx, true);
EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
}

View File

@ -49,7 +49,7 @@ boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)>
boost::signals2::signal<void (double, const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
: m_ConfigTx(0), m_Registered(false)
: m_ConfigTx(0), m_LocalTx(0), m_Registered(false)
{
RegisterAttribute("__name", Attribute_Config, &m_Name);
RegisterAttribute("__type", Attribute_Config, &m_Type);
@ -241,7 +241,9 @@ void DynamicObject::Touch(const String& name)
if (it == m_Attributes.end())
BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name));
it->second.SetTx(GetCurrentTx());
double tx = GetCurrentTx();
it->second.SetTx(tx);
m_LocalTx = tx;
m_ModifiedAttributes.insert(name);
@ -251,6 +253,12 @@ void DynamicObject::Touch(const String& name)
}
}
double DynamicObject::GetLocalTx(void) const
{
boost::mutex::scoped_lock lock(m_AttributeMutex);
return m_LocalTx;
}
Value DynamicObject::Get(const String& name) const
{
ASSERT(!OwnsLock());

View File

@ -90,6 +90,8 @@ public:
virtual void Start(void);
virtual void Stop(void);
double GetLocalTx(void) const;
const AttributeMap& GetAttributes(void) const;
static DynamicObject::Ptr GetObject(const String& type, const String& name);
@ -117,6 +119,7 @@ private:
AttributeMap m_Attributes;
std::set<String, string_iless> m_ModifiedAttributes;
double m_ConfigTx;
double m_LocalTx;
Attribute<String> m_Name;
Attribute<String> m_Type;

View File

@ -65,26 +65,14 @@ void FIFO::ResizeBuffer(size_t newSize)
*/
void FIFO::Optimize(void)
{
//char *newBuffer;
if (m_DataSize < m_Offset) {
memcpy(m_Buffer, m_Buffer + m_Offset, m_DataSize);
m_Offset = 0;
ResizeBuffer(m_DataSize);
return;
}
/*newBuffer = (char *)ResizeBuffer(NULL, 0, m_BufferSize - m_Offset);
if (newBuffer == NULL)
return;
memcpy(newBuffer, m_Buffer + m_Offset, m_BufferSize - m_Offset);
free(m_Buffer);
m_Buffer = newBuffer;
m_BufferSize -= m_Offset;
m_Offset = 0;*/
}
/**