Sirikata
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
Sirikata::Network::IOStrand Class Reference

IOStrands provide guaranteed serialized event handling. More...

#include <IOStrand.hpp>

Inheritance diagram for Sirikata::Network::IOStrand:
Collaboration diagram for Sirikata::Network::IOStrand:

List of all members.

Classes

class  WrappedHandler

Public Types

typedef
std::tr1::unordered_map< const
char *, uint32 > 
TagCountMap

Public Member Functions

 ~IOStrand ()
 Destroy the strand.
const String & name () const
 Get the name of this IOStrand.
IOServiceservice () const
 Get an IOService associated with this strand.
void dispatch (const IOCallback &handler, const char *tag=NULL)
 Request that the given handler be invoked, possibly before returning, on this strand.
void post (const IOCallback &handler, const char *tag=NULL)
 Request that the given handler be appended to the event queue and invoked on this strand at a later time.
void post (const Duration &waitFor, const IOCallback &handler, const char *tag=NULL)
 Request that the given handler be appended to the event queue and invoked on this strand at a later time.
IOCallback wrap (const IOCallback &handler)
 Wrap the given handler so that it will be handled in this strand.
template<typename CallbackType >
WrappedHandler< CallbackType > wrap (const CallbackType &handler)
 Wrap the given handler so that it will be handled in this strand.

Private Member Functions

 IOStrand (IOService &io, const String &name)
 Construct an IOStrand associated with the given IOService.

Private Attributes

IOServicemService
InternalIOStrandmImpl
const String mName

Friends

class IOService
class StrandTCPSocket

Detailed Description

IOStrands provide guaranteed serialized event handling.

Strands allow you to wrap events so that they may be dispatched to any currently running IOService (in thread), but guarantees that no two event handlers in the same strand will be executed concurrently. This is a a useful synchronization primitive, allow user code to avoid having to use locks explicitly and allowing the IOService to make the best use of available threads instead of locking operations to specific threads, causing unnecessary thread switching overhead.

Note that strands are never directly allocated -- instead, they are acquired from an existing IOService.


Member Typedef Documentation

typedef std::tr1::unordered_map<const char*, uint32> Sirikata::Network::IOStrand::TagCountMap

Constructor & Destructor Documentation

Sirikata::Network::IOStrand::IOStrand ( IOService io,
const String &  name 
) [private]

Construct an IOStrand associated with the given IOService.

References mImpl.

Sirikata::Network::IOStrand::~IOStrand ( )

Destroy the strand.

Outstanding events on the strand will be handled safely, i.e. non-concurrently.

References mImpl, and mService.


Member Function Documentation

void Sirikata::Network::IOStrand::dispatch ( const IOCallback handler,
const char *  tag = NULL 
)

Request that the given handler be invoked, possibly before returning, on this strand.

Parameters:
handlerthe handler callback to be called
taga string descriptor of the handler for debugging

References mImpl, mService, and Sirikata::Timer::now().

const String& Sirikata::Network::IOStrand::name ( ) const [inline]

Get the name of this IOStrand.

Not necessarily unique, but ideally it will be.

void Sirikata::Network::IOStrand::post ( const IOCallback handler,
const char *  tag = NULL 
)

Request that the given handler be appended to the event queue and invoked on this strand at a later time.

The handler is guaranteed not to be invoked will not be invoked during this method call.

Parameters:
handlerthe handler callback to be called
taga string descriptor of the handler for debugging

References mImpl, mService, and Sirikata::Timer::now().

Referenced by Sirikata::AggregateManager::addChild(), Sirikata::LibproxProximityBase::aggregateBoundsUpdated(), Sirikata::LibproxProximityBase::aggregateChildAdded(), Sirikata::LibproxProximityBase::aggregateChildRemoved(), Sirikata::LibproxProximityBase::aggregateCreated(), Sirikata::LibproxProximityBase::aggregateDestroyed(), Sirikata::NullAuthenticator::authenticate(), Sirikata::CBRLocationServiceCache::boundsUpdated(), Sirikata::LibproxProximityBase::checkObjectClass(), Sirikata::AsyncConnectionSet::connect_handler(), Sirikata::AsyncConnectionGet::connect_handler(), Sirikata::SQLiteObjectFactory::connectObjects(), Sirikata::CSVObjectFactory::connectObjects(), Sirikata::CassandraObjectFactory::connectObjects(), Sirikata::JS::EmersonScript::create_entity(), Sirikata::Graphics::WebView::defaultEvent(), Sirikata::LibproxManualProximity::destroyQuery(), Sirikata::OH::CassandraStorage::executeCommit(), Sirikata::OH::SQLiteStorage::executeCount(), Sirikata::OH::CassandraStorage::executeCount(), Sirikata::JS::JSObjectScriptManager::finishMeshDownload(), Sirikata::AggregateManager::generateAggregateMesh(), Sirikata::AggregateManager::generateAggregateMeshAsync(), Sirikata::AggregateManager::generateMeshesFromQueue(), Sirikata::LibproxProximity::generateObjectQueryEvents(), Sirikata::OH::Manual::ObjectQueryHandler::generateObjectQueryEvents(), Sirikata::LibproxProximity::generateServerQueryEvents(), Sirikata::AsyncCraqHybrid::get(), Sirikata::BulletPhysicsService::getMeshCallback(), Sirikata::HostedObject::handleConnected(), Sirikata::HostedObject::handleConnectedIndirect(), Sirikata::ObjectHostConnectionManager::handleConnectionEvent(), Sirikata::LocationService::handleLocationUpdateSubstreamRead(), Sirikata::CraqObjectSegmentation::handleMigrateMessageAck(), Sirikata::ObjectHostConnectionManager::handleNewConnection(), Sirikata::LibproxProximity::handleRemoveObjectQuery(), Sirikata::OH::Manual::ObjectQueryHandler::handleRemoveObjectQuery(), Sirikata::LibproxProximity::handleRemoveServerQuery(), Sirikata::CraqObjectSegmentation::handleUpdateOSegMessage(), Sirikata::LibproxManualProximity::handleUpdateServerQueryResultsToLocService(), Sirikata::LibproxManualProximity::handleUpdateServerQueryResultsToReplicatedTrees(), Sirikata::AggregateManager::handleUploadFinished(), Sirikata::ObjectHost::hostedObjectDestroyed(), Sirikata::AsyncCraqHybrid::initialize(), Sirikata::AggregateManager::iRemoveChild(), Sirikata::AsyncConnectionSet::killSequence(), Sirikata::AsyncConnectionGet::killSequence(), Sirikata::JS::JSPositionListener::loadMesh(), Sirikata::JS::JSObjectScriptManager::loadMesh(), Sirikata::MigrationMonitor::localLocationUpdated(), Sirikata::MigrationMonitor::localObjectAdded(), Sirikata::MigrationMonitor::localObjectRemoved(), Sirikata::LibproxProximity::localObjectRemoved(), Sirikata::LibproxManualProximity::localObjectRemoved(), Sirikata::CBRLocationServiceCache::locationUpdated(), Sirikata::CraqObjectSegmentation::lookup(), Sirikata::CBRLocationServiceCache::meshUpdated(), Sirikata::HostedObject::metadataDownloaded(), Sirikata::FairServerMessageReceiver::networkReceivedData(), Sirikata::CBRLocationServiceCache::objectAdded(), Sirikata::CBRLocationServiceCache::objectRemoved(), Sirikata::OH::Manual::ObjectQueryHandler::onBoundsUpdated(), Sirikata::MasterPintoServerQuerier::onConnected(), Sirikata::OH::Manual::ObjectQueryHandler::onEpochUpdated(), Sirikata::OH::Manual::ObjectQueryHandler::onLocationUpdated(), Sirikata::OH::Manual::ObjectQueryHandler::onMeshUpdated(), Sirikata::Server::onObjectHostDisconnected(), Sirikata::Server::onObjectHostMessageReceived(), Sirikata::LibproxManualProximity::onObjectHostSessionEnded(), Sirikata::OH::Manual::ObjectQueryHandler::onOrientationUpdated(), Sirikata::OH::Manual::ObjectQueryHandler::onPhysicsUpdated(), Sirikata::LibproxManualProximity::onPintoServerLocUpdate(), Sirikata::LibproxManualProximity::onPintoServerResult(), Sirikata::LibproxProximityBase::onSpaceNetworkConnected(), Sirikata::LibproxProximityBase::onSpaceNetworkDisconnected(), Sirikata::SessionManager::openConnectionStartMigration(), Sirikata::SessionManager::openConnectionStartSession(), Sirikata::CBRLocationServiceCache::orientationUpdated(), Sirikata::Server::osegAddNewFinished(), Sirikata::OSegLookupQueue::osegLookupCompleted(), Sirikata::Server::osegMigrationAcknowledged(), Sirikata::JS::JSObjectScriptManager::parseMeshWork(), Sirikata::OH::CassandraPersistedObjectSet::performUpdate(), Sirikata::OH::SQLitePersistedObjectSet::performUpdateWithRetry(), Sirikata::CBRLocationServiceCache::physicsUpdated(), Sirikata::TCPSpaceNetwork::RemoteStream::pop(), Sirikata::AsyncConnectionSet::processStoredValue(), Sirikata::AsyncConnectionGet::processStoredValue(), Sirikata::OH::SQLiteStorage::processTransactions(), Sirikata::AsyncConnectionGet::processValueFound(), Sirikata::AsyncConnectionGet::processValueNotFound(), Sirikata::LibproxManualProximity::queryHasEvents(), Sirikata::AsyncConnectionGet::queryTimedOutCallbackGet(), Sirikata::AsyncConnectionSet::queryTimedOutCallbackSet(), Sirikata::AggregateManager::queueDirtyAggregates(), Sirikata::LibproxProximity::removeQuery(), Sirikata::AggregateManager::removeStaleLeaves(), Sirikata::LibproxProximity::replicaObjectRemoved(), Sirikata::LibproxManualProximity::replicaObjectRemoved(), Sirikata::LibproxProximityBase::ProxStreamInfo< EndpointType, StreamType >::requestProxSubstream(), Sirikata::SQLiteAuthenticator::respond(), Sirikata::JS::EmersonScript::restorePresence(), Sirikata::Forwarder::routeObjectMessageToServer(), Sirikata::SessionManager::scheduleHandleServerMessages(), Sirikata::Server::scheduleObjectHostMessageRouting(), Sirikata::Forwarder::scheduleProcessReceivedServerMessages(), Sirikata::FairServerMessageQueue::scheduleServicing(), Sirikata::SessionManager::sendRetryingMessage(), Sirikata::Server::sendSessionMessageWithRetry(), Sirikata::LibproxProximity::sessionClosed(), Sirikata::AsyncCraqHybrid::set(), Sirikata::Graphics::WebView::setReadyCallback(), Sirikata::JS::JSObjectScript::setRestoreScript(), Sirikata::Poller::setupNextTimeout(), Sirikata::ObjectHostConnectionManager::shutdown(), Sirikata::LocalPintoServerQuerier::start(), Sirikata::Poller::start(), Sirikata::AsyncConnectionSet::stop(), Sirikata::AsyncConnectionGet::stop(), Sirikata::OH::Simple::SimpleObjectQueryProcessor::stop(), Sirikata::JS::JSObjectScript::storageBeginTransaction(), Sirikata::JS::JSObjectScript::storageCommit(), Sirikata::JS::JSObjectScript::storageCount(), Sirikata::JS::JSObjectScript::storageErase(), Sirikata::JS::JSObjectScript::storageRangeErase(), Sirikata::JS::JSObjectScript::storageRangeRead(), Sirikata::JS::JSObjectScript::storageRead(), Sirikata::JS::JSObjectScript::storageWrite(), Sirikata::ServerMessageQueue::trySend(), Sirikata::ObjectSegmentation::trySendMigAcks(), Sirikata::Server::trySendMigrationMessages(), Sirikata::MigrationMonitor::updatedSegmentation(), Sirikata::MasterPintoServerQuerierBase::updateLargestObject(), Sirikata::LocalPintoServerQuerier::updateLargestObject(), Sirikata::LibproxProximity::updateQuery(), Sirikata::MasterPintoServerQuerier::updateQuery(), Sirikata::MasterPintoManualServerQuerier::updateQuery(), Sirikata::ServerMessageQueue::updateReceiverStats(), Sirikata::MasterPintoServerQuerierBase::updateRegion(), Sirikata::LocalPintoServerQuerier::updateRegion(), Sirikata::ServerMessageReceiver::updateSenderStats(), Sirikata::LibproxManualProximity::updateServerQuery(), Sirikata::LibproxManualProximity::updateServerQueryResults(), Sirikata::AggregateManager::uploadAggregateMesh(), Sirikata::AsyncConnectionGet::write_some_handler_get(), Sirikata::JS::EmersonMessagingManager::writeData(), Sirikata::LibproxProximityBase::ProxStreamInfo< EndpointType, StreamType >::writeSomeObjectResults(), and Sirikata::OH::Manual::ServerQueryHandler::writeSomeProxData().

void Sirikata::Network::IOStrand::post ( const Duration waitFor,
const IOCallback handler,
const char *  tag = NULL 
)

Request that the given handler be appended to the event queue and invoked on this strand at a later time.

Regardless of the wait duration requested, the handler is guaranteed not to be invoked during this method call.

Parameters:
waitForthe length of time to wait before invoking the handler
handlerthe handler callback to be called
taga string descriptor of the handler for debugging

References mImpl, mService, Sirikata::Timer::now(), and Sirikata::Network::IOService::post().

IOService & Sirikata::Network::IOStrand::service ( ) const

Get an IOService associated with this strand.

References mService.

Referenced by Sirikata::Network::ASIOSocketWrapper::createSocket().

template<typename CallbackType >
IOStrand::WrappedHandler< CallbackType > Sirikata::Network::IOStrand::wrap ( const CallbackType &  handler)

Wrap the given handler so that it will be handled in this strand.

Parameters:
handlerthe handler which should be wrapped
Returns:
a new handler which will cause the original handler to be invoked in this strand

References mImpl.

IOCallback Sirikata::Network::IOStrand::wrap ( const IOCallback handler)

Wrap the given handler so that it will be handled in this strand.

Parameters:
handlerthe handler which should be wrapped
Returns:
a new handler which will cause the original handler to be invoked in this strand

References mImpl.

Referenced by Sirikata::Network::ASIOSocketWrapper::bindFunctions(), Sirikata::Network::ASIOReadBuffer::bindFunctions(), Sirikata::SpaceNodeConnection::connect(), Sirikata::CoordinateSegmentationClient::CoordinateSegmentationClient(), Sirikata::DistributedCoordinateSegmentation::createSocketContainers(), Sirikata::DistributedCoordinateSegmentation::DistributedCoordinateSegmentation(), Sirikata::AsyncConnection::get(), Sirikata::AsyncConnectionGet::get(), Sirikata::SessionManager::getAnySpaceConnection(), Sirikata::BulletPhysicsService::getMesh(), Sirikata::LibproxManualProximity::handleObjectHostSubstream(), Sirikata::AsyncConnectionSet::initialize(), Sirikata::AsyncConnectionGet::initialize(), Sirikata::TCPSpaceNetwork::listen(), Sirikata::LocationService::LocationService(), Sirikata::ObjectHost::ObjectHost(), Sirikata::TCPSpaceNetwork::openConnection(), Sirikata::Poller::Poller(), Sirikata::LibproxProximityBase::ProxStreamInfo< EndpointType, StreamType >::proxSubstreamCallback(), Sirikata::SessionManager::registerSpaceNodeConnection(), Sirikata::LibproxProximityBase::ProxStreamInfo< EndpointType, StreamType >::requestProxSubstream(), Sirikata::Server::Server(), Sirikata::AsyncConnection::set(), Sirikata::AsyncConnectionSet::set(), Sirikata::AsyncConnectionSet::set_generic_stored_not_found_error_handler(), Sirikata::AsyncConnectionGet::set_generic_stored_not_found_error_handler(), Sirikata::SessionManager::setupSpaceConnection(), Sirikata::Context::start(), and Sirikata::Network::IOTimer::wait().


Friends And Related Function Documentation

friend class IOService [friend]
friend class StrandTCPSocket [friend]

Member Data Documentation

Referenced by dispatch(), IOStrand(), post(), wrap(), and ~IOStrand().

const String Sirikata::Network::IOStrand::mName [private]

Referenced by dispatch(), post(), service(), and ~IOStrand().


The documentation for this class was generated from the following files: