Example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

List of usage examples for java.util.concurrent ConcurrentHashMap ConcurrentHashMap

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap ConcurrentHashMap.

Prototype

public ConcurrentHashMap() 

Source Link

Document

Creates a new, empty map with the default initial table size (16).

Usage

From source file:Main.java

/**
 * A factory method of maps.//from  w w  w .  j a v  a  2  s. co m
 *
 * @param <K>
 *            key type
 * @param <V>
 *            value type
 * @param mapType
 *            map implementation identifier
 * @return an empty map
 */
public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
    return new ConcurrentHashMap<>();
}

From source file:Main.java

public static Method getGetter(Object bean, String property) {
    Map<String, Method> cache = GETTER_CACHE.get(bean.getClass());
    if (cache == null) {
        cache = new ConcurrentHashMap<String, Method>();
        for (Method method : bean.getClass().getMethods()) {
            if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())
                    && !void.class.equals(method.getReturnType()) && method.getParameterTypes().length == 0) {
                String name = method.getName();
                if (name.length() > 3 && name.startsWith("get")) {
                    cache.put(name.substring(3, 4).toLowerCase() + name.substring(4), method);
                } else if (name.length() > 2 && name.startsWith("is")) {
                    cache.put(name.substring(2, 3).toLowerCase() + name.substring(3), method);
                }/*from ww w  . jav a  2 s.c o m*/
            }
        }
        Map<String, Method> old = GETTER_CACHE.putIfAbsent(bean.getClass(), cache);
        if (old != null) {
            cache = old;
        }
    }
    return cache.get(property);
}

From source file:com.tinydream.scribeproxy.utils.Config.java

synchronized private static void init() {
    String path = System.getProperty("appconfig");
    String pathFile = path + File.separator + "application.ini";

    //        System.out.println("pathFile:" + pathFile);
    // init configuration
    config = new CompositeConfiguration();
    _hashConfig = new ConcurrentHashMap<String, String>();
    try {/*from  w  w w.ja  v a2s .c  om*/
        config.addConfiguration(new HierarchicalINIConfiguration(pathFile));
    } catch (ConfigurationException ex) {
        logger_.error("Can't load configuration file", ex);
        System.err.println("Bad configuration; unable to start server");
        System.exit(1);
    }
}

From source file:Main.java

/**
 * get the method start with 'get' or 'is'.
 *//*from ww  w .j  a  v a2  s  . c  om*/
public static Method getGetter(Object bean, String property) {
    Map<String, Method> cache = GETTER_CACHE.get(bean.getClass());
    if (cache == null) {
        cache = new ConcurrentHashMap<>();
        for (Method method : bean.getClass().getMethods()) {
            if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())
                    && !void.class.equals(method.getReturnType()) && method.getParameterTypes().length == 0) {
                String name = method.getName();
                if (name.length() > 3 && name.startsWith("get")) {
                    cache.put(name.substring(3, 4).toLowerCase() + name.substring(4), method);
                } else if (name.length() > 2 && name.startsWith("is")) {
                    cache.put(name.substring(2, 3).toLowerCase() + name.substring(3), method);
                }
            }
        }
        Map<String, Method> old = GETTER_CACHE.putIfAbsent(bean.getClass(), cache);
        if (old != null) {
            cache = old;
        }
    }
    return cache.get(property);
}

From source file:Main.java

/**
 * Make a {@link ConcurrentMap} that when {@link ConcurrentMap#get(Object)} is called an null is
 * returned the creator function is called and the value returned is used with {@link
 * ConcurrentMap#putIfAbsent(Object, Object)}. The value that ends up in the {@link
 * ConcurrentMap} is returned by the get function.
 *///  ww w. ja  v  a2s.  c om
public static <K, V> ConcurrentMap<K, V> makeDefaultsMap(final Function<K, V> creator) {
    return new ConcurrentHashMap<K, V>() {
        @Override
        public V get(Object keyObj) {
            V value = super.get(keyObj);
            if (value == null) {
                K key = (K) keyObj;
                value = creator.apply(key);
                final V existingValue = super.putIfAbsent(key, value);
                if (existingValue != null) {
                    value = existingValue;
                }
            }
            return value;
        }
    };
}

From source file:edu.eci.arsw.blindway.persistence.StubGamePersistence.java

public StubGamePersistence() {
    this.gamesState = new ConcurrentHashMap<>();
}

From source file:com.wineaccess.wineryOWS.WineryOwsAdapterHelper.java

/**
 * this method is to create the winery historical ows data
 * @param addWineryOwsPO//from ww w .ja  va 2 s  .c  o  m
 * return map the output map
 */
public static Map<String, Object> addUpdateWineryOwsData(final AddUpdateWineryOwsPO addUpdateWineryOwsPO) {

    logger.info("start add/update winery historical Ows data");

    final Map<String, Object> output = new ConcurrentHashMap<String, Object>();
    Response response = null;

    final WineryHistoricalOwsData historicalOwsData = WineryOwsDataRepository
            .getOwsDataByWineryId(Long.parseLong(addUpdateWineryOwsPO.getWineryid()));
    if (historicalOwsData != null) {

        if (isValidDates(addUpdateWineryOwsPO)) {
            populateOwsDataModelFromPO(addUpdateWineryOwsPO, historicalOwsData);
            WineryOwsDataRepository.update(historicalOwsData);

            AddUpdateWineryOwsVO addUpdateWineryOwsVO = new AddUpdateWineryOwsVO(
                    SystemErrorCode.WINERY_OWS_UPDATE_SUCCESS_TEXT);
            addUpdateWineryOwsVO.setId(historicalOwsData.getId());
            addUpdateWineryOwsVO.setWineryId(historicalOwsData.getWineryid());
            response = new com.wineaccess.response.SuccessResponse(addUpdateWineryOwsVO, SUCCESS_CODE);
        } else {
            response = ApplicationUtils.errorMessageGenerate(
                    WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR,
                    WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR_TEXT, SUCCESS_CODE);
        }

    } else {

        if (isValidDates(addUpdateWineryOwsPO)) {
            final WineryModel wineryModel = WineryRepository
                    .getWineryById(Long.parseLong(addUpdateWineryOwsPO.getWineryid()));
            if (wineryModel != null) {
                try {
                    WineryHistoricalOwsData wineryHistoricalOwsData = new WineryHistoricalOwsData();
                    populateOwsDataModelFromPO(addUpdateWineryOwsPO, wineryHistoricalOwsData);
                    WineryOwsDataRepository.save(wineryHistoricalOwsData);

                    AddUpdateWineryOwsVO addWineryOwsVO = new AddUpdateWineryOwsVO(
                            SystemErrorCode.WINERY_OWS_ADD_SUCCESS_TEXT);
                    addWineryOwsVO.setId(wineryHistoricalOwsData.getId());
                    addWineryOwsVO.setWineryId(wineryHistoricalOwsData.getWineryid());
                    response = new com.wineaccess.response.SuccessResponse(addWineryOwsVO, SUCCESS_CODE);

                } catch (Exception e) {
                    logger.error("Some error occured " + e.getMessage(), e);
                }
            } else {
                response = ApplicationUtils.errorMessageGenerate(
                        WineaccessErrorCodes.SystemErrorCode.WINERY_NOT_FOUND_OWS,
                        WineaccessErrorCodes.SystemErrorCode.WINERY_NOT_FOUND_OWS_TEXT, SUCCESS_CODE);
            }
        } else {
            response = ApplicationUtils.errorMessageGenerate(
                    WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR,
                    WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR_TEXT, SUCCESS_CODE);
        }

    }
    output.put(OUPUT_PARAM_KEY, response);
    logger.info("exit add/update winery historical Ows data");

    return output;
}

From source file:ConcurrentSet.java

/**
 * 
 */
public ConcurrentSet() {
    this.map = new ConcurrentHashMap<Q, Object>();
}

From source file:com.DSC.client.SecureChannel.java

/**
 * @param args/*  ww w .j  a v  a2 s.co  m*/
 * @throws InterruptedException 
 * @throws IOException 
 */
public static void main(String[] args) throws InterruptedException, IOException {
    /* Create their private & public keys */
    ECKey key = new ECKey();
    key.init();
    ProgramState.publicKey = (ECPublicKeyParameters) key.getPublic();
    ProgramState.privateKey = (ECPrivateKeyParameters) key.getPrivate();

    /* Create the IV engine */
    byte[] seed = new byte[64]; // 512 bit seed 
    SecureRandom random = new SecureRandom();
    random.nextBytes(seed);
    ProgramState.IVEngine = new ISAACRandomGenerator(new ISAACEngine());
    ProgramState.IVEngine.init(seed);

    /* Create the blacklist and trusted contacts */
    ProgramState.blacklist = ConcurrentHashMultiset.create();
    ProgramState.trustedKeys = new ConcurrentHashMap<String, Address>();

    /* Set the time for the client accurately using a NTP server */
    DateTimeUtils.setCurrentMillisOffset(getTimeOffset());
    ProgramState.fmt = DateTimeFormat.forPattern("HH:mm:ss");

    /* Set the default nick as anonymous */
    ProgramState.nick = "anonymous";

    /* Initialize ISAACRandomGenerator, set ProgramState.IVEngine */
    receiveController = new ReceiveController();
    sendController = new SendController();

    /* Start input event handler loop */
    eventLoop();
}

From source file:org.emmanuel.spring.chat.handlers.EchoMessageHandler.java

public EchoMessageHandler() {
    sessions = new ConcurrentHashMap<String, WebSocketSession>();
}