axis-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sahan Gamage" <sah...@gmail.com>
Subject Re: [Axis2] Sharing services among threads
Date Wed, 18 Oct 2006 05:59:53 GMT
Hi Ishan,

are you using the same service to publish and subscribe ?
The difference (major) in the first code and the second client code
(which succeeds) is, the first one assumes it is the same service,
where in the second one it is not.
Can you send the endpoint url you use for the second client creation ?
Also I believe you are not writing to "svc" and to the hash map inside
the publisher threads. if you do you must synchronize manually. svc
object and axis2_util hash map is not thread safe IIRC.

-sahan


On 10/18/06, Ishan De Silva <ishan.asf@gmail.com> wrote:
> Hi,
>
> 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);
>
> param = AXIS2_SVC_GET_PARAM(svc, env, SUBSCRIBER_STORE);
>
> 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,
> sizeof(publisher_data_t));
>
> 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 =
> AXIS2_THREAD_POOL_GET_THREAD(env->thread_pool,
>      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?
>
> Thanks,
> Ishan.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-c-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-c-dev-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-c-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-c-dev-help@ws.apache.org


Mime
View raw message