Skip to content

Commit

Permalink
Update parent and seed version, cleanup threadlocal in link
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Apr 26, 2016
1 parent 2bacd59 commit f03a257
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 1.0.2 (?)
# Version 1.0.2 (2016-04-26)

* [chg] Update for SeedStack 16.4
* [chg] Update for SeedStack 16.4.
* [fix] Correctly cleanup `ThreadLocal` in `RedisLink`.

# Version 1.0.1 (2016-02-09)

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
<parent>
<groupId>org.seedstack.poms</groupId>
<artifactId>parent-internal</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.0</version>
</parent>

<groupId>org.seedstack.addons.redis</groupId>
<artifactId>redis</artifactId>
<version>1.0.2-SNAPSHOT</version>

<properties>
<seed.version>2.3.0-SNAPSHOT</seed.version>
<seed.version>2.3.0</seed.version>
<jedis.version>2.7.3</jedis.version>

<compatibility.version>1.0.0</compatibility.version>
Expand Down
43 changes: 30 additions & 13 deletions src/main/java/org/seedstack/redis/internal/RedisLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,50 @@ protected Deque<Holder> initialValue() {
};

public T get() {
Holder holder = this.perThreadObjectContainer.get().peek();
Holder holder = perThreadObjectContainer.get().peek();

if (holder == null || holder.attached == null) {
if (holder == null || holder.transaction == null) {
throw SeedException.createNew(RedisErrorCodes.ACCESSING_REDIS_OUTSIDE_TRANSACTION);
}

return holder.attached;
return holder.transaction;
}

void push(Jedis jedis) {
this.perThreadObjectContainer.get().push(new Holder(jedis));
Holder getHolder() {
return perThreadObjectContainer.get().peek();
}

Jedis pop() {
return this.perThreadObjectContainer.get().pop().jedis;
void push(Jedis jedis) {
perThreadObjectContainer.get().push(new Holder(jedis));
}

Holder getHolder() {
return this.perThreadObjectContainer.get().peek();
Jedis pop() {
Deque<Holder> holders = perThreadObjectContainer.get();
Holder holder = holders.pop();
if (holders.isEmpty()) {
perThreadObjectContainer.remove();
}
return holder.jedis;
}

final class Holder {
final Jedis jedis;
T attached;
class Holder {
private final Jedis jedis;
private T transaction;

Holder(Jedis jedis) {
private Holder(Jedis jedis) {
this.jedis = jedis;
}

Jedis getJedis() {
return jedis;
}

T getTransaction() {
return transaction;
}

void setTransaction(T transaction) {
this.transaction = transaction;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public void doInitialize(TransactionMetadata transactionMetadata) {
@Override
public Pipeline doCreateTransaction() {
RedisLink<Pipeline>.Holder holder = this.redisLink.getHolder();
holder.attached = holder.jedis.pipelined();
holder.attached.multi();
return holder.attached;
Pipeline pipeline = holder.getJedis().pipelined();
pipeline.multi();
holder.setTransaction(pipeline);
return pipeline;
}

@Override
Expand Down Expand Up @@ -83,7 +84,7 @@ public Pipeline getCurrentTransaction() {
if (holder == null) {
return null;
} else {
return holder.attached;
return holder.getTransaction();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public void doInitialize(TransactionMetadata transactionMetadata) {
@Override
public Transaction doCreateTransaction() {
RedisLink<Transaction>.Holder holder = this.redisLink.getHolder();
holder.attached = holder.jedis.multi();
return holder.attached;
Transaction transaction = holder.getJedis().multi();
holder.setTransaction(transaction);
return transaction;
}

@Override
Expand Down Expand Up @@ -82,7 +83,7 @@ public Transaction getCurrentTransaction() {
if (holder == null) {
return null;
} else {
return holder.attached;
return holder.getTransaction();
}
}
}

0 comments on commit f03a257

Please sign in to comment.