forked from infinispan/infinispan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-16750 [RESP] BLPOP should not block on empty list within multi/e…
…xec block * Set a flag on Netty's channel context to identify if executing from a transaction context.
- Loading branch information
1 parent
40d00b1
commit 56bf1bd
Showing
4 changed files
with
114 additions
and
4 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
55 changes: 55 additions & 0 deletions
55
server/resp/src/main/java/org/infinispan/server/resp/tx/TransactionContext.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,55 @@ | ||
package org.infinispan.server.resp.tx; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.util.AttributeKey; | ||
|
||
/** | ||
* Delimit the context of commands run by an {@link org.infinispan.server.resp.commands.tx.EXEC} command. | ||
* <p> | ||
* In a transaction execution, the commands are queued and executed (in order) after receiving an {@link org.infinispan.server.resp.commands.tx.EXEC} | ||
* command. This context provides delimitation of the transaction execution so commands are aware whether they are running | ||
* from inside a transaction. | ||
* </p> | ||
* | ||
* @since 15.1 | ||
*/ | ||
public final class TransactionContext { | ||
|
||
private static final AttributeKey<Boolean> TRANSACTIONAL_CONTEXT = AttributeKey.newInstance("multi-exec"); | ||
|
||
private TransactionContext() { } | ||
|
||
/** | ||
* Start the transaction context. | ||
* | ||
* @param ctx The client context executing the transaction. | ||
* @throws IllegalStateException in case another context is in place. | ||
*/ | ||
public static void startTransactionContext(ChannelHandlerContext ctx) { | ||
Boolean existing = ctx.channel().attr(TRANSACTIONAL_CONTEXT).setIfAbsent(Boolean.TRUE); | ||
if (existing != null) | ||
throw new IllegalStateException("Nested transaction context"); | ||
} | ||
|
||
/** | ||
* Finish the transaction context. | ||
* | ||
* @param ctx The client context executing the transaction. | ||
* @throws IllegalStateException in case no transaction context is in place. | ||
*/ | ||
public static void endTransactionContext(ChannelHandlerContext ctx) { | ||
Boolean existing = ctx.channel().attr(TRANSACTIONAL_CONTEXT).getAndSet(null); | ||
if (existing == null) | ||
throw new IllegalStateException("Not transaction context to remove"); | ||
} | ||
|
||
/** | ||
* Verify whether the current client is in a transactional context. | ||
* | ||
* @param ctx The client context to verify. | ||
* @return <code>true</code> if running from a transaction, <code>false</code>, otherwise. | ||
*/ | ||
public static boolean isInTransactionContext(ChannelHandlerContext ctx) { | ||
return Boolean.TRUE.equals(ctx.channel().attr(TRANSACTIONAL_CONTEXT).get()); | ||
} | ||
} |
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