Reputation: 377
I have an application which is used read and write data to different storage locations. There is a concept of storage pool that contains multiple storage devices. Only one device can be active at a time for writing content. Intially the first storage device in a pool is considered active. As soon as it gets full or inaccessible, the next device should become active.
I have a class ProviderManager with following interface.
public class DeviceManager
{
public StorageDevice CurrentDevice {get; private set;}
public bool MoveNext() { // get device on next index }
}
The problem is that we move the next device only when there is an exception that means its either filled or inaccessible. There could be a situation when multiple threads fail to write on a device and DeviceManager.MoveNext() is called by each thread instead of only one of them calling it.
Although, I can manage it but that involves some dirty work. Looking for a nice way to manage this.
Your ideas?
Upvotes: 2
Views: 156
Reputation: 69260
Why do you even expose MoveNext
to the caller? From your description I think that DeviceManager
should be responsible for handling errors and for moving on to the next device.
Is there some way that you can get DeviceManager
to intercept the write exceptions?
Upvotes: 0
Reputation: 798
MoveNext()
{
if(Current.isAccessible)
return;
<....>
}
of course MoveNext call should be synchronized
Upvotes: 0
Reputation: 273274
How about
public bool MoveNext(StorageDevice oldDevice)
As long as MoveNext is thread-safe, just check if Current == oldDevice
before changing.
Upvotes: 4