diff options
author | Keuin <[email protected]> | 2020-10-04 13:43:15 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2020-10-04 13:43:15 +0800 |
commit | e59bdf4ac0b66ce683be1bbc36852bfce6f70a63 (patch) | |
tree | 6c8b97f97af857d2740e7b79d46349cc83a8c7dd /src/main/java/com/keuin/kbackupfabric/operation/abstracts | |
parent | d9c2af035ac2edb68bc8b6a1f94b7c772c3509c8 (diff) |
Pump up
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/abstracts')
8 files changed, 31 insertions, 19 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractAsyncOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractAsyncOperation.java index f1a19de..bb0c704 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractAsyncOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractAsyncOperation.java @@ -1,6 +1,10 @@ package com.keuin.kbackupfabric.operation.abstracts; -public abstract class AbstractAsyncOperation extends AbstractSerializedOperation { +/** + * A basic async operation, but not invokable. + * If you want a invokable interface (InvokableOperation), use InvokableAsyncOperation instead. + */ +public abstract class AbstractAsyncOperation extends AbstractSerialOperation { private final Thread thread; private final String name; @@ -14,7 +18,7 @@ public abstract class AbstractAsyncOperation extends AbstractSerializedOperation /** * Start the worker thread. * - * @return true if succeed starting, false if already started. + * @return true if succeed starting, false if this operation is already started, or the sync method failed. */ @Override protected final boolean operate() { @@ -30,13 +34,16 @@ public abstract class AbstractAsyncOperation extends AbstractSerializedOperation /** * Implement your async operation here. - * When this method returns, the operation must finish. + * After starting the operation, this method will be run in another thread after the sync method returns. + * When this method returns, the operation must have been finished. */ protected abstract void async(); /** * If necessary, implement your sync operations here. * It will be invoked before starting the async thread. + * If this method failed, the async method will not be invoked. + * @return whether this method succeed. */ protected boolean sync() { return true; diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java index 15b72c9..b9638a8 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractBlockingOperation.java @@ -2,7 +2,7 @@ package com.keuin.kbackupfabric.operation.abstracts; import com.keuin.kbackupfabric.operation.abstracts.i.Blocking; -public abstract class AbstractBlockingOperation extends AbstractSerializedOperation implements Blocking { +public abstract class AbstractBlockingOperation extends AbstractSerialOperation implements Blocking { private static final Object sync = new Object(); private static boolean isBlocking = false; diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractConfirmableOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractConfirmableOperation.java index 0a56008..e234ddb 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractConfirmableOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractConfirmableOperation.java @@ -1,6 +1,6 @@ package com.keuin.kbackupfabric.operation.abstracts; -public abstract class AbstractConfirmableOperation extends AbstractSerializedOperation { +public abstract class AbstractConfirmableOperation extends AbstractSerialOperation { public final boolean confirm() { return operate(); diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractSerialOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractSerialOperation.java new file mode 100644 index 0000000..92dfb53 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractSerialOperation.java @@ -0,0 +1,17 @@ +package com.keuin.kbackupfabric.operation.abstracts; + +/** + * The most basic operation abstraction. + * This class represents an serial operation, which is limited in a non-public method. + * Note that the operation is not invokable by default, you should use InvokableOperation in order to provide a public method for users to call. + */ +public abstract class AbstractSerialOperation { + /** + * Do your operation here. + * This method is not designed to be public. + * When this method returns, the operation must have been finished. + * + * @return whether the operation succeed. + */ + protected abstract boolean operate(); +} diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractSerializedOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractSerializedOperation.java deleted file mode 100644 index 3168e8c..0000000 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/AbstractSerializedOperation.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.keuin.kbackupfabric.operation.abstracts; - -public abstract class AbstractSerializedOperation { - /** - * Do your operation here. - * This method is not designed to be public. - * When this method returns, the operation must have finished. - * - * @return the stat code. - */ - protected abstract boolean operate(); -} diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableAsyncOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableAsyncOperation.java index 518f670..707e3c5 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableAsyncOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableAsyncOperation.java @@ -4,7 +4,6 @@ public abstract class InvokableAsyncOperation extends InvokableOperation { private final AbstractAsyncOperation asyncOperation; - public InvokableAsyncOperation(String name) { asyncOperation = new AbstractAsyncOperation(name) { @Override diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableBlockingOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableBlockingOperation.java index b1a3748..508c676 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableBlockingOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableBlockingOperation.java @@ -27,6 +27,7 @@ public abstract class InvokableBlockingOperation extends InvokableOperation impl operation.block(blockState); } + @Deprecated protected void noUnblocking(boolean b) { operation.noUnblocking(b); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableOperation.java index 47c1ca8..19105f8 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/abstracts/InvokableOperation.java @@ -2,7 +2,7 @@ package com.keuin.kbackupfabric.operation.abstracts; import com.keuin.kbackupfabric.operation.abstracts.i.Invokable; -public abstract class InvokableOperation extends AbstractSerializedOperation implements Invokable { +public abstract class InvokableOperation extends AbstractSerialOperation implements Invokable { public boolean invoke() { return operate(); } |