To:
cf-dev@xxxxxxxxxxxFrom: Abhijan Bhattacharyya
Sent by: cf-dev-bounces@xxxxxxxxxxx
Date: 03/11/2017 08:08PM
Subject: [cf-dev] Sender thread does not seem to function while setting the timeout to very small value
Hi,
I was doing couple of small experiments and unfortunately failed. Any help will be highly appreciated.
Firstly, I was trying a simple PUT. But before calling the put I set the timeout to very low (see the code snippet below). But nothing goes out from the client.
/*************** code ******************/
client.setTimeout(1);
response = client.put("ABC", MediaTypeRegistry.TEXT_PLAIN);
/****************************************/
If I just make timeout(3), then it works! Any, specific reason to it?
Then, I tried to make the requester not to wait for the response and I tried a quick hack with the logic inside waitForResponse() method inside Request.java as below. But then I see the behaviour of the client becoming unpredictable. At times the request is sent. At times the sender does not work. Seems I am missing something with the synchronization between the receiver and the sender thread.
/************************* Code ****************************/
synchronized (lock) {
/********** This is new ***********/
//brute force - make it not wait//
this.setNoWait(true);
/******************************/
//Abhijan while (this.response == null && !isCanceled() && !isTimedOut() && !isRejected()) {
while (this.response == null && !isCanceled() && !isTimedOut() && !isRejected() &&!isNoWait()) { //New
lock.wait(timeout);
long now = System.currentTimeMillis();
// timeout expired?
if (timeout > 0 && expired <= now) {
// break loop since response is still null
break;
}
}
Response r = this.response;
this.response = null;
return r;
}
/*********************************************************/
/************* setNoWait() *************/
/**
* {@inheritDoc}
*
* If the request should not wait for a response it will wake up all threads that
* are currently waiting for a response.
*/
@Override
public void setNoWait(boolean doNotWait) {
super.setNoWait(doNotWait);
if (doNotWait && lock != null) {
synchronized (lock) {
lock.notifyAll();
}
}
}
/**********************************/
And inside Message.java I introduce the following:
/************** NoWait *********************/
/**
* Checks if this message is ste for no-response. If no-response is set to
* indicate dis-interest in all the responses then the client should not wait.
* TODO: Granularity not considered at this moment.
*
* @return true, if no-response
*/
public boolean isNoWait() {
return doNotWait;
}
public void setNoWait(boolean doNotWait) {
this.doNotWait = doNotWait;
}
/*******************************************/
Regards
Abhijan Bhattacharyya
Associate Consultant
Scientist, Innovation Lab, Kolkata, India
Tata Consultancy Services
Mailto: abhijan.bhattacharyya@xxxxxxx
Website: http://www.tcs.com
____________________________________________
Experience certainty. IT Services
Business Solutions
Consulting
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you