Skip to content

Commit

Permalink
Finally fixed #336 - thanks JCF
Browse files Browse the repository at this point in the history
  • Loading branch information
marcanpilami committed Nov 21, 2018
1 parent 1955d16 commit 374efa7
Showing 1 changed file with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DiscreteResourceManager extends ResourceManagerBase
private class Token
{
private AtomicBoolean free = new AtomicBoolean(true);
private Integer jiId = null;
private int jiId = 0;
}

private int defaultConsumption;
Expand Down Expand Up @@ -141,7 +141,6 @@ BookingStatus bookResource(JobInstance ji, DbConn cnx)
{
for (Token e : booked.values())
{
e.jiId = null;
e.free.set(true);
}
return BookingStatus.FAILED; // If here there are items available, just not enough.
Expand All @@ -154,35 +153,15 @@ BookingStatus bookResource(JobInstance ji, DbConn cnx)
}

@Override
synchronized void releaseResource(JobInstance ji)
void releaseResource(JobInstance ji)
{
if (ji == null)
{
throw new JqmInvalidRequestException("JI cannot be null");
}

int released = 0;
for (Token e : this.tokenRepository.values())
{
if (e == null || e.free == null || e.jiId == null)
{
continue; // Happens when the token has just been created - not an issue.
}
try
{
if (!e.free.get() && e.jiId == ji.getId())
{
e.jiId = null;
e.free.set(true);
released++;
}
}
catch (NullPointerException e2)
if (!e.free.get() && e.jiId == ji.getId())
{
// For bug search.
jqmlogger.error("TOKEN : " + e.toString());
jqmlogger.error("TOKEN FREE " + e.free);
throw new JqmRuntimeException("some NPE where there should be none", e2);
e.free.set(true);
released++;
}
}

Expand Down

0 comments on commit 374efa7

Please sign in to comment.