-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'EI62027952_20210723' of https://code.alipay.com/alipay-…
…com/bolt into release/1.5.9
- Loading branch information
Showing
10 changed files
with
264 additions
and
22 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
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
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
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
62 changes: 62 additions & 0 deletions
62
src/main/java/com/alipay/remoting/util/ThreadLocalArriveTimeHolder.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,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.remoting.util; | ||
|
||
import io.netty.channel.Channel; | ||
import io.netty.util.concurrent.FastThreadLocal; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.WeakHashMap; | ||
|
||
/** | ||
* @author zhaowang | ||
* @version : ThreadLocalTimeHolder.java, v 0.1 2021年07月01日 3:05 下午 zhaowang | ||
*/ | ||
public class ThreadLocalArriveTimeHolder { | ||
private static FastThreadLocal<WeakHashMap<Channel, Map<Integer, Long>>> arriveTimeInNano = new FastThreadLocal<WeakHashMap<Channel, Map<Integer, Long>>>(); | ||
|
||
public static void arrive(Channel channel, Integer key) { | ||
Map<Integer, Long> map = getArriveTimeMap(channel); | ||
if (map.get(key) == null) { | ||
map.put(key, System.nanoTime()); | ||
} | ||
} | ||
|
||
public static long getAndClear(Channel channel, Integer key) { | ||
Map<Integer, Long> map = getArriveTimeMap(channel); | ||
Long result = map.remove(key); | ||
if (result == null) { | ||
return -1; | ||
} | ||
return result; | ||
} | ||
|
||
private static Map<Integer, Long> getArriveTimeMap(Channel channel) { | ||
WeakHashMap<Channel, Map<Integer, Long>> map = arriveTimeInNano.get(); | ||
if (map == null) { | ||
arriveTimeInNano.set(new WeakHashMap<Channel, Map<Integer, Long>>(256)); | ||
map = arriveTimeInNano.get(); | ||
} | ||
Map<Integer, Long> subMap = map.get(channel); | ||
if (subMap == null) { | ||
map.put(channel, new HashMap<Integer, Long>()); | ||
} | ||
return map.get(channel); | ||
} | ||
|
||
} |
Oops, something went wrong.