-
Notifications
You must be signed in to change notification settings - Fork 1
feature/contextwindowclosedcheck #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
415f773
0cdf05a
ed2cd05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,13 +87,18 @@ public <R> R performTask(final HibernateStorage.@NonNull ResultTask<T, R> task) | |
| final R result = task.execute(taskContext); | ||
|
|
||
| transaction.commit(); | ||
| // marks context closed soo no context actions are done in queue | ||
| taskContext.markClosed(); | ||
| // execute tasks after transaction was successfully committed | ||
| taskContext.executeTasks(); | ||
|
|
||
| return result; | ||
| } catch (final Exception e) { | ||
| if (transaction.isActive()) { | ||
| transaction.rollback(); | ||
|
|
||
| taskContext.markClosed(); | ||
|
|
||
| taskContext.executeRollbackTasks(); | ||
| } | ||
|
|
||
|
|
@@ -123,6 +128,8 @@ public <R> R performTask(final HibernateStorage.@NonNull ResultTask<T, R> task) | |
| } | ||
|
|
||
| throw new CompletionException(e); | ||
| } finally { | ||
| taskContext.markClosed(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be careful with finally-blocks, since they are always executed, meaning #markClosed is executed twice in some cases. |
||
| } | ||
| } | ||
| } catch (final JDBCConnectionException e) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,16 @@ public class StandardTaskContext implements TaskContext { | |
| @NonNull | ||
| private final Queue<Runnable> rollbackQueue = new LinkedList<>(); | ||
|
|
||
| private final Thread owner = Thread.currentThread(); | ||
| private volatile boolean closed = false; | ||
|
|
||
| public StandardTaskContext(@NonNull final Session session) { | ||
| this.session = session; | ||
| } | ||
|
|
||
| @Override | ||
| public @NonNull Session session() { | ||
| this.checkUse(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep in mind that this will not always work and is easily bypassed. Example: This ^ is how I usually structure my code. |
||
| return this.session; | ||
| } | ||
|
|
||
|
|
@@ -52,4 +56,20 @@ public void executeRollbackTasks() { | |
| this.rollbackQueue.poll().run(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void markClosed() { | ||
| this.closed = true; | ||
| } | ||
|
|
||
| @Override | ||
| public void checkUse() { | ||
| if (closed) { | ||
| throw new IllegalStateException("TaskContext used after task finished"); | ||
| } | ||
|
|
||
| if (Thread.currentThread() != owner) { | ||
| throw new IllegalStateException("TaskContext used from non-owner thread"); | ||
| } | ||
| } | ||
|
Comment on lines
+65
to
+74
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure you want exceptions to be thrown in the default case?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this method will be overriden in dirtcore |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary new lines.