while ( true ) {
slot = slotMap.get(data.getSlotLabel());
if ( slot!=null ) {
break; // don't wait if we got a slot now
} else if ( !slotsBeingCreated.contains(data.getSlotLabel()) ) {
throw new CATokenOfflineException(intres.getLocalizedMessage("caadmin.errorcreatetoken")); // thread creating slot failed
}
// wait until another thread has created the slot
try {
slotsBeingCreated.wait();
} catch (InterruptedException e) {
throw new Error( "This should never happen.", e);
}
// the slot should now have been created by another thread
}
} else {
try {
slotsBeingCreated.add(data.getSlotLabel());// show that this thread is creating the slot
slot = data.getNewP11Slot();
slotMap.put(data.getSlotLabel(), slot);
} finally {
if ( slot==null ) {
slotsBeingCreated.remove(data.getSlotLabel());// show that creating the slot failed
}
slotsBeingCreated.notifyAll();// notify that the slot is now created
if ( slot==null ) {
throw new CATokenOfflineException(intres.getLocalizedMessage("caadmin.errorcreatetoken"));
}
}
Set<P11Slot> libSet = libMap.get(data.getLibName());
if (libSet==null) {
libSet=new HashSet<P11Slot>();