Why does common-pool2 using abandonedConfig have to do it like this: `final AbandonedConfig ac = this.abandonedConfig`? - pool

I read the source code in apache/commons-pool tonight and I found every time when reading the abandonedConfig, the code always is written like this:
final AbandonedConfig ac = this.abandonedConfig;
if (ac != null && ac.getRemoveAbandonedOnBorrow() && (getNumIdle() < 2) &&
(getNumActive() > getMaxTotal() - 3)) {
removeAbandoned(ac);
}
Please tell me why they do that? Why not do something like:
if (abandonedConfig != null && abandonedConfig.getRemoveAbandonedOnBorrow() && (getNumIdle() < 2) &&
(getNumActive() > getMaxTotal() - 3)) {
removeAbandoned(ac);
}

Related

Ionic select is not changing to the correct values on change

I have an ion-select where on change, I need to update values in other ion-select that is related.
The first ion-select is for selecting countries, then according to the specified one, the second ion-select will display the related major cities.
The problem that is cities displayed are always the one of the following array: kuwait_ar except of the country of Kuwait , where the cities are the correct ones kuwait_en.
Here is a stackblitz.
Here is the code for (ionChange):
displayCities()
{
let country = this.formGroup.controls.country.value;
this.cityArray = [];
//console.log(country)
this.cityArray = ((country == "Bahrain" || country == "البحرين") && this.lang=="en")?this.bahrain_cities_en:this.bahrain_cities_ar;
this.cityArray = ((country == "Oman" || country == "عمان") && this.lang=="en")?this.oman_cities_en:this.oman_cities_ar;
this.cityArray = ((country == "Qatar" || country == "قطر") && this.lang=="en")?this.qatar_cities_en:this.qatar_cities_ar;
this.cityArray = ((country == "Saudi Arabia" || country == "المملكة العربية السعودية") && this.lang=="en")?this.ksa_cities_en:this.ksa_cities_ar;
this.cityArray = ((country == "UAE" || country == "الامارات العربية المتحدة") && this.lang=="en")?this.uae_cities_en:this.uae_cities_ar;
this.cityArray = ((country == "Kuwait" || country == "الكويت") && this.lang=="en")?this.kuwait_cities_en:this.kuwait_cities_ar;
//console.log(this.cityArray)
}
Your problem is happening because you are assigning this.cityArray multiple times. The reason "Kuwait" works correctly, is because it is the last one in the list.
Consider when you select "Bahrain":
#1 this.cityArray = ((country == "Bahrain" || country == "البحرين") && this.lang=="en")?this.bahrain_cities_en:this.bahrain_cities_ar;
#2 this.cityArray = ((country == "Oman" || country == "عمان") && this.lang=="en")?this.oman_cities_en:this.oman_cities_ar;
#3 this.cityArray = ((country == "Qatar" || country == "قطر") && this.lang=="en")?this.qatar_cities_en:this.qatar_cities_ar;
#4 this.cityArray = ((country == "Saudi Arabia" || country == "المملكة العربية السعودية") && this.lang=="en")?this.ksa_cities_en:this.ksa_cities_ar;
#5 this.cityArray = ((country == "UAE" || country == "الامارات العربية المتحدة") && this.lang=="en")?this.uae_cities_en:this.uae_cities_ar;
#6 this.cityArray = ((country == "Kuwait" || country == "الكويت") && this.lang=="en")?this.kuwait_cities_en:this.kuwait_cities_ar;
Line #1 correctly sets this.cityArray = this.bahrain_cities_er because your condition (country == "Bahrain" evaluates to true AND this.lang is set to "en"... GOOD
But... Line #2, (country == "Oman" || country == "عمان") evaluates to false, so your are reassigning the value of this.cityArray = this.oman_cities_ar
The same goes for Line #3-#6, thus the last line assigns it to this.kuwait_cities_ar as you have experienced.
Perhaps a switch statement would work better when only once case gets executed.
However, your approach is very complicated. You could structure your definitions of country/city names in a nested array or map, so you can simply "look up" the correct list, rather than "figure it out" based on a selected value. You could also two separate lists, one for each language, then simply swap them out based on the current language.

pass decimal column value to populate results from a table using linq query

I have a product table with 20 column. There is a column 'Width' which is decimal data type. I have been calling particular width value in web api controller to populate results. As an example,width values are like below:
Width values
1 0.0015
2 1.0000
3 0.0063
4 1.0100
5 2.0000
6 2.0630
public HttpResponseMessage GetclassByWidthList(Decimal cWidth)
{
using (CrossReferenceTool1Entities cls1 = new CrossReferenceTool1Entities())
{
**var query = (from u in cls1.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && **u.Width == cWidth**) select u.Class).Distinct().ToList()**;
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
}
method is working fine. results are reflected if width value is "1.0000" OR "2.0000" but for other values of width it is not populating any result.
Please help me on above query where other decimal values with precision will populate result.
i have tried in browser to populate result:
1.
http://localhost:55481/api/KendoCascading/GetclassByWidthList/1 - result is poupulating
`http://localhost:55481/api/KendoCascading/GetclassByWidthList/1.01 - http-404 error showing
For debugging, your decimal data of Cwidth is being truncated, Please check
As per Ehasanul's suggestion i Just modified my method with putting extra "/" last of that route path
[Route("**api/KendoCascading/GetclassByWidthList/{cWidth:decimal}/**")]
public HttpResponseMessage GetclassByWidthList(decimal cWidth)
{
using (CrossReferenceTool1Entities cls1 = new CrossReferenceTool1Entities())
{
var query = (from u in cls1.Products where (u.PrivateOnly == false && u.SelectionTool == true && u.ProductTypeID == 2 && (u.ProductFamilyID == 11 || u.ProductFamilyID == 12 || u.ProductFamilyID == 58 || u.ProductFamilyID == 59 || u.ProductFamilyID == 92) && u.Width == cWidth) select u.Class).Distinct().ToList();
HttpResponseMessage res;
res = Request.CreateResponse(HttpStatusCode.OK, query);
return res;
}
}
call that url in my angular service http.get method with adding extra "/" in last.
this.getclsWidthList3 = function (cWidth) {
var res;
if (cWidth !== 0.0000) {
res = $http.get("/api/KendoCascading/GetclassByWidthList"+ "/"+ cWidth+"/");
return res;
}
};
and its working great.

PIC 24F I2C slave issue

PIC 24F as an I2C slave has lock up issues sending multiple data bytes to the master (MASTER READ).
The PIC (specifically 24FJ128GB202) as an I2C slave receiving data (MASTER WRITE) works perfectly, passing all unit tests. (address only, address and register, address register single data and multiple data auto increment)
My slave code can handle address-only and reading a single byte. It hangs on multiple reads made from the master (auto increment).
I used the Microchip app note as the basis of my code, as well as looking at the Code Composer generated code.
Initialization:
void I2C1_Initialize(void)
{
I2C1ADD = I2C1_SLAVE_ADDRESS;
I2C1MSK = I2C1_SLAVE_MASK;
I2C1CONL = 0x8200;
I2C1CONH = 0x0000;
I2C1STAT = 0x0000;
// clear the master interrupt flag
IFS1bits.SI2C1IF = 0;
// enable the master interrupt
IEC1bits.SI2C1IE = 1;
}
Interrupt Write:
// clear the interrupt
_SI2C1IF = 0;
// Write from Master to Slave - Address
// S = 1, D_A = 0, R_W = 0, BF = 1
if ( (I2C1STATbits.S == 1) && (I2C1STATbits.D_A == 0) && (I2C1STATbits.R_W == 0) && (I2C1STATbits.RBF == 1) )
{
myI2CAd = I2C1RCV;
mySTATE = 0;
}
// Write from Master to Slave - Data
// S = 1, D_A = 1, R_W = 0, BF = 1
if ( (I2C1STATbits.S == 1) && (I2C1STATbits.D_A == 1) && (I2C1STATbits.R_W == 0) && (I2C1STATbits.RBF == 1))
{
mySTATE++;
if(mySTATE == 1)
{
myREGISTER = I2C1RCV;
// limit register to MAX
if(myREGISTER > I2CMAXREGISTER) myREGISTER = I2CMAXREGISTER;
}
if(mySTATE == 2)
{
myDATA = I2C1RCV;
shelfregister[myREGISTER] = myDATA;
}
if(mySTATE > 2)
{
myDATA = I2C1RCV;
// limit register to MAX
if(myREGISTER < I2CMAXREGISTER) myREGISTER++;
shelfregister[myREGISTER] = myDATA;
}
}
Interrupt Read:
// Read from Slave to Master - Address
// S = 1, D_A = 0, R_W = 1, BF = 0
if ( (I2C1STATbits.S == 1) && (I2C1STATbits.D_A == 0) && (I2C1STATbits.R_W == 1) && (I2C1STATbits.TBF == 0) )
{
myI2CAd = I2C1RCV;
I2C1TRN = shelfregister[myREGISTER];
I2C1CONLbits.SCLREL = 1;
if(myREGISTER < I2CMAXREGISTER) myREGISTER++;
}
The code generated by the Code Composer for slave operation is quite similar and has the same issue.
My main question is how to handle multiple reads from the master, not just the single byte that is handled in this read function. It should involve checking I2CSTATbits.ACKSTAT, but the timing of that bit is unclear to me since it should happen 9 clocks after the byte is in the register, but there is no bit to indicate that point in time. Any guidance appreciated.

Drupal redirection

I am working on a project and there is a custom module in that which have the drupal redirection code in it here is the code :
if (empty($_GET['destination'])
&& isset($_COOKIE["abc"])
&& $_COOKIE["abc"]<>''
&& ($_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = "xyz" ;
}
}
Can anyone please explain the 3rd line of code or maybe all of it. Thanks
I have added comments to the source. <> is the same as !=. See PHP Comparison Opperators.
if (empty($_GET['destination']) //Check if $_GET['destination'] is empty.
&& isset($_COOKIE["abc"]) //Check if $_COOKIE["abc"] is not NULL.
&& $_COOKIE["abc"]<>'' //Check if $_COOKIE["abc"] does not equal an empty string.
&& ($_POST['form_id'] != 'user_pass_reset')) //Check if $_POST['form_id'] is not 'user_pass_reset'
{
$_GET['destination'] = "xyz" ; //Set $_GET['destination'] to "xyz"
}
}
should be modify a little bit in second line
if (empty($_GET['destination']) //Check if $_GET['destination'] is empty.
&& isset($_COOKIE["abc"]) //Check if $_COOKIE["abc"] is EXISTS.
&& $_COOKIE["abc"]<>'' //Check if $_COOKIE["abc"] does not equal an empty string.
&& ($_POST['form_id'] != 'user_pass_reset')) //Check if $_POST['form_id'] is not 'user_pass_reset'
{
$_GET['destination'] = "xyz" ; //Set $_GET['destination'] to "xyz"
}
}

Linq to Entities: multiple criteria query for one table

using (WinFileContextContainer c = new WinFileContextContainer())
{
IQueryable<File> dbfiles = (from f in c.File
where //(f.Category.Any((category => category.name == categoryname)) &&
f.alive //&&
//f.description == "" &&
//f.Category.Count == 1)
select f);
// the rest....
}
The query works only as it is now - I left just one criteria (the rest is in comment sections). But I want the other criteria to be taken into account too. I tried with multiple "where"s :D or all the criteria in brackets with one "where", but still no success. I'm kinda new to LINQ so any help is appreciated. Thanks in advance !
Finally got it to work:
IQueryable<File> dbfiles =
c.File.Where(f => f.Category.Any(cat => cat.name == categoryname) &&
f.alive &&
f.description == null &&
f.Category.Count == 1);