private setState(List<KeyValuePair> pairs) { for (KeyValuePair pair : pairs) { String key = pair.getKey(); String value = pair.getValue(); hungry = (key.equals("hunger") && value.equals("Y")) || hungry; sleepy = (key.equals("tired") && value.equals("Y")) || sleepy; happy = (key.equals("sad") && value.equals("N")) || happy; } }
public Map<String, String> getAll() { Map<String, String> ret = new HashMap<String, String>(); Query query = em.createQuery("select kvp from KeyValuePair kvp"); for (KeyValuePair kvp : query.getResultList()) { ret.put(kvp.getKey(), kvp.getValue()); } return ret; }
public void update(List<KeyValuePair> pairs) { for (KeyValuePair kvp: pairs) { kvp.setValue(kvp.getValue() + "+"); } }
static String getDecoratedCacheKey(String cacheName, KeyValuePair<String, String> mediaTypes) { return cacheName + "|" + mediaTypes.getKey() + "|" + mediaTypes.getValue(); }
@ClientCacheEntryRemoved public void processCacheEntryDestroyed(ClientCacheEntryCustomEvent<byte[]> event) { emitSessionDestroyedEvent(readEvent(event).getValue()); }
@ClientCacheEntryCreated public void processCacheEntryCreated(ClientCacheEntryCustomEvent<byte[]> event) { emitSessionCreatedEvent(readEvent(event).getValue()); }
@Override public MarshalledEntry next() { try { if (rs.next()) { rowIndex++; Object key = key2StringMapper.getKeyMapping(rs.getString(2)); KeyValuePair<ByteBuffer, ByteBuffer> icv = unmarshall(rs.getBinaryStream(1)); return new MarshalledEntryImpl(key, icv.getKey(), icv.getValue(), marshaller); } else { close(); throw new NoSuchElementException(); } } catch (SQLException e) { throw new PersistenceException("SQL error while fetching all StoredEntries", e); } }
@ClientCacheEntryExpired public void processCacheEntryExpired(ClientCacheEntryCustomEvent<byte[]> event) { emitSessionExpiredEvent(readEvent(event).getValue()); }
private void writeNamedFactory(Optional<KeyValuePair<String, List<byte[]>>> namedFactory, ByteBuf buffer) { if (namedFactory.isPresent()) { KeyValuePair<String, List<byte[]>> factory = namedFactory.get(); writeString(factory.getKey(), buffer); buffer.writeByte(factory.getValue().size()); factory.getValue().forEach(bytes -> writeRangedBytes(bytes, buffer)); } else { buffer.writeByte(0); } }
Set<Class<?>> keys() { if (indexedEntities != null) { return indexedEntities; } startInternalCache(); Set<Class<?>> result = new HashSet<>(); Transaction tx = transactionHelper.suspendTxIfExists(); try { for (KeyValuePair<String, Class<?>> key : knownClassesCache.keySet()) { if (key.getKey().equals(cacheName)) { result.add(key.getValue()); } } return result; } finally { transactionHelper.resume(tx); } }
Set<Class<?>> keys() { if (indexedEntities != null) { return indexedEntities; } startInternalCache(); Set<Class<?>> result = new HashSet<>(); Transaction tx = transactionHelper.suspendTxIfExists(); try { for (KeyValuePair<String, Class<?>> key : knownClassesCache.keySet()) { if (key.getKey().equals(cacheName)) { result.add(key.getValue()); } } return result; } finally { transactionHelper.resume(tx); } }
AdvancedCache getCacheInstance(KeyValuePair<String, String> requestTypes, HotRodHeader header, String cacheName, EmbeddedCacheManager cacheManager, Boolean skipCacheCheck, Boolean addToKnownCaches) { AdvancedCache cache = null; String scopedCacheKey = getDecoratedCacheKey(cacheName, requestTypes); if (!skipCacheCheck) cache = knownCaches.get(scopedCacheKey); if (cache == null) { String validCacheName = cacheName.isEmpty() ? configuration.defaultCacheName() : cacheName; cache = SecurityActions.getCache(cacheManager, validCacheName).getAdvancedCache(); Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache); // We don't need synchronization as long as we store the cache last knownCacheConfigurations.put(cacheName, cacheConfiguration); knownCacheRegistries.put(cacheName, SecurityActions.getCacheComponentRegistry(cache.getAdvancedCache())); cache = cache.withMediaType(requestTypes.getKey(), requestTypes.getValue()); if (addToKnownCaches) { knownCaches.put(scopedCacheKey, cache); } // make sure we register a Migrator for this cache! tryRegisterMigrationManager(cache); } return cache; }
@CacheEntryModified public void modified(CacheEntryModifiedEvent<KeyValuePair<String, Class>, Boolean> e) { if (!e.isOriginLocal() && !e.isPre() && e.getValue()) { handleClusterRegistryRegistration(e.getKey().getValue()); } } }
@CacheEntryCreated public void created(CacheEntryCreatedEvent<KeyValuePair<String, Class>, Boolean> e) { if (!e.isOriginLocal() && !e.isPre() && e.getValue()) { handleClusterRegistryRegistration(e.getKey().getValue()); } }
@CacheEntryModified public void modified(CacheEntryModifiedEvent<KeyValuePair<String, Class>, Boolean> e) { if (!e.isOriginLocal() && !e.isPre() && e.getValue()) { handleClusterRegistryRegistration(e.getKey().getValue()); } } }
void handleModification(Channel ch, ByteBuf buf) throws IOException { KeyValuePair<byte[], Boolean> pair = readKey(buf); key = pair.getKey(); if (pair.getValue()) { // If it's the end of the operation, it can only be a remove writeResponse(ch, remove()); } else { checkpoint(MemcachedDecoderState.DECODE_PARAMETERS); } }
@CacheEntryCreated public void created(CacheEntryCreatedEvent<KeyValuePair<String, Class>, Boolean> e) { if (!e.isOriginLocal() && !e.isPre() && e.getValue()) { handleClusterRegistryRegistration(e.getKey().getValue()); } }
@Override public Flowable<K> publishKeys(Predicate<? super K> filter) { return Flowable.using(() -> { EntityManager emStream = emf.createEntityManager(); Session session = emStream.unwrap(Session.class); Criteria criteria = session.createCriteria(configuration.entityClass()).setProjection(Projections.id()).setReadOnly(true); if (setFetchSizeMinInteger) { criteria.setFetchSize(Integer.MIN_VALUE); } ScrollableResults results = criteria.scroll(ScrollMode.FORWARD_ONLY); return new KeyValuePair<>(emStream, results); }, kvp -> { ScrollableResults results = kvp.getValue(); return Flowable.fromIterable(() -> new ScrollableResultsIterator(results, filter) ); }, kvp -> { try { kvp.getValue().close(); } finally { kvp.getKey().close(); } }); }
public void testReadEventWithoutValue() { RemoteApplicationPublishedBridge remoteApplicationPublishedBridge = new RemoteApplicationPublishedBridge(createSpringCache()); String id = "1234"; ClientCacheEntryCustomEvent<byte[]> event = new TestEvent(id); KeyValuePair<String, Session> keyValuePair = remoteApplicationPublishedBridge.readEvent(event); assertEquals(id, keyValuePair.getKey()); assertNotNull(keyValuePair.getValue()); MapSession value = (MapSession) keyValuePair.getValue(); assertEquals(id, value.getId()); }
private MarshalledEntry deserialize(Object key, byte[] b, boolean fetchValue, boolean fetchMetadata) { try { if (b == null) return null; // We have to fetch metadata to tell if a key or entry is expired. Note this can be changed // after API changes fetchMetadata = true; KeyValuePair<Object, InternalMetadata> keyValuePair = (KeyValuePair<Object, InternalMetadata>) marshaller.objectFromByteBuffer(b); return ctx.getMarshalledEntryFactory().newMarshalledEntry(key, fetchValue ? keyValuePair.getKey() : null, fetchMetadata ? keyValuePair.getValue() : null); } catch (IOException e) { throw new CacheException(e); } catch (ClassNotFoundException e) { throw new CacheException(e); } }