dorkbox.messageBus.common.ClassTree Maven / Gradle / Ivy
/*
* Copyright 2015 dorkbox, llc
*
* Licensed 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 dorkbox.messageBus.common;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import dorkbox.collections.IdentityMap;
import dorkbox.util.FastThreadLocal;
/**
* Simple tree structure that is a map that contains a chain of keys to publish to a value.
*
*
* This Tree store "message classes" as the key, and a unique object as the "value". This map is NEVER cleared (shutdown clears it), and
* the "value" object is used to store/lookup in another map
*
* This data structure is used to keep track of multi-messages - where there is more that one parameter for publish().
*
* @author dorkbox, llc
* Date: 2/2/15
*/
public class ClassTree {
public static int INITIAL_SIZE = 4;
public static float LOAD_FACTOR = 0.8F;
private static
final FastThreadLocal keyCache = new FastThreadLocal() {
@Override
public
IdentityMap initialValue() {
return new IdentityMap(INITIAL_SIZE, LOAD_FACTOR);
}
};
private static AtomicInteger valueId = new AtomicInteger(Integer.MIN_VALUE);
private static
final FastThreadLocal valueCache = new FastThreadLocal() {
@Override
public
MultiClass initialValue() {
return new MultiClass(valueId.getAndIncrement());
}
};
private AtomicReference