/** * Fetch all the values for the specified keys. Null is returned if the key isn't found. * * @param keys * @return */ public Map<K, V> getAll(Collection<K> keys) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); Map<K, V> rc = utils.getAll(keys, bmap); mbean.getGetMetrics().logTime(System.nanoTime() - start); return rc; }
/** * Set the value for the key. If the entry doesn't exist then it is inserted otherwise it's * updated. * * @param k * @param v */ public void put(K k, V v) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid.getName(), mapName); long start = System.nanoTime(); try { InsertAgent<K, V> a = new InsertAgent<K, V>(); a.doGet = true; a.batch = new TreeMap<K, V>(); a.batch.put(k, v); a.isWriteThrough = true; Object o = tls.getMap(mapName).getAgentManager().callReduceAgent(a, Collections.singletonList(k)); if (o instanceof Boolean) { Boolean b = (Boolean) o; if (!b) { logger.log(Level.SEVERE, "put(K,V) failed"); throw new ObjectGridRuntimeException("put failed"); } } mbean.getPutMetrics().logTime(System.nanoTime() - start); } catch (Exception e) { logger.log(Level.SEVERE, "Exception", e); mbean.getPutMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * This get an advisory lock on a key. In reality, it inserts a record in a 'lock' map to acquire * ownership of a notional named lock (the name is the key). It will try to acquire the lock for * at least timeoutMs. Once acquired, the lock is permanent until the lock is removed OR evictor * by configuring a default evictor on the lock map. * * @param k The name of the lock * @param value Any value, doesn't matter, typically use a Boolean * @param timeOutMS Desired max wait time for a lock * @return true if lock is acquired. */ public boolean lockPrim(boolean isLock, K k, V value, int timeOutMS) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid.getName(), mapName); long start = System.nanoTime(); try { LockAgent<K, V> a = new LockAgent<K, V>(); a.isLock = isLock; a.key = k; a.value = value; a.timeOutMS = timeOutMS; Object o = tls.getMap(mapName).getAgentManager().callReduceAgent(a, Collections.singletonList(k)); if (isLock) mbean.getLockMetrics().logTime(System.nanoTime() - start); else mbean.getUnlockMetrics().logTime(System.nanoTime() - start); if (o instanceof Boolean) { Boolean b = (Boolean) o; return b; } else { String c = isLock ? "lock" : "unlock"; logger.log(Level.SEVERE, c + " failed", o.toString()); throw new ObjectGridRuntimeException(c + " failed"); } } catch (Exception e) { logger.log(Level.SEVERE, "Exception", e); if (isLock) mbean.getLockMetrics().logException(e); else mbean.getUnlockMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
public Map<K, Boolean> cond_putAll(Map<K, V> originalValues, Map<K, V> newValues) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid.getName(), mapName); long start = System.nanoTime(); Map<K, Boolean> rc = utils.cond_putAll(originalValues, newValues, bmap); mbean.getPutMetrics().logTime(System.nanoTime() - start); return rc; }
/** * This does a single entry insert. If the key already exists then an exception is thrown. * * @param k * @param v */ public void insert(K k, V v) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); try { tls.getMap(mapName).insert(k, v); mbean.getInsertMetrics().logTime(System.nanoTime() - start); } catch (Exception e) { mbean.getInsertMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * Fetch a value from the Map * * @param k * @return */ public V get(K k) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); try { V rc = (V) tls.getMap(mapName).get(k); mbean.getGetMetrics().logTime(System.nanoTime() - start); return rc; } catch (Exception e) { mbean.getGetMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * Check if the entry exists for the key * * @param k * @return */ public boolean contains(K k) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); try { boolean rc = tls.getMap(mapName).containsKey(k); mbean.getContainsMetrics().logTime(System.nanoTime() - start); return rc; } catch (Exception e) { mbean.getContainsMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * Remove the entry from the Map * * @param k * @return The last value otherwise null */ public void invalidate(K k) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid.getName(), mapName); long start = System.nanoTime(); try { tls.getMap(mapName).invalidate(k, true); mbean.getInvalidateMetrics().logTime(System.nanoTime() - start); } catch (Exception e) { logger.log(Level.SEVERE, "Exception", e); mbean.getInvalidateMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * Remove the entry from the Map * * @param k * @return The last value otherwise null */ public V remove(K k) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid.getName(), mapName); long start = System.nanoTime(); try { V rc = (V) tls.getMap(mapName).remove(k); mbean.getRemoveMetrics().logTime(System.nanoTime() - start); return rc; } catch (Exception e) { logger.log(Level.SEVERE, "Exception", e); mbean.getRemoveMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * Set the value for the key. If the entry doesn't exist then it is inserted otherwise it's * updated. * * @param k * @param v */ public void put(K k, V v) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); try { InsertAgent<K, V> a = new InsertAgent<K, V>(); a.doGet = true; a.batch = new Hashtable<K, V>(); a.batch.put(k, v); tls.getMap(mapName).getAgentManager().callReduceAgent(a, Collections.singletonList(k)); mbean.getPutMetrics().logTime(System.nanoTime() - start); } catch (Exception e) { mbean.getPutMetrics().logException(e); throw new ObjectGridRuntimeException(e); } }
/** * Remove all entries with these keys * * @param keys */ public void removeAll(Collection<K> keys) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); utils.removeAll(keys, bmap); mbean.getRemoveMetrics().logTime(System.nanoTime() - start); }
/** * Parallel insert all the entries. This does a real insert, not a put (get/update) * * @param batch */ public void insertAll(Map<K, V> batch) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid, mapName); long start = System.nanoTime(); utils.insertAll(batch, bmap); mbean.getInsertMetrics().logTime(System.nanoTime() - start); }
public void putAll_noLoader(Map<K, V> batch) { WXSMapMBeanImpl mbean = WXSUtils.getWXSMapMBeanManager().getBean(grid.getName(), mapName); long start = System.nanoTime(); utils.putAll_noLoader(batch, bmap); mbean.getPutMetrics().logTime(System.nanoTime() - start); }