This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor future utils, extracted AbstractTaskFuture2.
- Loading branch information
1 parent
a350d37
commit 624ae0f
Showing
8 changed files
with
124 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
melnorme_util/src/melnorme/utilbox/concurrency/MonitorTaskFuture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 Bruno Medeiros and other Contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Bruno Medeiros - initial API and implementation | ||
*******************************************************************************/ | ||
package melnorme.utilbox.concurrency; | ||
|
||
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull; | ||
|
||
import melnorme.utilbox.concurrency.ICancelMonitor.CancelMonitor; | ||
import melnorme.utilbox.concurrency.ICancelMonitor.CompositeCancelMonitor; | ||
|
||
/** | ||
* A {@link AbstractTaskFuture2} with a cancellation monitor. | ||
*/ | ||
public abstract class MonitorTaskFuture<RET> | ||
extends AbstractTaskFuture2<RET> | ||
{ | ||
|
||
/** The cancel monitor for this Future */ | ||
private final CancelMonitor cancelMonitor; | ||
|
||
public MonitorTaskFuture() { | ||
this(new CancelMonitor()); | ||
} | ||
|
||
public MonitorTaskFuture(ICancelMonitor cancelMonitor) { | ||
this(new CompositeCancelMonitor(cancelMonitor)); | ||
} | ||
|
||
public MonitorTaskFuture(CancelMonitor cancelMonitor) { | ||
this.cancelMonitor = assertNotNull(cancelMonitor); | ||
} | ||
|
||
public CancelMonitor getCancelMonitor() { | ||
updateCancellationFromMonitor(); | ||
return cancelMonitor; | ||
} | ||
|
||
protected void updateCancellationFromMonitor() { | ||
boolean monitorCancelled = cancelMonitor.isCancelled(); | ||
if(monitorCancelled && super.isCancelled() == false) { | ||
tryCancel(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isTerminated() { | ||
updateCancellationFromMonitor(); | ||
return super.isTerminated(); | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
updateCancellationFromMonitor(); | ||
return super.isCancelled(); | ||
} | ||
|
||
@Override | ||
protected void handleCancellation() { | ||
cancelMonitor.cancel(); | ||
super.handleCancellation(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters