Skip to content

Commit

Permalink
no longer need traceId2LeafSpanIdInfo cache. Oh yeah!! #53
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Dec 7, 2015
1 parent 199e7de commit ed73383
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.alibaba.mtc.MtContextThreadLocal;
import com.alibaba.mtc.Utils;
import com.alibaba.mtc.threadpool.MtContextExecutors;
import com.google.common.cache.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -68,27 +67,9 @@ public String toString() {
}
}


private static Cache<String, LeafSpanIdInfo> traceId2LeafSpanIdInfo = CacheBuilder.newBuilder().weakValues()
.removalListener(new RemovalListener<String, LeafSpanIdInfo>() {
@Override
public void onRemoval(RemovalNotification<String, LeafSpanIdInfo> notification) {
if (notification.getCause() != RemovalCause.COLLECTED) {
System.err.println("ERROR: Bug!! Should COLLECTED");
}
System.out.printf("DEBUG: Remove traceId %s in thread %s by cause %s: %s\n",
notification.getKey(), Thread.currentThread().getName(), notification.getCause(), notification.getValue());
}
}).build();

static int increaseLeafSpanCurrentAndReturn() {
DtTransferInfo dtTransferInfo = transferInfo.get();
String traceId = dtTransferInfo.traceId;
LeafSpanIdInfo leafSpanIdInfo = traceId2LeafSpanIdInfo.getIfPresent(traceId);
if (leafSpanIdInfo == null) {
throw new IllegalStateException("LeafSpanIdInfo is NOT present, Bug!!");
}
return leafSpanIdInfo.current.getAndIncrement();
return dtTransferInfo.leafSpanIdInfo.current.getAndIncrement();
}

public static void main(String[] args) throws Exception {
Expand All @@ -114,7 +95,6 @@ static void rpcInvokeIn() {
String baseSpanId = "1.1";

LeafSpanIdInfo leafSpanIdInfo = new LeafSpanIdInfo();
traceId2LeafSpanIdInfo.put(traceId, leafSpanIdInfo);
transferInfo.set(new DtTransferInfo(traceId, baseSpanId, leafSpanIdInfo));


Expand Down

0 comments on commit ed73383

Please sign in to comment.