bool AlwaysLocationUpdatePolicy::trySend(const UUID& dest, const Sirikata::Protocol::Loc::BulkLocationUpdate& blu) { std::string bluMsg = serializePBJMessage(blu); SSTStreamPtr locServiceStream = mLocService->getObjectStream(dest); bool sent = false; if (locServiceStream) { Sirikata::Protocol::Frame msg_frame; msg_frame.set_payload(bluMsg); std::string* framed_loc_msg = new std::string(serializePBJMessage(msg_frame)); tryCreateChildStream(locServiceStream, framed_loc_msg, 0); sent = true; } return sent; }
bool AlwaysLocationUpdatePolicy::trySend(const ServerID& dest, const Sirikata::Protocol::Loc::BulkLocationUpdate& blu) { Message* msg = new Message( mLocService->context()->id(), SERVER_PORT_LOCATION, dest, SERVER_PORT_LOCATION, serializePBJMessage(blu) ); return mLocMessageRouter->route(msg); }
void TimeSyncServer::handleMessage(const OHDP::Endpoint& src, const OHDP::Endpoint& dst, MemoryReference payload) { SILOG(timesync, detailed, "Received time sync message from remote node " << src.node()); Sirikata::Protocol::TimeSync sync_msg; bool parse_success = sync_msg.ParseFromArray(payload.data(), payload.size()); if (!parse_success) { LOG_INVALID_MESSAGE_BUFFER(sync, error, ((char*)payload.data()), payload.size()); return; } // Our only job is to take the existing message, fill in a timestamp, and // send it back. sync_msg.set_t(mContext->simTime()); String resp = serializePBJMessage(sync_msg); mPort->send(src, MemoryReference(resp)); SILOG(timesync, detailed, "Sent time sync message reply to remote node " << src.node()); }
void LoadMonitor::sendLoadReadings() { //send mCurrentLoadReading to other servers uint32 total_servers = mCoordinateSegmentation->numServers(); Sirikata::Protocol::CSeg::LoadMessage load_msg; load_msg.set_load(mAveragedLoadReading); std::string serialized_load = serializePBJMessage(load_msg); for (uint32 i=1 ; i <= total_servers; i++) { if (i != mContext->id() && handlesAdjacentRegion(i) ) { printf("%d handles adjacent region with %d\n", i, mContext->id()); Message* msg = new Message( mContext->id(), SERVER_PORT_LOAD_STATUS, (ServerID)i, SERVER_PORT_LOAD_STATUS, serialized_load ); bool send_success = mLoadServerMessageService->route(msg); // Ignore send success, lost load readings don't matter } } }
void HostedObject::sendLocUpdateRequest(const SpaceID& space, const ObjectReference& oref) { // Up here to avoid recursive lock ProxyObjectPtr self_proxy = getProxy(space, oref); Mutex::scoped_lock locker(presenceDataMutex); assert(mPresenceData.find(SpaceObjectReference(space, oref)) != mPresenceData.end()); PerPresenceData& pd = *(mPresenceData.find(SpaceObjectReference(space, oref)))->second; if (!self_proxy) { HO_LOG(warn,"Requesting sendLocUpdateRequest for missing self proxy. Doing nothing."); return; } assert(pd.updateFields != PerPresenceData::LOC_FIELD_NONE); // Generate and send an update to Loc Protocol::Loc::Container container; Protocol::Loc::ILocationUpdateRequest loc_request = container.mutable_update_request(); uint64 epoch = pd.requestEpoch++; loc_request.set_epoch(epoch); if (pd.updateFields & PerPresenceData::LOC_FIELD_LOC) { Protocol::ITimedMotionVector requested_loc = loc_request.mutable_location(); requested_loc.set_t( spaceTime(space, pd.requestLoc->location().updateTime()) ); requested_loc.set_position(pd.requestLoc->location().position()); requested_loc.set_velocity(pd.requestLoc->location().velocity()); // Save value but bump the epoch pd.requestLoc->setLocation(pd.requestLoc->location(), epoch); } if (pd.updateFields & PerPresenceData::LOC_FIELD_ORIENTATION) { Protocol::ITimedMotionQuaternion requested_orient = loc_request.mutable_orientation(); requested_orient.set_t( spaceTime(space, pd.requestLoc->orientation().updateTime()) ); //Normalize positions, which only make sense as unit quaternions. requested_orient.set_position(pd.requestLoc->orientation().position().normal()); requested_orient.set_velocity(pd.requestLoc->orientation().velocity()); // Save value but bump the epoch pd.requestLoc->setOrientation(pd.requestLoc->orientation(), epoch); } if (pd.updateFields & PerPresenceData::LOC_FIELD_BOUNDS) { loc_request.set_bounds(pd.requestLoc->bounds()); // Save value but bump the epoch pd.requestLoc->setBounds(pd.requestLoc->bounds(), epoch); } if (pd.updateFields & PerPresenceData::LOC_FIELD_MESH) { loc_request.set_mesh(pd.requestLoc->mesh().toString()); // Save value but bump the epoch pd.requestLoc->setMesh(pd.requestLoc->mesh(), epoch); } if (pd.updateFields & PerPresenceData::LOC_FIELD_PHYSICS) { loc_request.set_physics(pd.requestLoc->physics()); // Save value but bump the epoch pd.requestLoc->setPhysics(pd.requestLoc->physics(), epoch); } std::string payload = serializePBJMessage(container); bool send_succeeded = false; SSTStreamPtr spaceStream = mObjectHost->getSpaceStream(space, oref); if (spaceStream) { spaceStream->createChildStream( std::tr1::bind(discardChildStream, _1, _2), (void*)payload.data(), payload.size(), OBJECT_PORT_LOCATION, OBJECT_PORT_LOCATION ); send_succeeded = true; } if (send_succeeded) { pd.updateFields = PerPresenceData::LOC_FIELD_NONE; } else { // Set up retry timer. Just rerun this method, but add no new // update fields. pd.rerequestTimer->wait( Duration::milliseconds((int64)10), std::tr1::bind(&HostedObject::sendLocUpdateRequest, this, space, oref) ); } }
std::string* serialize() const { return new std::string( serializePBJMessage(*this) ); };