AXIS2_EXTERN axis2_status_t AXIS2_CALL axis2_amqp_receiver_init( axis2_transport_receiver_t* receiver, const axutil_env_t* env, axis2_conf_ctx_t* conf_ctx, axis2_transport_in_desc_t* in_desc) { axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL; axutil_property_t* property = NULL; const axis2_char_t* broker_ip = NULL; int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int)); *broker_port = AXIS2_QPID_NULL_CONF_INT; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); receiver_resource_pack = AXIS2_AMQP_RECEIVER_TO_RESOURCE_PACK(receiver); receiver_resource_pack->conf_ctx = conf_ctx; /* Set broker IP */ broker_ip = axis2_amqp_util_get_in_desc_conf_value_string(in_desc, env, AXIS2_AMQP_CONF_QPID_BROKER_IP); if(!broker_ip) { broker_ip = AXIS2_QPID_DEFAULT_BROKER_IP; } property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, (void*)broker_ip); axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property); /* Set broker port */ *broker_port = axis2_amqp_util_get_in_desc_conf_value_int(in_desc, env, AXIS2_AMQP_CONF_QPID_BROKER_PORT); if(*broker_port == AXIS2_QPID_NULL_CONF_INT) { *broker_port = AXIS2_QPID_DEFAULT_BROKER_PORT; } property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, (void*)broker_port); axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property); return AXIS2_SUCCESS; }
AXIS2_EXTERN axis2_char_t* AXIS2_CALL axis2_amqp_util_conf_ctx_get_dual_channel_queue_name( axis2_conf_ctx_t* conf_ctx, const axutil_env_t* env) { axutil_property_t* property = NULL; axis2_char_t* queue_name = NULL; axis2_char_t* value = NULL; /* Get property */ property = axis2_conf_ctx_get_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME); if(!property) /* Very first call */ { property = axutil_property_create(env); axis2_conf_ctx_set_property(conf_ctx, env, AXIS2_AMQP_CONF_CTX_PROPERTY_QUEUE_NAME, property); } /* Get queue name */ value = (axis2_char_t*)axutil_property_get_value(property, env); /* AMQP listener and the sender are the two parties that are * interested in the queue. Either party can create the queue. * If the queue is already created by one party, "value" is * not NULL. If "value" is NULL, that mean the caller of * this method is supposed to create the queue */ if(value) { queue_name = (axis2_char_t*)AXIS2_MALLOC(env->allocator, axutil_strlen(value) + 1); strcpy(queue_name, value); /*axutil_property_set_value(property, env, NULL);*/ } else { /* Create new queue name */ queue_name = axutil_stracat(env, AXIS2_AMQP_TEMP_QUEUE_NAME_PREFIX, axutil_uuid_gen(env)); /* Put queue name in the conf_ctx so that the sender will know */ axutil_property_set_value(property, env, (void*)queue_name); } return queue_name; }
AXIS2_EXTERN axis2_transport_receiver_t* AXIS2_CALL axis2_amqp_receiver_create( const axutil_env_t* env, const axis2_char_t* repo, const axis2_char_t* qpid_broker_ip, int qpid_broker_port) { AXIS2_ENV_CHECK(env, NULL); axis2_amqp_receiver_resource_pack_t* receiver_resource_pack = NULL; receiver_resource_pack = (axis2_amqp_receiver_resource_pack_t*)AXIS2_MALLOC(env->allocator, sizeof(axis2_amqp_receiver_resource_pack_t)); if(!receiver_resource_pack) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); return NULL; } receiver_resource_pack->receiver.ops = &amqp_receiver_ops; receiver_resource_pack->qpid_receiver = NULL; receiver_resource_pack->conf_ctx = NULL; receiver_resource_pack->conf_ctx_private = NULL; if(repo) { /** * 1. We first create a private conf ctx which is owned by this server * we only free this private conf context. We should never free the * receiver_impl->conf_ctx because it may be owned by any other object which * may lead to double free. * * 2. The Qpid broker IP and port are set in conf_ctx at two different places. * If the repo is specified, they are set here. Otherwise, they are set * in axis2_amqp_receiver_init method. */ axutil_property_t* property = NULL; const axis2_char_t* broker_ip = NULL; int* broker_port = (int*)AXIS2_MALLOC(env->allocator, sizeof(int)); *broker_port = AXIS2_QPID_NULL_CONF_INT; receiver_resource_pack->conf_ctx_private = axis2_build_conf_ctx(env, repo); if(!receiver_resource_pack->conf_ctx_private) { axis2_amqp_receiver_free((axis2_transport_receiver_t *)receiver_resource_pack, env); return NULL; } /* Set broker IP */ broker_ip = qpid_broker_ip ? qpid_broker_ip : AXIS2_QPID_DEFAULT_BROKER_IP; property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, (void*)broker_ip); axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_IP, property); /* Set broker port */ *broker_port = (qpid_broker_port != AXIS2_QPID_NULL_CONF_INT) ? qpid_broker_port : AXIS2_QPID_DEFAULT_BROKER_PORT; property = axutil_property_create_with_args(env, AXIS2_SCOPE_APPLICATION, 0, 0, (void*)broker_port); axis2_conf_ctx_set_property(receiver_resource_pack->conf_ctx_private, env, AXIS2_AMQP_CONF_CTX_PROPERTY_BROKER_PORT, property); receiver_resource_pack->conf_ctx = receiver_resource_pack->conf_ctx_private; } return &(receiver_resource_pack->receiver); }
int AXIS2_CALL service_admin_counter_get_last_count ( const axutil_env_t *env, axis2_msg_ctx_t *msg_ctx, axis2_char_t *svc_name, axis2_char_t *op_name) { int *count = NULL; axutil_hash_t *last_counts = NULL; axutil_property_t *property = NULL; axis2_conf_ctx_t *conf_ctx = NULL; conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env); if(svc_name && op_name) { axis2_char_t *key = NULL; key = axutil_strcat(env, svc_name, "-", op_name, NULL); property = axis2_conf_ctx_get_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_OPERATION_COUNT); if(!property) { last_counts = axutil_hash_make(env); property = axutil_property_create_with_args(env, AXIS2_TRUE, AXIS2_SCOPE_APPLICATION, service_admin_counter_last_counts_free_void_arg, last_counts); axis2_conf_ctx_set_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_OPERATION_COUNT, property); } else { last_counts = axutil_property_get_value(property, env); } count = axutil_hash_get(last_counts, key, AXIS2_HASH_KEY_STRING); if(count) { AXIS2_FREE(env->allocator, key); } else { count = AXIS2_MALLOC(env->allocator, sizeof(int)); *count = 0; axutil_hash_set(last_counts, key, AXIS2_HASH_KEY_STRING, count); } } else if(svc_name) { property = axis2_conf_ctx_get_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_SERVICE_COUNT); if(!property) { last_counts = axutil_hash_make(env); property = axutil_property_create_with_args(env, AXIS2_TRUE, AXIS2_SCOPE_APPLICATION, service_admin_counter_last_counts_free_void_arg, last_counts); axis2_conf_ctx_set_property(conf_ctx, env, SERVICE_ADMIN_COUNTER_LAST_SERVICE_COUNT, property); } else { last_counts = axutil_property_get_value(property, env); } count = axutil_hash_get(last_counts, svc_name, AXIS2_HASH_KEY_STRING); if(!count) { count = AXIS2_MALLOC(env->allocator, sizeof(int)); *count = 0; axutil_hash_set(last_counts, axutil_strdup(env, svc_name) , AXIS2_HASH_KEY_STRING, count); } } return *count; }