void thorium_actor_send_reply_int64_t(struct thorium_actor *actor, int tag, int64_t value) { thorium_actor_send_int64_t(actor, thorium_actor_source(actor), tag, value); }
void biosal_input_stream_receive(struct thorium_actor *actor, struct thorium_message *message) { int tag; int source; uint64_t count; struct biosal_input_stream *concrete_self; int i; int has_sequence; int sequences; int sequence_index; int buffer_size; char *buffer; char *read_buffer; struct biosal_mega_block mega_block; char *file_name_in_buffer; if (thorium_actor_take_action(actor, message)) { return; } concrete_self = thorium_actor_concrete_actor(actor); tag = thorium_message_action(message); source = thorium_message_source(message); buffer = (char *)thorium_message_buffer(message); /* Do nothing if there is an error. * has_error returns the error to the source. */ /* if (biosal_input_stream_has_error(actor, message)) { return; } */ if (tag == ACTION_INPUT_OPEN) { #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_OPEN\n"); #endif if (concrete_self->open) { concrete_self->error = BIOSAL_INPUT_ERROR_ALREADY_OPEN; thorium_actor_send_reply_int(actor, ACTION_INPUT_OPEN_REPLY, concrete_self->error); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } concrete_self->open = 1; /* TODO: find out the maximum read length in some way */ concrete_self->maximum_sequence_length = BIOSAL_INPUT_MAXIMUM_SEQUENCE_LENGTH; concrete_self->buffer_for_sequence = (char *)core_memory_allocate(concrete_self->maximum_sequence_length, MEMORY_INPUT_STREAM); /*biosal_input_stream_init(actor);*/ #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG biosal_input_stream_receive open %s\n", buffer); #endif /*core_memory_copy(&concrete_self->file_index, buffer, sizeof(concrete_self->file_index));*/ file_name_in_buffer = buffer; printf("stream/%d (node/%d) opens file %s offset %" PRIu64 "\n", thorium_actor_name(actor), thorium_actor_node_name(actor), file_name_in_buffer, concrete_self->starting_offset); #ifdef DEBUG_ISSUE_594 thorium_message_print(message); printf("Buffer %s\n", buffer); #endif concrete_self->file_name = core_memory_allocate(strlen(file_name_in_buffer) + 1, MEMORY_INPUT_STREAM); strcpy(concrete_self->file_name, file_name_in_buffer); biosal_input_proxy_init(&concrete_self->proxy, concrete_self->file_name, concrete_self->starting_offset, concrete_self->ending_offset); concrete_self->proxy_ready = 1; /* Die if there is an error... */ if (biosal_input_stream_has_error(actor, message)) { #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG has error\n"); #endif thorium_actor_send_reply_int(actor, ACTION_INPUT_OPEN_REPLY, concrete_self->error); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } concrete_self->controller = source; /* no error here... */ thorium_actor_send_reply_int(actor, ACTION_INPUT_OPEN_REPLY, concrete_self->error); } else if (tag == ACTION_INPUT_COUNT) { /* count a little bit and yield the worker */ if (concrete_self->count_customer == THORIUM_ACTOR_NOBODY) { concrete_self->count_customer = source; } if (biosal_input_stream_check_open_error(actor, message)) { thorium_actor_send_reply_int64_t(actor, ACTION_INPUT_COUNT_REPLY, concrete_self->error); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_COUNT received...\n"); #endif i = 0; /* continue counting ... */ has_sequence = 1; while (i < concrete_self->granularity && has_sequence) { has_sequence = biosal_input_proxy_get_sequence(&concrete_self->proxy, concrete_self->buffer_for_sequence); #if 0 printf("Sequence= %s\n", concrete_self->buffer_for_sequence); #endif i++; } sequences = biosal_input_proxy_size(&concrete_self->proxy); #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_COUNT sequences %d...\n", sequences); #endif if (!has_sequence || sequences % concrete_self->mega_block_size == 0) { biosal_mega_block_init(&mega_block, -1, concrete_self->last_offset, sequences - concrete_self->last_entries, sequences); core_vector_push_back(&concrete_self->mega_blocks, &mega_block); concrete_self->last_entries = sequences; concrete_self->last_offset = biosal_input_proxy_offset(&concrete_self->proxy); thorium_actor_send_int64_t(actor, concrete_self->controller, ACTION_INPUT_COUNT_PROGRESS, sequences); } if (has_sequence) { /*printf("DEBUG yield\n");*/ thorium_actor_send_to_self_empty(actor, ACTION_YIELD); /* notify the controller of our progress... */ } else { thorium_actor_send_to_self_empty(actor, ACTION_INPUT_COUNT_READY); } } else if (tag == ACTION_YIELD_REPLY) { if (biosal_input_stream_check_open_error(actor, message)) { /* * it is not clear that there can be an error when receiving YIELD. error = concrete_self->error; thorium_actor_send_reply_int(actor, ACTION_INPUT_COUNT_REPLY, error); thorium_actor_send_to_self(actor, ACTION_ASK_TO_STOP); */ return; } thorium_actor_send_to_self_empty(actor, ACTION_INPUT_COUNT); } else if (tag == ACTION_INPUT_COUNT_READY) { if (biosal_input_stream_check_open_error(actor, message)) { return; } count = biosal_input_proxy_size(&concrete_self->proxy); thorium_actor_send_vector(actor, concrete_self->count_customer, ACTION_INPUT_COUNT_REPLY, &concrete_self->mega_blocks); printf("input_stream/%d on node/%d counted entries in %s, %" PRIu64 "\n", thorium_actor_name(actor), thorium_actor_node_name(actor), concrete_self->file_name, count); } else if (tag == ACTION_INPUT_CLOSE) { #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG destroy proxy\n"); #endif concrete_self->error = BIOSAL_INPUT_ERROR_NO_ERROR; if (biosal_input_stream_check_open_error(actor, message)) { concrete_self->error = BIOSAL_INPUT_ERROR_FILE_NOT_OPEN; thorium_message_init(message, ACTION_INPUT_CLOSE_REPLY, sizeof(concrete_self->error), &concrete_self->error); thorium_actor_send(actor, source, message); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); return; } thorium_message_init(message, ACTION_INPUT_CLOSE_REPLY, sizeof(concrete_self->error), &concrete_self->error); thorium_actor_send(actor, source, message); thorium_actor_send_to_self_empty(actor, ACTION_ASK_TO_STOP); #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("actor %d sending ACTION_INPUT_CLOSE_REPLY to %d\n", thorium_actor_name(actor), source); #endif } else if (tag == ACTION_INPUT_GET_SEQUENCE) { if (biosal_input_stream_check_open_error(actor, message)) { /* the error management could be better. */ concrete_self->error = BIOSAL_INPUT_ERROR_FILE_NOT_OPEN; thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE_REPLY, sizeof(concrete_self->error), &concrete_self->error); thorium_actor_send(actor, source, message); return; } sequence_index = biosal_input_proxy_size(&concrete_self->proxy); /* TODO it would be clearer to use a struct to pack a int and a char [] * then to use the code below. */ read_buffer = concrete_self->buffer_for_sequence + sizeof(sequence_index); has_sequence = biosal_input_proxy_get_sequence(&concrete_self->proxy, read_buffer); if (!has_sequence) { thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE_END, 0, NULL); thorium_actor_send(actor, source, message); return; } buffer_size = sizeof(sequence_index) + strlen(read_buffer) + 1; core_memory_copy(concrete_self->buffer_for_sequence, &sequence_index, sizeof(sequence_index)); thorium_message_init(message, ACTION_INPUT_GET_SEQUENCE_REPLY, buffer_size, concrete_self->buffer_for_sequence); thorium_actor_send(actor, source, message); } else if (tag == ACTION_INPUT_PUSH_SEQUENCES) { biosal_input_stream_push_sequences(actor, message); } else if (tag == ACTION_ASK_TO_STOP) { thorium_actor_send_to_self_empty(actor, ACTION_STOP); thorium_actor_send_range_empty(actor, &concrete_self->parallel_streams, ACTION_ASK_TO_STOP); thorium_actor_send_reply_empty(actor, ACTION_ASK_TO_STOP_REPLY); } else if (tag == ACTION_INPUT_STREAM_RESET) { /* fail silently */ if (!concrete_self->open) { thorium_actor_send_reply_empty(actor, ACTION_INPUT_STREAM_RESET_REPLY); return; } #ifdef BIOSAL_INPUT_STREAM_DEBUG printf("DEBUG ACTION_INPUT_STREAM_RESET\n"); #endif biosal_input_proxy_destroy(&concrete_self->proxy); biosal_input_proxy_init(&concrete_self->proxy, concrete_self->file_name, concrete_self->starting_offset, concrete_self->ending_offset); thorium_actor_send_reply_empty(actor, ACTION_INPUT_STREAM_RESET_REPLY); } else if (tag == ACTION_PUSH_SEQUENCE_DATA_BLOCK_REPLY) { thorium_actor_send_to_supervisor_int(actor, ACTION_INPUT_PUSH_SEQUENCES_REPLY, source); } }