Пример #1
0
void send_frames_at_server(zhash_t *frames, void *worker,  enum SEND_TYPE type, int n, ...) {
    char *key;
    va_list valist;
    int i;

    va_start(valist, n);

    zlist_t *names = zlist_new();

    for(i=0; i < n; i++ ) {
        key = va_arg(valist, char *);
        zframe_t *frame = (zframe_t *)zhash_lookup(frames, key);
        assert(frame!=NULL); 

        assert(zframe_is(frame));
        zlist_append(names, key);

        if( i == n-1 && type==SEND_FINAL)  {
            zframe_send(&frame, worker, ZFRAME_REUSE);
        } else
            zframe_send(&frame, worker, ZFRAME_REUSE + ZFRAME_MORE);
    }
    va_end(valist);

    if(DEBUG_MODE) print_out_hash_in_order(frames, names);

    zlist_purge(names);
    zlist_destroy(&names);

}
Пример #2
0
void
zlist_destroy (zlist_t **self_p)
{
    assert (self_p);
    if (*self_p) {
        zlist_t *self = *self_p;
        zlist_purge (self);
        free (self);
        *self_p = NULL;
    }
}
Пример #3
0
JNIEXPORT void JNICALL
Java_zlist__1_1purge (JNIEnv *env, jclass c, jlong self)
{
    zlist_purge ((zlist_t *) self);
}
Пример #4
0
static void
server_worker (void *_server_args, zctx_t *ctx) {
    void *worker = zsocket_new (ctx, ZMQ_DEALER);
    zsocket_connect(worker, "inproc://backend");

    int64_t affinity = 5000;
    int rc = zmq_setsockopt(socket, ZMQ_SNDBUF, &affinity, sizeof affinity);
    rc = zmq_setsockopt(socket, ZMQ_RCVBUF, &affinity, sizeof affinity);

    char algorithm_name[BUFSIZE];
    server_args = (Server_Args *)_server_args;

    printf("Initial value size %ld\n", strlen(server_args->init_data));
    printf("Initial server str %s\n", server_args->servers_str);

    zmq_pollitem_t items[] = { { worker, 0, ZMQ_POLLIN, 0}};

//    int count = 0;
    while (true) {
        printf("\twaiting for message\n");
        int rc = zmq_poll(items, 1, -1);
        if( rc < 0 || s_interrupted==1) {
            exit(EXIT_FAILURE);
        }

        if (items[0].revents & ZMQ_POLLIN) {
            printf("\treceived message\n");

            zmsg_t *msg = zmsg_recv(worker);

            // receive the frames
            status->network_data += (float)zmsg_content_size(msg) ;
            zlist_t *frames_list = zlist_new();
            zhash_t *frames = receive_message_frames_at_server(msg, frames_list);

            get_string_frame(algorithm_name, frames, ALGORITHM);

            if( strcmp(algorithm_name, "ABD")==0)  {
                printf(" [[[ %s\n", server_args->server_id);
                if(DEBUG_MODE) {
                    print_out_hash_in_order(frames, frames_list);
                }

                algorithm_ABD(frames, worker, server_args);
                printf("   ]]]\n\n");
            } else if( strcmp(algorithm_name, SODAW)==0)  {
                printf(" [[[ %s\n",server_args->server_id);
                if(DEBUG_MODE) {
                    print_out_hash_in_order(frames, frames_list);
                }

                algorithm_SODAW(frames, worker, server_args);
                printf("  ]]]\n\n");
            }

            zlist_purge(frames_list);
            zlist_destroy(&frames_list);
            destroy_frames(frames);
            zmsg_destroy(&msg);
        }
    }
    printf("done\n");
}
Пример #5
0
void  ABD_get_max_tag_value_phase(
    char *obj_name,
    unsigned int op_num,
    zsock_t *sock_to_servers,
    unsigned int num_servers,
    RawData *max_tag_value
) {

    // send out the messages to all servers

    char phase[64];
    char tag_str[64];
    unsigned int round;

    Tag *tag;

    zmq_pollitem_t items [] = { { sock_to_servers, 0, ZMQ_POLLIN, 0 } };

    char *types[] = {OBJECT, ALGORITHM, PHASE, OPNUM};
    send_multicast_servers(sock_to_servers, num_servers, types,  4, obj_name, "ABD", GET_TAG_VALUE, &op_num) ;


    unsigned int majority =  ceil(((float)num_servers+1)/2);
    unsigned int responses =0;
    zlist_t *tag_list = zlist_new();

    while (true) {
        //  Tick once per second, pulling in arriving messages

        // zmq_pollitem_t items [] = { { sock_to_servers, 0, ZMQ_POLLIN, 0 } };
        printf("\t\twaiting for  data...\n");
        int rc = zmq_poll(items, 1, -1);
        if(rc < 0 ||  s_interrupted ) {
            printf("Interrupted!\n");
            exit(EXIT_FAILURE);
        }
        printf("\t\treceived data\n");

        if (items [0].revents & ZMQ_POLLIN) {
            zmsg_t *msg = zmsg_recv(sock_to_servers);

            zlist_t *names = zlist_new();
            zhash_t* frames = receive_message_frames_at_client(msg, names);

            //value
            zframe_t *value_frame = (zframe_t *)zhash_lookup(frames, PAYLOAD);
            assert(value_frame !=NULL);

            get_string_frame(phase, frames, PHASE);
            round = get_int_frame(frames, OPNUM);
            get_string_frame(tag_str, frames, TAG);


            if(round==op_num && strcmp(phase, GET_TAG_VALUE)==0) {
                if(DEBUG_MODE) print_out_hash_in_order(frames, names);
                responses++;
                // add tag to list
                tag = (Tag *)malloc(sizeof(Tag));
                string_to_tag(tag_str, tag);
                zlist_append(tag_list, (void *)tag);

                max_tag_value->data = (void *)value_frame;
                max_tag_value->data_size = zframe_size(value_frame);

                if(responses >= majority) { 
                   zlist_purge(names);
                   zlist_destroy(&names);
                   zmsg_destroy (&msg);
                   destroy_frames(frames);
                   break;
                }
                //if(responses >= num_servers) break;
            } else {
                printf("\tOLD MESSAGES : (%s, %d)\n", phase, op_num);

            }
            zmsg_destroy (&msg);
        }
    }
    //comute the max tag now and return
    max_tag_value->tag = get_max_tag(tag_list);

    free_items_in_list(tag_list);
    zlist_destroy(&tag_list);
}
Пример #6
0
///
//  Purge all items from list
void QZlist::purge ()
{
    zlist_purge (self);
    
}
Пример #7
0
JNIEXPORT void JNICALL
Java_org_zeromq_czmq_Zlist__1_1purge (JNIEnv *env, jclass c, jlong self)
{
    zlist_purge ((zlist_t *) (intptr_t) self);
}