本文整理汇总了C++中ice::ConnectionPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionPtr类的具体用法?C++ ConnectionPtr怎么用?C++ ConnectionPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectionPtr类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: close
//
// Disconnect from the remote peer.
//
virtual void close()
{
Talk::PeerPrx peer;
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_lock);
if(!_connected)
{
cout << ">>>> Not connected!" << endl;
return;
}
_connected = false;
peer = _peer;
_peer = 0;
}
//
// Try to notify the remote peer that we are disconnecting.
//
try
{
peer->disconnect();
Ice::ConnectionPtr con = peer->ice_getCachedConnection();
if(con)
{
con->close(false);
}
}
catch(const Ice::Exception& ex)
{
cout << ">>>> Error: " << ex << endl;
}
}
示例2: sync
void
ReapThread::add(const ReapablePtr& reapable, int timeout, const Ice::ConnectionPtr& connection)
{
Lock sync(*this);
if(_terminated)
{
return;
}
//
// NOTE: registering a reapable with a null timeout is allowed. The reapable is reaped
// only when the reaper thread is shutdown.
//
//
// 10 seconds is the minimum permissable timeout.
//
if(timeout > 0 && timeout < 10)
{
timeout = 10;
}
ReapableItem item;
item.item = reapable;
item.connection = connection;
item.timeout = timeout == 0 ? IceUtil::Time() : IceUtil::Time::seconds(timeout);
_sessions.push_back(item);
if(connection)
{
map<Ice::ConnectionPtr, set<ReapablePtr> >::iterator p = _connections.find(connection);
if(p == _connections.end())
{
p = _connections.insert(make_pair(connection, set<ReapablePtr>())).first;
connection->setCloseCallback(_closeCallback);
connection->setHeartbeatCallback(_heartbeatCallback);
}
p->second.insert(reapable);
}
if(timeout > 0)
{
//
// If there is a new minimum wake interval then wake the reaping
// thread.
//
if(calcWakeInterval())
{
notify();
}
//
// Since we just added a new session with a non null timeout there
// must be a non-zero wakeInterval.
//
assert(_wakeInterval != IceUtil::Time());
}
}
示例3: getConnection
void
BlobjectI::ice_invoke_async(const Ice::AMD_Object_ice_invokePtr& amdCb, const vector<Ice::Byte>& inEncaps,
const Ice::Current& current)
{
Ice::ConnectionPtr connection = getConnection(current);
const bool twoway = current.requestId > 0;
Ice::ObjectPrx obj = connection->createProxy(current.id);
if(!twoway)
{
if(_startBatch)
{
_startBatch = false;
_batchProxy = obj->ice_batchOneway();
}
if(_batchProxy)
{
obj = _batchProxy;
}
if(!current.facet.empty())
{
obj = obj->ice_facet(current.facet);
}
if(_batchProxy)
{
vector<Ice::Byte> out;
obj->ice_invoke(current.operation, current.mode, inEncaps, out, current.ctx);
amdCb->ice_response(true, vector<Ice::Byte>());
}
else
{
CallbackPtr cb = new Callback(amdCb, false);
Ice::Callback_Object_ice_invokePtr del =
Ice::newCallback_Object_ice_invoke(cb, &Callback::response, &Callback::exception, &Callback::sent);
obj->ice_oneway()->begin_ice_invoke(current.operation, current.mode, inEncaps, current.ctx, del);
}
}
else
{
if(!current.facet.empty())
{
obj = obj->ice_facet(current.facet);
}
CallbackPtr cb = new Callback(amdCb, true);
Ice::Callback_Object_ice_invokePtr del =
Ice::newCallback_Object_ice_invoke(cb, &Callback::response, &Callback::exception, &Callback::sent);
obj->begin_ice_invoke(current.operation, current.mode, inEncaps, current.ctx, del);
}
}
示例4: update
void SearchLogicManagerI::update(const UpdateUnitSeq& updateUnits, const Ice::Current& ic) {
const Ice::ConnectionPtr con = ic.con;
if (con.get() != NULL) {
MCE_DEBUG("SearchLogicManagerI::update" << updateUnits.size() << " objects. invoker is :" << con->toString() << ", facet=" << ic.facet << ", operation=" << ic.operation << ", requestId=" << ic.requestId << ", id.name=" << ic.id.name << ", id.category=" << ic.id.category << ", adapter.name=" << ic.adapter->getName());
}
if (updateUnits.empty())
return;
for(UpdateUnitSeq::const_iterator iter=updateUnits.begin(); iter!=updateUnits.end(); ++iter) {
int user_id = iter->id;
if (user_id >= 0) {
(_vecMessageQueueThread.at(user_id % kMessageQueueThreadNum))->invoke(*iter);
}
}
}
示例5: getSearchCacheList
Int2SearchCacheResultMap SearchCacheManagerI::getSearchCacheList(const ::MyUtil::IntSeq& userIds, const Ice::Current& ic) {
struct timeval tvStart;
struct timeval tvStart1;
struct timeval tvEnd;
MyUtil::LongSeq uids;
gettimeofday(&tvStart, NULL);
Int2SearchCacheResultMap result;
for (MyUtil::IntSeq::const_iterator it = userIds.begin(); it!= userIds.end(); ++it) {
BinStringPtr binStrPtr = ObjectCacheHelper::instance().findObject<BinStringPtr> (*it);
if (binStrPtr.get() != NULL) {
SearchMemCacheDataPtr pSCData = new SearchMemCacheData();
char* pBuf = NULL;
int len = 0;
binStrPtr->getBuf(&pBuf, &len);
if (pBuf==NULL || len <= 0) continue;
if (pSCData->Unserialize(pBuf, len)) {
result[*it] = pSCData->getProperties();
}
} else {
//scq
if (*it != 0) {
uids.push_back(*it);
}
}
}
gettimeofday(&tvStart1, NULL);
if (!uids.empty())
_invokeLoad.invoke(uids);
gettimeofday(&tvEnd, NULL);
int start = tvStart.tv_sec*1000000 + tvStart.tv_usec;
int start1 = tvStart1.tv_sec*1000000 + tvStart1.tv_usec;
int end = tvEnd.tv_sec*1000000 + tvEnd.tv_usec;
if ((end - start) > 5000) {
const Ice::ConnectionPtr con = ic.con;
if (con.get() != NULL) {
MCE_INFO(con->toString() << " Get SearchCache List: time=" << end-start << "us " <<
"invokeLoad: time=" << end - start1 << "us total=" << userIds.size());
}
}
return result;
}
示例6: SessionNotExistException
void
SessionRouterI::refreshSession(const Ice::ConnectionPtr& con)
{
RouterIPtr router;
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
router = getRouterImpl(con, Ice::Identity(), false); // getRouter updates the session timestamp.
if(!router)
{
//
// Close the connection otherwise the peer has no way to know that the
// session has gone.
//
con->close(ICE_SCOPED_ENUM(ConnectionClose, Forcefully));
throw SessionNotExistException();
}
}
SessionPrx session = router->getSession();
if(session)
{
//
// Ping the session to ensure it does not timeout.
//
session->begin_ice_ping(Ice::newCallback(new ACMPingCallback(this, con), &ACMPingCallback::finished));
}
}
示例7: seq
//.........这里部分代码省略.........
cb->check();
}
cout << "ok" << endl;
cout << "testing AMI write timeout... " << flush;
{
//
// Expect TimeoutException.
//
TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(500));
to->holdAdapter(2000);
ByteSeq seq(100000);
CallbackPtr cb = new Callback();
to->begin_sendData(seq, newCallback_Timeout_sendData(cb, &Callback::responseEx, &Callback::exceptionEx));
cb->check();
}
{
//
// Expect success.
//
timeout->op(); // Ensure adapter is active.
TimeoutPrx to = TimeoutPrx::uncheckedCast(obj->ice_timeout(1000));
to->holdAdapter(500);
ByteSeq seq(100000);
CallbackPtr cb = new Callback();
to->begin_sendData(seq, newCallback_Timeout_sendData(cb, &Callback::response, &Callback::exception));
cb->check();
}
cout << "ok" << endl;
cout << "testing close timeout... " << flush;
{
TimeoutPrx to = TimeoutPrx::checkedCast(obj->ice_timeout(250));
Ice::ConnectionPtr connection = to->ice_getConnection();
timeout->holdAdapter(750);
connection->close(false);
try
{
connection->getInfo(); // getInfo() doesn't throw in the closing state.
}
catch(const Ice::LocalException&)
{
test(false);
}
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(500));
try
{
connection->getInfo();
test(false);
}
catch(const Ice::CloseConnectionException&)
{
// Expected.
}
timeout->op(); // Ensure adapter is active.
}
cout << "ok" << endl;
cout << "testing timeout overrides... " << flush;
{
//
// Test Ice.Override.Timeout. This property overrides all
// endpoint timeouts.
//
Ice::InitializationData initData;
initData.properties = communicator->getProperties()->clone();
示例8: assert
void
SessionHelperI::connected(const Glacier2::RouterPrxPtr& router, const Glacier2::SessionPrxPtr& session)
{
//
// Remote invocation should be done without acquiring a mutex lock.
//
assert(router);
Ice::ConnectionPtr conn = router->ice_getCachedConnection();
string category = router->getCategoryForClient();
Ice::Int acmTimeout = 0;
try
{
acmTimeout = router->getACMTimeout();
}
catch(const Ice::OperationNotExistException&)
{
}
if(acmTimeout <= 0)
{
acmTimeout = static_cast<Ice::Int>(router->getSessionTimeout());
}
//
// We create the callback object adapter here because createObjectAdapter internally
// makes synchronous RPCs to the router. We can't create the OA on-demand when the
// client calls objectAdapter() or addWithUUID() because they can be called from the
// GUI thread.
//
if(_useCallbacks)
{
_adapter = _communicator->createObjectAdapterWithRouter("", router);
_adapter->activate();
}
bool destroy;
{
IceUtil::Mutex::Lock sync(_mutex);
_router = router;
destroy = _destroy;
if(!_destroy)
{
//
// Cache the category.
//
_category = category;
//
// Assign the session after _destroy is checked.
//
_session = session;
_connected = true;
if(acmTimeout > 0)
{
Ice::ConnectionPtr connection = _router->ice_getCachedConnection();
assert(connection);
connection->setACM(acmTimeout, IceUtil::None, Ice::HeartbeatAlways);
#ifdef ICE_CPP11_MAPPING
connection->setCloseCallback([self = shared_from_this()](Ice::ConnectionPtr)
{
self->destroy();
});
#else
connection->setCloseCallback(ICE_MAKE_SHARED(CloseCallbackI, shared_from_this()));
#endif
}
}
}
if(destroy)
{
//
// connected() is only called from the ConnectThread so it is ok to
// call destroyInternal here.
//
destroyInternal(new Disconnected(shared_from_this(), _callback));
}
else
{
dispatchCallback(new Connected(_callback, shared_from_this()), conn);
}
}
示例9: is
//.........这里部分代码省略.........
string endpoints = helper->getTestEndpoint() + ":" + helper->getTestEndpoint("udp") + " -c";
int port = helper->getTestPort();
Ice::ObjectPrxPtr base = communicator->stringToProxy("test:" + endpoints);
TestIntfPrxPtr testIntf = ICE_CHECKED_CAST(TestIntfPrx, base);
cout << "test connection endpoint information... " << flush;
{
Ice::EndpointInfoPtr info = base->ice_getConnection()->getEndpoint()->getInfo();
Ice::TCPEndpointInfoPtr tcpinfo = getTCPEndpointInfo(info);
test(tcpinfo->port == port);
test(!tcpinfo->compress);
test(tcpinfo->host == defaultHost);
ostringstream os;
Ice::Context ctx = testIntf->getEndpointInfoAsContext();
test(ctx["host"] == tcpinfo->host);
test(ctx["compress"] == "false");
istringstream is(ctx["port"]);
int portCtx;
is >> portCtx;
test(portCtx > 0);
info = base->ice_datagram()->ice_getConnection()->getEndpoint()->getInfo();
Ice::UDPEndpointInfoPtr udp = ICE_DYNAMIC_CAST(Ice::UDPEndpointInfo, info);
test(udp);
test(udp->port == portCtx);
test(udp->host == defaultHost);
}
cout << "ok" << endl;
cout << "testing connection information... " << flush;
{
Ice::ConnectionPtr connection = base->ice_getConnection();
connection->setBufferSize(1024, 2048);
Ice::TCPConnectionInfoPtr info = getTCPConnectionInfo(connection->getInfo());
test(info);
test(!info->incoming);
test(info->adapterName.empty());
test(info->localPort > 0);
test(info->remotePort == port);
if(defaultHost == "127.0.0.1")
{
test(info->remoteAddress == defaultHost);
test(info->localAddress == defaultHost);
}
#if !defined(ICE_OS_UWP)
test(info->rcvSize >= 1024);
test(info->sndSize >= 2048);
#endif
ostringstream os;
Ice::Context ctx = testIntf->getConnectionInfoAsContext();
test(ctx["incoming"] == "true");
test(ctx["adapterName"] == "TestAdapter");
test(ctx["remoteAddress"] == info->localAddress);
test(ctx["localAddress"] == info->remoteAddress);
os.str("");
os << info->localPort;
test(ctx["remotePort"] == os.str());
os.str("");
os << info->remotePort;
test(ctx["localPort"] == os.str());
示例10:
Ice::ObjectPrx
AdminSessionI::toProxy(const Ice::Identity& id, const Ice::ConnectionPtr& connection, const Ice::EncodingVersion& v)
{
return id.name.empty() ? Ice::ObjectPrx() : connection->createProxy(id)->ice_encodingVersion(v);
}
示例11: out
bool
Glacier2::Application::doMain(Ice::StringSeq& args, const Ice::InitializationData& initData, int& status)
{
//
// Reset internal state variables from Ice.Application. The
// remainder are reset at the end of this method.
//
IceInternal::Application::_callbackInProgress = false;
IceInternal::Application::_destroyed = false;
IceInternal::Application::_interrupted = false;
bool restart = false;
status = 0;
try
{
IceInternal::Application::_communicator = Ice::initialize(args, initData);
_router = Glacier2::RouterPrx::uncheckedCast(communicator()->getDefaultRouter());
if(!_router)
{
Error out(getProcessLogger());
out << IceInternal::Application::_appName << ": no glacier2 router configured";
status = 1;
}
else
{
//
// The default is to destroy when a signal is received.
//
if(IceInternal::Application::_signalPolicy == Ice::HandleSignals)
{
destroyOnInterrupt();
}
// If createSession throws, we're done.
try
{
_session = createSession();
_createdSession = true;
}
catch(const Ice::LocalException& ex)
{
Error out(getProcessLogger());
out << IceInternal::Application::_appName << ": " << ex;
status = 1;
}
if(_createdSession)
{
Ice::Int acmTimeout = 0;
try
{
acmTimeout = _router->getACMTimeout();
}
catch(const Ice::OperationNotExistException&)
{
}
if(acmTimeout <= 0)
{
acmTimeout = static_cast<Ice::Int>(_router->getSessionTimeout());
}
if(acmTimeout > 0)
{
Ice::ConnectionPtr connection = _router->ice_getCachedConnection();
assert(connection);
connection->setACM(acmTimeout, IceUtil::None, Ice::HeartbeatAlways);
connection->setCallback(new ConnectionCallbackI(this));
}
_category = _router->getCategoryForClient();
IceUtilInternal::ArgVector a(args);
status = runWithSession(a.argc, a.argv);
}
}
}
// We want to restart on those exceptions which indicate a
// break down in communications, but not those exceptions that
// indicate a programming logic error (ie: marshal, protocol
// failure, etc).
catch(const RestartSessionException&)
{
restart = true;
}
catch(const Ice::ConnectionRefusedException& ex)
{
Error out(getProcessLogger());
out << IceInternal::Application::_appName << ": " << ex;
restart = true;
}
catch(const Ice::ConnectionLostException& ex)
{
Error out(getProcessLogger());
out << IceInternal::Application::_appName << ": " << ex;
restart = true;
}
catch(const Ice::UnknownLocalException& ex)
{
Error out(getProcessLogger());
//.........这里部分代码省略.........
示例12: seq
TimeoutPrxPtr
allTests(const Ice::CommunicatorPtr& communicator)
{
string sref = "timeout:" + getTestEndpoint(communicator, 0);
Ice::ObjectPrxPtr obj = communicator->stringToProxy(sref);
test(obj);
TimeoutPrxPtr timeout = ICE_CHECKED_CAST(TimeoutPrx, obj);
test(timeout);
cout << "testing connect timeout... " << flush;
{
//
// Expect ConnectTimeoutException.
//
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(100));
timeout->holdAdapter(500);
try
{
to->op();
test(false);
}
catch(const Ice::ConnectTimeoutException&)
{
// Expected.
}
}
{
//
// Expect success.
//
timeout->op(); // Ensure adapter is active.
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(1000));
timeout->holdAdapter(500);
try
{
to->op();
}
catch(const Ice::ConnectTimeoutException&)
{
test(false);
}
}
cout << "ok" << endl;
// The sequence needs to be large enough to fill the write/recv buffers
ByteSeq seq(2000000);
cout << "testing connection timeout... " << flush;
{
//
// Expect TimeoutException.
//
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(100));
timeout->holdAdapter(500);
try
{
to->sendData(seq);
test(false);
}
catch(const Ice::TimeoutException&)
{
// Expected.
}
}
{
//
// Expect success.
//
timeout->op(); // Ensure adapter is active.
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(1000));
timeout->holdAdapter(500);
try
{
ByteSeq seq(1000000);
to->sendData(seq);
}
catch(const Ice::TimeoutException&)
{
test(false);
}
}
cout << "ok" << endl;
cout << "testing invocation timeout... " << flush;
{
Ice::ConnectionPtr connection = obj->ice_getConnection();
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(100));
test(connection == to->ice_getConnection());
try
{
to->sleep(750);
test(false);
}
catch(const Ice::InvocationTimeoutException&)
{
}
obj->ice_ping();
to = ICE_CHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(500));
test(connection == to->ice_getConnection());
//.........这里部分代码省略.........
示例13: if
int
TalkApp::run(int argc, char*[])
{
if(argc > 1)
{
cerr << appName() << ": too many arguments" << endl;
return EXIT_FAILURE;
}
//
// Create an object adapter with the name "Talk". Its endpoint is defined
// in the configuration file 'config'.
//
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Talk");
//
// Install a servant with the well-known identity "peer".
//
PeerIPtr incomingPeer = new IncomingPeerI;
PeerIPtr peer = incomingPeer;
adapter->add(peer, communicator()->stringToIdentity("peer"));
adapter->activate();
usage();
cout << ">>>> Ready." << endl;
do
{
string s;
cout << "";
getline(cin, s);
if(!s.empty())
{
if(s[0] == '/')
{
if(s.size() > 8 && s.substr(0, 8) == "/connect")
{
string::size_type sp = s.find(' ');
if(sp == string::npos)
{
usage();
continue;
}
sp = s.find_first_not_of(' ', sp);
if(sp == string::npos)
{
usage();
continue;
}
string addr = s.substr(sp);
//
// Generate a UUID for our callback servant. We have to pass this identity to
// the remote peer so that it can invoke callbacks on the servant over a
// bidirectional connection.
//
Ice::Identity id = communicator()->stringToIdentity(IceUtil::generateUUID());
PeerIPtr servant;
try
{
//
// Create a proxy for the remote peer using the address given by the user
// and the well-known UUID for the talk service.
//
Talk::PeerPrx prx = Talk::PeerPrx::uncheckedCast(
communicator()->stringToProxy(
"peer:bt -a \"" + addr + "\" -u 6a193943-1754-4869-8d0a-ddc5f9a2b294"));
cout << ">>>> Connecting to " << addr << endl;
//
// Configure an object adapter for the connection and add the servant. This enables
// us to receive callbacks via this connection. Calling ice_getConnection() blocks
// until the connection to the peer is established.
//
Ice::ConnectionPtr con = prx->ice_getConnection();
con->setAdapter(adapter);
servant = new OutgoingPeerI(adapter, id, prx);
adapter->add(servant, id);
//
// Now we're ready to notify the peer that we'd like to connect.
//
prx->connect(id);
peer = servant;
cout << ">>>> Connected to " << addr << endl;
}
catch(const Ice::Exception& ex)
{
cout << ">>>> " << ex << endl;
if(servant)
{
adapter->remove(id);
}
}
}
else if(s == "/disconnect")
{
//.........这里部分代码省略.........