Help - Avoiding access to the same file

8 views
Skip to first unread message

K Cheng

unread,
May 9, 2016, 3:29:30 AM5/9/16
to Concurrent Ruby
Hi All,

I'm quite new to the concept of Java/Clojure concurrency and synchronisation and I'm running into an issue where I think there is a concurrency solution but I'm not 100% sure which solution or how to implement it.

Basically I have a dispatcher class which calls a duck type against multiple classes. Each of these classes can do various tasks such as setup apt-repos and perform an apt-get update.

The problem I have is in a particular scenario, these classes are all actually against the same remote server due to the environment type/setup and as such tasks such as writing and moving a file and performing apt-get update isn't so great when run lots of times on the same server (Note: most of the time, these actually run on different servers hence why concurrently running at the same time isn't normally an issue).

As an example of the action, basically I perform the following:

  • Connect to server
  • Write data to a tmp file (due to sudo rights)
  • Move this file with the relevant rights to /etc/apt/sources.list.d/new_file.list
  • Perform apt-get update

Is there a way to ensure that only one of the classes performs the action and subjects the rest of the classes to a wait for this particular method? I thought it might be a synchronize, but it doesn't appear to be what I am after.

I'm hoping to avoid putting a messy check for the environment type inside each of the classes themselves and performing various sleeps and checks of files and repos.


Hopefully the above isn't too horrible to understand and any help would be greatly appreciated.

Cheers

Karen
Reply all
Reply to author
Forward
0 new messages