예제 #1
0
bool P3ReplicationGroup::prebindDataToReplica(OverlayPeerInfoPtr& replica) {
    ACE_GUARD_RETURN(ACE_SYNCH_RECURSIVE_MUTEX, mon, m_lock, false);
    ACE_Connector<FTDataClientHandler, ACE_SOCK_Connector> connector;
    Endpoint endpoint;
    replica->getFTDataSAPInfo()->getFirstEndpoint(endpoint);
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::prebindDataToReplica - SAP=%s\n"), endpoint.toString().c_str()));
    ThreadPerConnection *tpc = new ThreadPerConnection();
    //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt = new
    //      ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex > (tpc);
    ExecutionModelPtr* tpcPrt = new
            ExecutionModelPtr(tpc);

    FTDataClientHandler* ftDataClient = new FTDataClientHandler(this,
            replica->getUUID(),
            replica->getFID(),
            this->getGroupUUID(),
            false, false, tpcPrt, 0, 0, 0);

    CPUReservation* reserve = 0;
    CPUQoS* cpuQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_RT_DEFAULT, CPUQoS::MAX_RT_PRIO);
    if (this->m_ft->getQoSManager() != 0) {
        reserve = m_ft->getQoSManager()->createCPUReservation("HRT", cpuQoS);
    }
    tpc->bind(ftDataClient);
    tpc->open(reserve, cpuQoS);
    //tpc->bind(ftDataClient);
    connector.reactor(tpc->getResources()->getReactor());

    if (connector.connect(ftDataClient, endpoint.getAddr()) == -1) {
        ACE_ERROR((LM_ERROR, ACE_TEXT("(%T)%@\n"),
                ACE_TEXT("(%T)ERROR: P3ReplicationGroup::prebindDataToReplica - connect failed:")));
        ftDataClient->close();
        delete ftDataClient;
        return false;
    } else {
        if (m_debugP3ReplicationGroup) {
            ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::prebindDataToReplica - Connect Data to Replica - OK! UUID=%s\n"),
                    replica->getUUID()->toString().c_str()));
        }
    }

    ftDataClient->preBindSession();

    if (m_clientDataManager.add(ftDataClient) == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::prebindDataToReplica - failed to add to group UUID=%s\n"),
                replica->getUUID()->toString().c_str()));
        return false;
    }

    if (ftDataClient->asynchronous(true, false) == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::prebindDataToReplica - failed to add to async UUID=%s\n"),
                replica->getUUID()->toString().c_str()));
        ftDataClient->close();
        return false;
    }
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::prebindDataToReplica - OK! UUID=%s\n"),
            replica->getUUID()->toString().c_str()));
    return true;
}
예제 #2
0
int main(int argc, char *argv[])
{
  ACE_Connector <My_Handler,ACE_SOCK_Connector> connector;
  My_Handler * handler = 0;
  int port = atoi (argv[1]);
  ACE_SOCK_Connector::PEER_ADDR addr (port, "localhost");
  connector.connect(handler, addr);
  ACE_Reactor::instance()->run_reactor_event_loop();

  return 0;
}
예제 #3
0
파일: Client.cpp 프로젝트: DOCGroup/ACE_TAO
// Listing 6 code/ch07
int ACE_TMAIN (int, ACE_TCHAR *[])
{
  ACE_INET_Addr port_to_connect (ACE_TEXT ("HAStatus"), ACE_LOCALHOST);
  ACE_Connector<Client, ACE_SOCK_CONNECTOR> connector;
  Client client;
  Client *pc = &client;
  if (connector.connect (pc, port_to_connect) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
                       ACE_TEXT ("connect")), 1);

  ACE_Reactor::instance ()->run_reactor_event_loop ();
  return (0);
}
예제 #4
0
void P3LeafMesh::createRemoteService(const SAPInfo* hint, const UUIDPtr& uuid, const UUIDPtr& sid, ServiceParamsPtr& params, UUIDPtr& iid) throw (ServiceException&) {
    ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock);
    if (hint == 0) {
        throw ServiceException(ServiceException::SERVICE_WITHOUT_IMPL);
    }
    Endpoint endpoint;
    ACE_Connector<P3MeshClientHandler, ACE_SOCK_Connector> connector;
    hint->getFirstEndpoint(endpoint);
    QoSEndpoint qosE = *(endpoint.getQoS());
    UUIDPtr runtimeUUID;
    getUUID(runtimeUUID);
    UUIDPtr fid;
    getFID(fid);
    P3MeshClientHandler* clientHandler = new P3MeshClientHandler(
            runtimeUUID,
            fid,
            qosE,
            false, false, 0, 0, 0, 0);

    if (connector.connect(clientHandler, endpoint.getAddr()) == -1) {
        ACE_ERROR((LM_ERROR, ACE_TEXT("(%T)%@\n"),
                ACE_TEXT("(%T)ERROR: P3Mesh::createRemoteService - connect failed:")));
        clientHandler->close();
        clientHandler = 0;
        delete clientHandler;
    } else {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh::createRemoteService - Connect OK!\n")));
    }

    int ret = clientHandler->createService(params, iid);
    clientHandler->close();
    delete clientHandler;
    if (ret == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh::createRemoteService - failed to create, not enough resources\n")));
        throw ServiceException(ServiceException::INSUFFICIENT_RESOURCES);
    }
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh::createRemoteService - service created!\n")));
}
예제 #5
0
int ActuatorServiceClient::bindClientHandler() {
    ACE_GUARD_RETURN(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock, -1);
    FindServiceInstanceQuery* query = new FindServiceInstanceQuery(m_sid, m_iid);
    Stheno* runtime = this->getRuntime();
    OverlayInterface* oi = runtime->getOverlayInterface();
    DiscoveryInterfacePtr discoveryPtr = oi->getDiscovery();
    printf("ActuatorServiceClient::bindClientHandler() OI=%p\n", oi);
    DiscoveryQueryReply* queryReply_ = discoveryPtr->executeQuery(query);
    if (queryReply_ == 0) {
        return -1;
    }
    if (queryReply_->isException()) {
        //printf("ActuatorServiceClient: exception! SID(%s) IID(%s)\n", m_sid->toString().c_str(), m_iid->toString().c_str());
        delete queryReply_;
        return -1;
    }
    FindServiceInstanceQueryReply *queryReply = new FindServiceInstanceQueryReply(queryReply_);

    //printf("StreamClient: FindServiceInstanceQueryReply!\n",queryReply->
    //EndpointPtr endpoint = m_streamParams->getEndpoint();
    Endpoint endpoint;
    //queryReply->getSAPInfo()->getFirstEndpoint(endpoint);
    queryReply->getSAPInfo()->getEndpoint(m_cp->getQoS(), endpoint);
    printf("ActuatorServiceClient: FindServiceInstanceQueryReply! endpoint=%s\n", endpoint.toString().c_str());
    ACE_Connector<ActuatorServiceClientHandler, ACE_SOCK_Connector> connector;
    //QoSEndpoint qosE = *(endpoint.getQoS());        

    ThreadPerConnection *tpc = new ThreadPerConnection();
    //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt = new
    //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex > (tpc);
    ExecutionModelPtr* tpcPrt = new
            ExecutionModelPtr(tpc);

    //QoSEndpoint qosEndpoint(Endpoint::TCP, 50);
    UUIDPtr runtimeUUID;
    UUIDPtr fid;
    m_runtime->getUUID(runtimeUUID);
    m_runtime->getOverlayInterface()->getMesh()->getFID(fid);

    m_clientHandler = new ActuatorServiceClientHandler(
            runtimeUUID,
            fid,
            false, false, tpcPrt, 0, 0, 0);

    printf("ActuatorServiceClient: before tpc\n");
    //tpc->open();
    CPUReservation* reserve = 0;
    //CPUQoS* cpuQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_FIFO, CPUQoS::MAX_RT_PRIO);
    CPUQoS* cpuQoS = m_cp->createCPUQoS(); //new CPUPriorityQoS(m_cp->getScheduleType(), m_cp->getPriority());
    tpc->bind(m_clientHandler);
    tpc->open(reserve, cpuQoS);
    //tpc->bind(m_clientHandler);
    connector.reactor(tpc->getResources()->getReactor());
    printf("ActuatorServiceClient: before connect\n");
    if (connector.connect(m_clientHandler, endpoint.getAddr()) == -1) {
        ACE_ERROR((LM_ERROR, ACE_TEXT("(%T)%@\n"),
                ACE_TEXT("(%T)ERROR: ActuatorServiceClient::executeQuery() - connect failed:")));
        m_clientHandler->close();
        delete m_clientHandler;
        m_clientHandler = 0;
        return -1;
    } else {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: ActuatorServiceClient::open_i() - Connect to service! %@\n"), m_clientHandler));
        if (m_rebindStart.msec() != 0) {
            ACE_Time_Value rebindEnd = ACE_OS::gettimeofday() - m_rebindStart;
            m_rebindTotalTime += rebindEnd;
        }
    }
    printf("ActuatorServiceClient: after connect\n");
    //m_client->setCloseListener(this);

    /*if (m_clientHandler->setCloseListener(this) == -1) {
        m_clientHandler->close();
        delete m_clientHandler;
        m_clientHandler = 0;        
        return -1;
    }*/


    //if (m_clientHandler->asynchronous(true, false) != 0) {
    if (m_clientHandler->asynchronous(true, false) != 0) {
        m_clientHandler->close();
        delete m_clientHandler;
        m_clientHandler = 0;
        return -1;
    }
    return 0;
}
예제 #6
0
int RPCServiceClient::bindClientHandler() {
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: RPCServiceClient::bindClientHandler()\n")));
    ACE_GUARD_RETURN(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock, -1);
    FindServiceInstanceQuery* query = new FindServiceInstanceQuery(m_sid, m_iid);
    Stheno* runtime = this->getRuntime();
    OverlayInterface* oi = runtime->getOverlayInterface();
    DiscoveryInterfacePtr discoveryPtr = oi->getDiscovery();
    //printf("RPCServiceClient::bindClientHandler() OI=%p\n", oi);
    DiscoveryQueryReply* queryReply_ = discoveryPtr->executeQuery(query);
    //query is already owned
    /*ACE_DEBUG((LM_DEBUG, ACE_TEXT("********************RPCServiceClient::bindClientHandler %s %s %p\n"),
            m_sid->toString().c_str(),
            m_iid->toString().c_str(),
            queryReply_));*/
    if (queryReply_ == 0) {
        printf("query == bnull!\n");
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: RPCServiceClient::bindClientHandler() query null!\n")));
        return -1;
    }
    if (queryReply_->isException()) {
        printf("query == ex!\n");
        delete queryReply_;
        return -1;
    }
    FindServiceInstanceQueryReply *queryReply = new FindServiceInstanceQueryReply(queryReply_);

    Endpoint endpoint;
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: RPCServiceClient::bindClientHandler() before endpoint choosing\n")));
    try {
        queryReply->getSAPInfo()->getEndpoint(m_cp->getQoS(), endpoint);
    } catch (EndpointException& ex) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: RPCServiceClient::bindClientHandler() endpoint EX!\n")));
        delete queryReply;
        return -1;
    }
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: bindClientHandler! endpoint=%s\n"), endpoint.toString().c_str()));
    ACE_Connector<RPCServiceClientHandler, ACE_SOCK_Connector> connector;
    //QoSEndpoint qosE = *(endpoint.getQoS());        

    ThreadPerConnection *tpc = new ThreadPerConnection();
    //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt = new
    //      ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex > (tpc);
    ExecutionModelPtr* tpcPrt = new
            ExecutionModelPtr(tpc);

    //QoSEndpoint qosEndpoint(Endpoint::TCP, 50);
    if (m_clientHandler != 0) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: RPCServiceClient::bindClientHandler() closing open client\n")));
        m_clientHandler->close();
        delete m_clientHandler;
    }

    UUIDPtr runtimeUUID;
    UUIDPtr fid;
    m_runtime->getUUID(runtimeUUID);
    m_runtime->getOverlayInterface()->getMesh()->getFID(fid);
    m_clientHandler = new RPCServiceClientHandler(
            runtimeUUID,
            fid,
            m_cp->getQoS(),
            false, false, tpcPrt, 0, 0, 0);

    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: RPCServiceClient::bindClientHandler() endpoint client=%@\n"), m_clientHandler));
    //tpc->open();
    CPUReservation* reserve = 0;
    CPUQoS* cpuQoS = m_cp->createCPUQoS();
    //CPUQoS* cpuQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_FIFO, CPUQoS::MAX_RT_PRIO);
    //CPUQoS* cpuQoS = new CPUPriorityQoS(m_cp->getScheduleType(), m_cp->getPriority());    
    tpc->bind(m_clientHandler);
    tpc->open(reserve, cpuQoS);
    //tpc->bind(m_clientHandler);
    connector.reactor(tpc->getResources()->getReactor());
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) RPCServiceClient: bindClientHandler before connect\n")));
    if (connector.connect(m_clientHandler, endpoint.getAddr()) == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T)(%t|%T) ERROR: RPCServiceClient::bindClientHandler() - connect failed!")));
        m_clientHandler->close();
        delete m_clientHandler;
        m_clientHandler = 0;
        return -1;
    } else {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: RPCServiceClient::bindClientHandler() - Connect to service! client=%@\n"), m_clientHandler));
        if (m_rebindStart.msec() != 0) {
            ACE_Time_Value rebindEnd = ACE_OS::gettimeofday() - m_rebindStart;
            m_rebindTotalTime += rebindEnd;
            m_rebindStart = ACE_Time_Value(0,0);
        }
    }



    /*if (m_clientHandler->asynchronous(true, false) != 0) {
        m_clientHandler->close();
        delete m_clientHandler;
        m_clientHandler = 0;
        return -1;
    }*/

    /*if (m_rebindStart.msec() != 0) {
        ACE_Time_Value rebindEnd = ACE_OS::gettimeofday() - m_rebindStart;
        m_rebindTotalTime += rebindEnd;
    }*/

    return 0;
}
예제 #7
0
bool P3ReplicationGroup::bindControlToReplica(OverlayPeerInfoPtr& replica) {
    ACE_GUARD_RETURN(ACE_SYNCH_RECURSIVE_MUTEX, mon, m_lock, false);
    ACE_Connector<FTControlClientHandler, ACE_SOCK_Connector> connector;
    Endpoint endpoint;
    replica->getFTSAPInfo()->getFirstEndpoint(endpoint);
    //printf("==============bindControlToReplica endpoint=%s\n", endpoint.toString().c_str());

    ThreadPerConnection *tpc = new ThreadPerConnection();
    //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt = new
    //      ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex > (tpc);
    ExecutionModelPtr* tpcPrt = new
            ExecutionModelPtr(tpc);

    FTControlClientHandler* ftControlClient = new FTControlClientHandler(
            this,
            replica->getUUID(),
            replica->getFID(),
            this->getGroupUUID(),
            false, false, tpcPrt, 0, 0, 0);

    printMembers();
    SAPInfoPtr ftDataSAPInfo;

    //*(getGroupMembers()));
    tpc->bind(ftControlClient);
    tpc->open();
    //tpc->bind(ftControlClient);
    connector.reactor(tpc->getResources()->getReactor());

    if (connector.connect(ftControlClient, endpoint.getAddr()) == -1) {
        ACE_ERROR((LM_ERROR, ACE_TEXT("(%T)%@\n"),
                ACE_TEXT("(%T)ERROR: P3ReplicationGroup::bindControlToReplica - connect failed:")));
        ftControlClient->close();
        delete ftControlClient;
        return false;
    } else {
        if (m_debugP3ReplicationGroup) {
            ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::bindControlToReplica - Connect to replica OK! UUID=%s\n"),
                    replica->getUUID()->toString().c_str()));
        }
    }
    UUIDPtr sid;
    getSID(sid);
    ftControlClient->initSession(
            sid,
            m_groupUUID,
            //m_iid,
            this->getServiceParams(),
            this->getPrimary(),
            this->getReplicaList(),
            ftDataSAPInfo);
    if (m_debugP3ReplicationGroup) {
        ACE_DEBUG((LM_DEBUG,
                ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::bindControlToReplica() - update(dataft) = (%@)\n"),
                ftDataSAPInfo.get()
                ));
    }
    if (m_clientControlManager.add(ftControlClient) == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::bindControlToReplica - to add to group! UUID=%s\n"),
                replica->getUUID()->toString().c_str()));
        return false;
    }
    //this->updateFTDataSAP(replica->getUUID(), ftDataSAPInfo); //why???
    replica->setFTDataSAP(ftDataSAPInfo);

    if (ftControlClient->asynchronous(true, false) == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::bindControlToReplica - to aync! UUID=%s\n"),
                replica->getUUID()->toString().c_str()));
        ftControlClient->close();
        return false;
    }
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3ReplicationGroup::bindControlToReplica -OK UUID=%s\n"),
            replica->getUUID()->toString().c_str()));
    return true;
}
예제 #8
0
void P3LeafMesh::bind(bool firstTime) throw (ServiceException&) {
    ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock);
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) INFO: P3LeafMesh::bind():open\n")));
    UUIDPtr runtimeUUID;
    this->getUUID(runtimeUUID);    
    LeafMeshDiscovery* discovery = new LeafMeshDiscovery(runtimeUUID);    
    try {
        discovery->open();
    } catch (CellException& ex) {
        delete discovery;
        throw ServiceException("Discovery failed to open!");
    }        
    CoordinatorInfo* coordInfo = discovery->requestCoordinator();
    if (coordInfo == 0) {
        delete discovery;
        throw ServiceException("Error connecting to coordinator!");
    }    
  
    m_coordMeshSAP = coordInfo->getMeshSap();
    m_fid = coordInfo->getCellID();
    m_coordDiscoverySAP = coordInfo->getDiscoverySap();
    m_coordinatorUUID = coordInfo->getPID();
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T) INFO: P3LeafMesh::bind() - DiscoverySAP=%@\n"), m_coordDiscoverySAP.get()));
    ACE_Connector<LeafClientHandler, ACE_SOCK_Connector> connector;
    CellID* cellID = new CellID(*coordInfo->getCellID().get());
    CellIDPtr cellIDPtr(cellID);

    //LeafClientHandler* client = new LeafClientHandler(coordInfo->getPID(), cellIDPtr, this, false, false, 0, 0, 0, 0);
    ThreadPerConnection *tpc = new ThreadPerConnection();
    /*ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt*/ 
    ExecutionModelPtr* tpcPrt = new
            ExecutionModelPtr (tpc);
    LeafClientHandler* client = new LeafClientHandler(coordInfo->getPID(), cellIDPtr, this, false, false, tpcPrt, 0, 0, 0);
    
    
    //tpc->open();
    CPUQoS* cpuQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_RT_DEFAULT, CPUQoS::MAX_RT_PRIO);
    CPUReservation* reserve = 0;
    if (getQoSManager() != 0) {
        reserve = getQoSManager()->createCPUReservation("HRT", cpuQoS);
    }
    tpc->bind(client);
    tpc->open(reserve, cpuQoS);
    //tpc->bind(client);
    connector.reactor(tpc->getResources()->getReactor());

    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh - Connecting...(%s) client=%@!\n"),
            coordInfo->getPID()->toString().c_str(), client));
    if (connector.connect(client, coordInfo->getCellCoordinatorEndpoint()->getAddr()) == -1) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)ERROR: P3LeafMesh - Error Connecting...(%s) client=%@!\n"),
                coordInfo->getPID()->toString().c_str(), client));
        perror("P3LeafMesh=");
        /*ACE_ERROR((LM_ERROR, ACE_TEXT("(%T)%@\n"),
                ACE_TEXT("(%T)connect failed:")));*/
        delete coordInfo;

        delete client;
        delete discovery;

        throw ServiceException("Error connecting to coordinator!");
    } else {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh:bind() - Connect OK!\n")));
        delete discovery;
        delete coordInfo;
        m_client.reset(client);
        if (m_client->asynchronous(true,false) == -1) {
            //delete m_client;
            //m_client = 0;
            m_client.reset(0);
            throw ServiceException("Error connecting to coordinator (2)!");
        }        
        bool joinRet = client->joinMesh(getOverlay_i()->getType());
        //m_client = client;        
        if (m_client->setCloseListener(this) == -1) {
            //delete m_client;
            //m_client = 0;
            m_client.reset(0);
            throw ServiceException("Error connecting to coordinator (2)!");
        }        
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh:bind() - join(%d)\n"), joinRet));
    }
    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: P3LeafMesh:bind() - join end!\n")));
    UUIDPtr fid;
    this->getFID(fid);
    TraceRuntimeSingleton::instance()->logBindToMesh(runtimeUUID,fid, m_coordinatorUUID, m_fid);
    if(firstTime){
        ACE_Time_Value end = ACE_OS::gettimeofday();
        end -= m_start;
        TraceRuntimeSingleton::instance()->logMembershipTime(end);
    }else{
        ACE_Time_Value end = ACE_OS::gettimeofday();
        end -= m_start;
        TraceRuntimeSingleton::instance()->logMembershipRebindTime(end);
    }
    //CellDiscovery* discovery = new CellDiscovery(this->getUUID());
    //discovery->open();
    //CellReply* info = discovery->requestCell(CellID::INVALID_CELL_ID_UUIDPTR);

}
예제 #9
0
int CellAcceptor::handle_input(ACE_HANDLE fd) {
    //ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)CellAcceptor::handle_input - New incoming connection\n")));
    CellSvcHandler *client;
    ThreadPerConnection *tpc = new ThreadPerConnection();
    //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt = new
      //      ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex > (tpc);
    ExecutionModelPtr* tpcPrt = new ExecutionModelPtr (tpc);
    ACE_NEW_RETURN(client,
            CellSvcHandler(m_cell,  tpcPrt, 0, 0, 0), -1);

    auto_ptr<CellSvcHandler> p(client);
    if (this->m_acceptor.accept(client->peer()) == -1)
        ACE_ERROR_RETURN((LM_ERROR,
            ACE_TEXT("(%T) failed to accept\n")),
            -1);
    p.release();

    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO CellAcceptor::handle_input - new connection %d!\n"), client->get_handle()));
    CPUPriorityQoS* cpuQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_RT_DEFAULT, CPUQoS::MAX_RT_PRIO);
    CPUReservation* reserve = 0;
    if (m_cell->getQoSManager() != 0) {
        reserve = m_cell->getQoSManager()->createCPUReservation("HRT", cpuQoS);
    }
    //printf("==================== %p %p \n\n\n\n",cpuQoS,reserve);
    tpc->bind(client);
    tpc->open(reserve, cpuQoS);

    if (client->open() == -1) {
        printf("CellAcceptor: failed to eopn client == -1\n");
        delete client;
        return 0;
    }
    UUIDPtr uuid;
    m_cell->getPID(uuid);
    UUIDPtr fid;
    m_cell->getFID(fid);
    CellIDPtr cellID;
    m_cell->getCellID(cellID);
    if (client->isLeaf()) {
        ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: CellAcceptor::handle_input() - Add new children peer (%s,%s)\n"),
                cellID->toString().c_str(), client->getCellID()->toString().c_str()));
        if(m_leafGroup->add(client) == -1){
            return 0;
        }
    } else {
        if (client->isChildren()) {
            CellIDPtr runtimeCellID;
            m_cell->getCellID(runtimeCellID);
            ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: CellAcceptor::handle_input() - Add new children peer (%s,%s)\n"),
                    runtimeCellID->toString().c_str(), client->getCellID()->toString().c_str()));
            if(m_childrenGroup->add(client)==-1){
                return 0;
            }
        } else {
            ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: CellAcceptor::handle_input() - Add group peer\n")));
            if(m_cellGroup->add(client) == -1){
                return 0;
            }
            ACE_Connector<CellFollowerClientHandler, ACE_SOCK_Connector> connector;
            ThreadPerConnection *tpc = new ThreadPerConnection();
            //ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex>* tpcPrt = new
            //        ACE_Strong_Bound_Ptr<ThreadPerConnection, ACE_Recursive_Thread_Mutex > (tpc);
            ExecutionModelPtr* tpcPrt = new ExecutionModelPtr(tpc);

            CellFollowerClientHandler* followerClient = new CellFollowerClientHandler(
                    client->getPID(), client->getFID(), m_cell,
                    //true, false,
                    false,false,
                    tpcPrt,
                    0, 0, 0);

            CPUQoS* followerCPUQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_RT_DEFAULT, CPUQoS::MAX_RT_PRIO);
            CPUReservation* followerReserve = 0;
            if (m_cell->getQoSManager() != 0) {
                followerReserve = m_cell->getQoSManager()->createCPUReservation("HRT", cpuQoS);
            }

            tpc->bind(followerClient);
            tpc->open(followerReserve,followerCPUQoS);
            connector.reactor(tpc->getResources()->getReactor());

            ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: Connecting to follower...(%s)!\n"), client->getPID()->toString().c_str()));

            if (connector.connect(followerClient, client->getFollowerEndpoint()->getAddr()) == -1) {
                ACE_ERROR((LM_ERROR, ACE_TEXT("CellAcceptor::handle_input follower connection failed\n")));
                followerClient->close();
                throw ServiceException("Error connecting to follower!");
            } else {
                ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: Cell:joinNonCoordinator() - Connect OK!\n")));
            }

            if(m_cellFollowerGroup->add(followerClient) == -1){
                client->close();
                return 0;
            }
            if (followerClient->asynchronous(true, false)) {
                followerClient->close();
            }
        }
    }
    //if (client->asynchronous(true, true) == -1) {
    //changed:
    if (client->asynchronous(true, false) == -1) {
        client->close();
    }

    ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t|%T)INFO: client binded OK!\n")));
    return 0;
}