コード例 #1
0
ファイル: Server.cpp プロジェクト: 465060874/ice
int
run(int, char**, const Ice::CommunicatorPtr& communicator)
{
    IceUtil::TimerPtr timer = new IceUtil::Timer();

    communicator->getProperties()->setProperty("TestAdapter1.Endpoints", getTestEndpoint(communicator, 0) + ":udp");
    communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.Size", "5");
    communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.SizeMax", "5");
    communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.SizeWarn", "0");
    communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.Serialize", "0");
    Ice::ObjectAdapterPtr adapter1 = communicator->createObjectAdapter("TestAdapter1");
    adapter1->add(ICE_MAKE_SHARED(HoldI, timer, adapter1), communicator->stringToIdentity("hold"));

    communicator->getProperties()->setProperty("TestAdapter2.Endpoints", getTestEndpoint(communicator, 1) + ":udp");
    communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.Size", "5");
    communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.SizeMax", "5");
    communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.SizeWarn", "0");
    communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.Serialize", "1");
    Ice::ObjectAdapterPtr adapter2 = communicator->createObjectAdapter("TestAdapter2");
    adapter2->add(ICE_MAKE_SHARED(HoldI, timer, adapter2), communicator->stringToIdentity("hold"));

    adapter1->activate();
    adapter2->activate();

    TEST_READY

    communicator->waitForShutdown();

    timer->destroy();

    return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: ChatServer.cpp プロジェクト: hewenjian123/ice-demos
bool
ChatServer::start(int, char*[], int& status)
{
    _timer = new IceUtil::Timer();
    // Timeout for reaping polling sessions.
    int timeout = communicator()->getProperties()->getPropertyAsIntWithDefault("ReaperTimeout", 10);
    bool traceEnabled = communicator()->getProperties()->getPropertyAsIntWithDefault("Server.Trace", 0) != 0;
    Ice::LoggerPtr logger = communicator()->getLogger();
    ReaperTaskPtr reaper = new ReaperTask(timeout, traceEnabled, logger);
    _timer->scheduleRepeated(reaper, IceUtil::Time::seconds(timeout));
    try
    {
        _adapter = communicator()->createObjectAdapter("ChatServer");

        ChatRoomPtr chatRoom = new ChatRoom(traceEnabled, logger);
        if(traceEnabled)
        {
            ostringstream os;
            os << "Chat room created ok.";
            logger->trace("info", os.str());
        }
        _adapter->add(new ChatSessionManagerI(chatRoom, traceEnabled, logger),
                     communicator()->stringToIdentity("ChatSessionManager"));

        if(traceEnabled)
        {
            ostringstream os;
            os << "Chat session manager created ok.";
            logger->trace("info", os.str());
        }
        _adapter->add(new PollingChatSessionFactoryI(chatRoom, reaper, traceEnabled, logger),
                     communicator()->stringToIdentity("PollingChatSessionFactory"));

        if(traceEnabled)
        {
            ostringstream os;
            os << "Polling chat session factory created ok.";
            logger->trace("info", os.str());
        }

        _adapter->activate();
        if(traceEnabled)
        {
            ostringstream os;
            os << "Chat server started ok.";
            logger->trace("info", os.str());
        }
    }
    catch(const Ice::LocalException&)
    {
        status = EXIT_FAILURE;
        _timer->destroy();
        throw;
    }
    status = EXIT_SUCCESS;
    return true;
}
コード例 #3
0
ファイル: Client.cpp プロジェクト: bholl/zeroc-ice
void
SessionClient::cleanup(bool destroy)
{
    IceUtil::Mutex::Lock sync(_mutex);

    //
    // The refresher thread must be terminated before destroy is
    // called, otherwise it might get ObjectNotExistException. refresh
    // is set to 0 so that if session->destroy() raises an exception
    // the thread will not be re-terminated and re-joined.
    //
    if(_timer)
    {
        _timer->destroy();
        _timer = 0;
    }
    
    if(destroy && _session)
    {
        _session->destroy();
    }
    _session = 0;
}
コード例 #4
0
int
SessionServer::run(int argc, char*[])
{
    if(argc > 1)
    {
        cerr << appName() << ": too many arguments" << endl;
        return EXIT_FAILURE;
    }

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("SessionFactory");

    IceUtil::TimerPtr timer = new IceUtil::Timer();
    ReapTaskPtr reapTask = new ReapTask;
    timer->scheduleRepeated(reapTask, IceUtil::Time::seconds(1));

    SessionFactoryPtr factory = new SessionFactoryI(reapTask);
    adapter->add(factory, Ice::stringToIdentity("SessionFactory"));
    adapter->activate();
    communicator()->waitForShutdown();

    timer->destroy();

    return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: ChatServer.cpp プロジェクト: hewenjian123/ice-demos
bool
ChatServer::stop()
{
    _timer->destroy();
    return true;
}