コード例 #1
0
bool ExpandableBlockStreamExchange::open(const PartitionOffset& partition_off){
	if(sem_open_.try_wait()){
		nexhausted_lowers=0;
		nlowers=state.lower_ip_list.size();

		for(unsigned i=0;i<nlowers;i++){
			received_block[i]=0;
		}

		socket_fd_lower_list=new int[nlowers];
//		lower_ip_array=new std::string[nlowers];

		buffer=new BlockStreamBuffer(state.block_size,nlowers*10,state.schema);
		received_block_stream_=BlockStreamBase::createBlock(state.schema,state.block_size);
		block_for_socket_=new BlockReadableFix(received_block_stream_->getSerializedBlockSize(),state.schema);
		if(PrepareTheSocket()==false)
			return false;

		if(RegisterExchange()==false){
			Logging_ExchangeIteratorEager("Register Exchange with ID=%l fails!",state.exchange_id);
		}

		if(isMaster()){
			Logging_ExchangeIteratorEager("This exchange is the master one, serialize the iterator subtree to the children...");
			if(SerializeAndSendToMulti()==false)
				return false;
		}


		if(WaitForConnectionFromLowerExchanges()==false){
			return false;
		}

		if(CreateReceiverThread()==false){
			return false;
		}




		open_finished_=true;
		return true;
	}
	else{
		while(!open_finished_){
			usleep(1);
		}
		return true;
	}
}
コード例 #2
0
bool ExpandableBlockStreamExchangeMaterialized::open(const PartitionOffset& part_off){
	if(sem_open_.try_wait()){
		nexhausted_lowers_=0;
		received_block_stream_=BlockStreamBase::createBlock(state_.schema_,state_.block_size_);
		block_for_socket_=new BlockReadableFix(received_block_stream_->getSerializedBlockSize(),state_.schema_);
		buffer=new BlockStreamBuffer(state_.block_size_,nlowers_*10,state_.schema_);
		if(PrepareTheSocket()==false)
			return false;

		if(RegisterExchange(ExchangeID(state_.exchange_id_,0))==false){
			Logging_ExpandableBlockStreamExchangeMaterialized("Register Exchange with ID=%l fails!",state_.exchange_id_);
		}

		if(isMaster()){
			Logging_ExpandableBlockStreamExchangeMaterialized("This exchange is the master one, serialize the iterator subtree to the children...");
			if(SerializeAndSendToMulti()==false)
				return false;
		}

		if(WaitForConnectionFromLowerExchanges()==false){
			return false;
		}

		if(pthread_create(&receiver_tid,NULL,receiver,this)!=0){
			Logging_ExpandableBlockStreamExchangeMaterialized("Failed to create receiver thread.");
			return false;
		}
		open_finished_=true;
		return true;

	}
	else{
		while(!open_finished_){
			usleep(1);
		}
		return true;
	}

}