-
1. Re: Locking in DeploymentRepository
starksm64 Mar 6, 2009 3:44 PM (in response to alesj)Why doesn't just calling setScanEnabled suspend/resume the scanning?
-
2. Re: Locking in DeploymentRepository
jason.greene Mar 6, 2009 3:46 PM (in response to alesj)It sounds like you need a simple flag, or alternatively a latch instead of a lock:
http://anonsvn.jboss.org/repos/jbosscache/core/trunk/src/main/java/org/jboss/cache/util/concurrent/ReclosableLatch.java
If you really want a lock that can be shared across threads, in order to conform to the Lock interface, you need to use a thread local. Manik and I created one specific to jboss cache transactional locks here (you can derive from it if you like):
http://anonsvn.jboss.org/repos/jbosscache/core/trunk/src/main/java/org/jboss/cache/util/concurrent/locks/OwnableReentrantLock.java -
3. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 3:49 PM (in response to alesj)How does this fit with in-progress scan()?
As I think this will not cause scan to stop,
hence it might pick up partial deployments
since suspend would return immediately. -
4. Re: Locking in DeploymentRepository
starksm64 Mar 6, 2009 3:53 PM (in response to alesj)"alesj" wrote:
How does this fit with in-progress scan()?
As I think this will not cause scan to stop,
hence it might pick up partial deployments
since suspend would return immediately.
It does cancel any inprogress scan, but how quickly that ends depends on the Future. Your looking to set the HDScanner in a known state of scanning disabled and any in progress scan completed/disabled? -
5. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 4:00 PM (in response to alesj)"scott.stark@jboss.org" wrote:
Your looking to set the HDScanner in a known state of scanning disabled and any in progress scan completed/disabled?
Looking from Tools usage, I want to suspend HD thread to pick up
any partial deployments I might currently deploy.
Looking at HDScanner's activeScan I think I might get away with
calling cancel on it, and spinning a bit around until it's done (activeScan.isDone == true). -
6. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 4:05 PM (in response to alesj)"alesj" wrote:
Looking at HDScanner's activeScan I think I might get away with
calling cancel on it, and spinning a bit around until it's done (activeScan.isDone == true).public synchronized void suspend() { suspended = (activeScan != null); if (activeScan != null) { activeScan.cancel(false); while(activeScan.isDone() == false) { try { Thread.sleep(100); } catch (InterruptedException ignored) { } } activeScan = null; } } public synchronized void resume() { if (suspended) { start(); } suspended = false; }
Or too hack-ish? :-) -
7. Re: Locking in DeploymentRepository
starksm64 Mar 6, 2009 4:19 PM (in response to alesj)adding suspend/resume ops that essentially mirror stop/start but wait until the state of the scanner has changed seems fine. The details of the impl can be hacky for now.
-
8. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 4:45 PM (in response to alesj)"alesj" wrote:
The issue is how to impl that, since Tools invocations will call from two diff threads,
and most Lock impls don't support that.
(btw: this should also be fixed in 5_0's SerializableDeploymentRepository).
How come this didn't pop-up before?
As PS tests should see this, when using DeploymentManager to do remote deployment.
Or is the thread that takes the stream, that does the suspend and resume?
I'll check this out once I properly port JBAS-6330 to 5_0. -
9. Re: Locking in DeploymentRepository
jason.greene Mar 6, 2009 5:22 PM (in response to alesj)"alesj" wrote:
Looking at HDScanner's activeScan I think I might get away with
calling cancel on it, and spinning a bit around until it's done (activeScan.isDone == true)
Or too hack-ish? :-)
Ugh. If you are waiting on a future, use get(), don't spin. Also, if a cancellation is successful, then isDone will immediately be true, even if the thread for the task is still running. -
10. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 5:25 PM (in response to alesj)I think the future is an impl detail there.
Scott?"jason.greene@jboss.com" wrote:
Also, if a cancellation is successful, then isDone will immediately be true, even if the thread for the task is still running.
How to avoid this? -
11. Re: Locking in DeploymentRepository
starksm64 Mar 6, 2009 5:29 PM (in response to alesj)"alesj" wrote:
I think the future is an impl detail there.
Scott?
Its part of the HDScanner api in that it uses a ScheduledExecutorService via injection. If one is not provided it creates one. -
12. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 5:46 PM (in response to alesj)The question is more "can I get a hold of that Future instance",
then, like Jason says, it would be just a matter of calling
Future::get to know when we're done with cancel. -
13. Re: Locking in DeploymentRepository
starksm64 Mar 6, 2009 5:56 PM (in response to alesj)The ScheduledFuture is the activeScan variable. It could be exposed as a read-only property that would be null if scanning is not enabled.
-
14. Re: Locking in DeploymentRepository
alesj Mar 6, 2009 6:14 PM (in response to alesj)Eh, I should read the code better. :-(
As you said, activeScan == Future. :-)