Skip to content

Commit

Permalink
rehash class hashcode
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenceDut committed Mar 26, 2019
1 parent 16791b5 commit b623a10
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ private static void putImpl(Class api , IHub impl) {

}

/**
* copy from HashMap jdk8
* @param key
* @return
*/
private static int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}

public static <T extends IHub> T getImpl(Class<T> iHub) {

if (!iHub.isInterface()) {
Hub.sIHubLog.error(TAG, String.format("interfaceType must be a interface , %s is not a interface", iHub.getName()),new IllegalArgumentException("interfaceType must be a interface"));
}

int monitorIndex = iHub.hashCode() & (HubMonitor.values().length -1);
int monitorIndex = hash(iHub.hashCode()) & (HubMonitor.values().length -1);
IHub realImpl;
long monitorStartTime = System.currentTimeMillis();
Hub.sIHubLog.info(TAG, "getImpl before monitor"+iHub.getName()+" monitor"+monitorIndex +" currentThread :"+Thread.currentThread().getName());
Expand Down Expand Up @@ -74,6 +83,8 @@ public static <T extends IHub> T getImpl(Class<T> iHub) {
}

realImpl.onCreate();


Hub.sIHubLog.info(TAG, String.format("newImpl %s, cost time %s ", iHub.getName(),System.currentTimeMillis() - startTime));
}
} catch (Throwable throwable) {
Expand Down

0 comments on commit b623a10

Please sign in to comment.