axis-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ishan De Silva <>
Subject [Axis2] Sharing services among threads
Date Wed, 18 Oct 2006 05:16:38 GMT

I have a problem of sharing a single service among two threads.I 
encountered this problem when developing a sample WS-Eventing publisher 
service. This service engages the Savan (WS-Eventing implementation) module.

This is the scenario.

A client sends a Subscribe request and the Savan in-handler captures 
this request. It then creates a subscriber object and attaches that to a 
hash map in the service.

axis2_svc_t *svc = NULL;
axis2_param_t *param = NULL;
axis2_hash_t *store = NULL;
savan_subscriber_t *subscriber = NULL;

svc = AXIS2_MSG_CTX_GET_SVC(msg_ctx, env);


store = (axis2_hash_t*)AXIS2_PARAM_GET_VALUE(param, env);

/* Extract info from incoming msg and create a subscriber */
subscriber = savan_sub_processor_get_subscriber_from_msg(env, msg_ctx);

/* Store the created subscriber in the svc */
axis2_hash_set(store, SAVAN_SUBSCRIBER_GET_ID(subscriber, env),
     AXIS2_HASH_KEY_STRING, subscriber);

Then this service spawns a thread which would periodically publish some 
test events. This is done in the invoke function of the service skeleton.

When spawning, I pass the current configuration context and the service 
to this thread as follows.

publisher_data_t *data = AXIS2_MALLOC(env->allocator, 				 

data->env = (axis2_env_t*)env;
data->svc = AXIS2_MSG_CTX_GET_SVC(msg_ctx, env);
data->conf_ctx = AXIS2_MSG_CTX_GET_CONF_CTX(msg_ctx, env);

axis2_thread_t *worker_thread = 
     publisher_worker_func, (void*)data);
if(NULL == worker_thread)
     printf("failed to create thread");
     return AXIS2_FAILURE;

AXIS2_THREAD_POOL_THREAD_DETACH(env->thread_pool, worker_thread);

Inside the thread, I use the passed in conf context and the service to 
create a service client.

publisher_data_t *mydata = (publisher_data_t*)data;
main_env = mydata->env;
conf_ctx = mydata->conf_ctx;
svc = mydata->svc;

env = axis2_init_thread_env(main_env);

This is how the service client is created:

svc_client = axis2_svc_client_create_with_conf_ctx_and_svc(env, path, 
conf_ctx, svc);

ret_node = AXIS2_SVC_CLIENT_SEND_RECEIVE(svc_client, env, test_node);

test_node is the dummy data that I want to publish.

The problem is that this call to SEND_RECEIVE fails at the following 
code. (svc_client.c:1007)

op = AXIS2_SVC_GET_OP_WITH_QNAME(svc_client_impl->svc, env, op_qname);

if (!op)
     /*TODO:error - svc does not have the operation*/
     return NULL;

However, if I create the service client without using the conf context 
and the service passed in to the thread, then the SEND_RECEIVE succeeds. 
But then that service is a *separate* instance and therefore, it doesn't 
have the hash map I created above.

svc_client = axis2_svc_client_create(env, path);

What is wrong here?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message