I searched for an answer to this question on SO and Google but couldn't find a proper solution so far.
I'm currently working on a LayerManager in a graph routing problem. The manager is responsible for providing and resetting a fixed set of layers.
I wanted to implement the Consumer-Producer pattern with a blocking list, so that incoming routing requests are blocked as long no free layer is available. So far I only found a blocking queue but since we don't need FIFO, LIFO but random access a queue doesn't really work. To be a little more precise, something like this should be possible:
/* this should be blocking until a layer becomes available */
public Layer getLayer(){
for ( Layer layer : layers ) {
if ( layer.isUnused() && layer.matches(request) )
return layers.pop(layer);
}
}
Is there any way to achieve this?