public Key cloneWithoutRegions() { return new Key(entityType, entityName, requestType, requestVersion, eurekaAccept); }
public void onRemoval(RemovalNotification<Key, Value> notification) { Key removedKey = notification.getKey(); if (removedKey.hasRegions()) { Key cloneWithNoRegions = removedKey.cloneWithoutRegions(); regionSpecificKeys.remove(cloneWithNoRegions, removedKey); @Override public Value load(Key key) throws Exception { if (key.hasRegions()) { Key cloneWithNoRegions = key.cloneWithoutRegions(); regionSpecificKeys.put(cloneWithNoRegions, key);
/** * Invalidate the cache information given the list of keys. * * @param keys the list of keys for which the cache information needs to be invalidated. */ public void invalidate(Key... keys) { for (Key key : keys) { logger.debug("Invalidating the response cache key : {} {} {} {}, {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType(), key.getEurekaAccept()); readWriteCacheMap.invalidate(key); Collection<Key> keysWithRegions = regionSpecificKeys.get(key); if (null != keysWithRegions && !keysWithRegions.isEmpty()) { for (Key keysWithRegion : keysWithRegions) { logger.debug("Invalidating the response cache key : {} {} {} {} {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType(), key.getEurekaAccept()); readWriteCacheMap.invalidate(keysWithRegion); } } } }
/** * Generate pay load with both JSON and XML formats for all applications. */ private String getPayLoad(Key key, Applications apps) { EncoderWrapper encoderWrapper = serverCodecs.getEncoder(key.getType(), key.getEurekaAccept()); String result; try { result = encoderWrapper.encode(apps); } catch (Exception e) { logger.error("Failed to encode the payload for all apps", e); return ""; } if(logger.isDebugEnabled()) { logger.debug("New application cache entry {} with apps hashcode {}", key.toStringCompact(), apps.getAppsHashCode()); } return result; }
/** * Generate pay load with both JSON and XML formats for a given application. */ private String getPayLoad(Key key, Application app) { if (app == null) { return EMPTY_PAYLOAD; } EncoderWrapper encoderWrapper = serverCodecs.getEncoder(key.getType(), key.getEurekaAccept()); try { return encoderWrapper.encode(app); } catch (Exception e) { logger.error("Failed to encode the payload for application {}", app.getName(), e); return ""; } }
try { String payload; switch (key.getEntityType()) { case Application: boolean isRemoteRegionRequested = key.hasRegions(); if (ALL_APPS.equals(key.getName())) { if (isRemoteRegionRequested) { tracer = serializeAllAppsWithRemoteRegionTimer.start(); payload = getPayLoad(key, registry.getApplicationsFromMultipleRegions(key.getRegions())); } else { tracer = serializeAllAppsTimer.start(); payload = getPayLoad(key, registry.getApplications()); } else if (ALL_APPS_DELTA.equals(key.getName())) { if (isRemoteRegionRequested) { tracer = serializeDeltaAppsWithRemoteRegionTimer.start(); versionDeltaWithRegionsLegacy.incrementAndGet(); payload = getPayLoad(key, registry.getApplicationDeltasFromMultipleRegions(key.getRegions())); } else { tracer = serializeDeltaAppsTimer.start(); payload = getPayLoad(key, registry.getApplication(key.getName())); break; default: logger.error("Unidentified entity type: {} found in the cache key.", key.getEntityType());
@Override public boolean equals(Object other) { if (other instanceof Key) { return getHashKey().equals(((Key) other).getHashKey()); } else { return false; } }
try { String payload; switch (key.getEntityType()) { case Application: boolean isRemoteRegionRequested = key.hasRegions(); if (ALL_APPS.equals(key.getName())) { if (isRemoteRegionRequested) { tracer = serializeAllAppsWithRemoteRegionTimer.start(); payload = getPayLoad(key, registry.getApplicationsFromMultipleRegions(key.getRegions())); } else { tracer = serializeAllAppsTimer.start(); payload = getPayLoad(key, registry.getApplications()); } else if (ALL_APPS_DELTA.equals(key.getName())) { if (isRemoteRegionRequested) { tracer = serializeDeltaAppsWithRemoteRegionTimer.start(); versionDeltaWithRegionsLegacy.incrementAndGet(); payload = getPayLoad(key, registry.getApplicationDeltasFromMultipleRegions(key.getRegions())); } else { tracer = serializeDeltaAppsTimer.start(); payload = getPayLoad(key, registry.getApplication(key.getName())); break; default: logger.error("Unidentified entity type: {} found in the cache key.", key.getEntityType());
/** * Generate pay load with both JSON and XML formats for all applications. */ private String getPayLoad(Key key, Applications apps) { EncoderWrapper encoderWrapper = serverCodecs.getEncoder(key.getType(), key.getEurekaAccept()); String result; try { result = encoderWrapper.encode(apps); } catch (Exception e) { logger.error("Failed to encode the payload for all apps", e); return ""; } if(logger.isDebugEnabled()) { logger.debug("New application cache entry {} with apps hashcode {}", key.toStringCompact(), apps.getAppsHashCode()); } return result; }
/** * Generate pay load with both JSON and XML formats for a given application. */ private String getPayLoad(Key key, Application app) { if (app == null) { return EMPTY_PAYLOAD; } EncoderWrapper encoderWrapper = serverCodecs.getEncoder(key.getType(), key.getEurekaAccept()); try { return encoderWrapper.encode(app); } catch (Exception e) { logger.error("Failed to encode the payload for application {}", app.getName(), e); return ""; } }
@Override public int hashCode() { String hashKey = getHashKey(); return hashKey.hashCode(); }
@Override public void run() { logger.debug("Updating the client cache from response cache"); for (Key key : readOnlyCacheMap.keySet()) { if (logger.isDebugEnabled()) { logger.debug("Updating the client cache from response cache for key : {} {} {} {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType()); } try { CurrentRequestVersion.set(key.getVersion()); Value cacheValue = readWriteCacheMap.get(key); Value currentCacheValue = readOnlyCacheMap.get(key); if (cacheValue != currentCacheValue) { readOnlyCacheMap.put(key, cacheValue); } } catch (Throwable th) { logger.error("Error while updating the client cache from response cache for key {}", key.toStringCompact(), th); } } } };
/** * Invalidate the cache of a particular application. * * @param appName the application name of the application. */ @Override public void invalidate(String appName, @Nullable String vipAddress, @Nullable String secureVipAddress) { for (Key.KeyType type : Key.KeyType.values()) { for (Version v : Version.values()) { invalidate( new Key(Key.EntityType.Application, appName, type, v, EurekaAccept.full), new Key(Key.EntityType.Application, appName, type, v, EurekaAccept.compact), new Key(Key.EntityType.Application, ALL_APPS, type, v, EurekaAccept.full), new Key(Key.EntityType.Application, ALL_APPS, type, v, EurekaAccept.compact), new Key(Key.EntityType.Application, ALL_APPS_DELTA, type, v, EurekaAccept.full), new Key(Key.EntityType.Application, ALL_APPS_DELTA, type, v, EurekaAccept.compact) ); if (null != vipAddress) { invalidate(new Key(Key.EntityType.VIP, vipAddress, type, v, EurekaAccept.full)); } if (null != secureVipAddress) { invalidate(new Key(Key.EntityType.SVIP, secureVipAddress, type, v, EurekaAccept.full)); } } } }
public void onRemoval(RemovalNotification<Key, Value> notification) { Key removedKey = notification.getKey(); if (removedKey.hasRegions()) { Key cloneWithNoRegions = removedKey.cloneWithoutRegions(); regionSpecificKeys.remove(cloneWithNoRegions, removedKey); @Override public Value load(Key key) throws Exception { if (key.hasRegions()) { Key cloneWithNoRegions = key.cloneWithoutRegions(); regionSpecificKeys.put(cloneWithNoRegions, key);
@Override public boolean equals(Object other) { if (other instanceof Key) { return getHashKey().equals(((Key) other).getHashKey()); } else { return false; } }
private static Applications getApplicationsForVip(Key key, AbstractInstanceRegistry registry) { logger.debug( "Retrieving applications from registry for key : {} {} {} {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType()); Applications toReturn = new Applications(); Applications applications = registry.getApplications(); for (InstanceInfo instanceInfo : application.getInstances()) { String vipAddress; if (Key.EntityType.VIP.equals(key.getEntityType())) { vipAddress = instanceInfo.getVIPAddress(); } else if (Key.EntityType.SVIP.equals(key.getEntityType())) { vipAddress = instanceInfo.getSecureVipAddress(); } else { String[] vipAddresses = vipAddress.split(","); Arrays.sort(vipAddresses); if (Arrays.binarySearch(vipAddresses, key.getName()) >= 0) { if (null == appToAdd) { appToAdd = new Application(application.getName()); logger.debug( "Retrieved applications from registry for key : {} {} {} {}, reconcile hashcode: {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType(), toReturn.getReconcileHashCode()); return toReturn;
protected Response getVipResponse(String version, String entityName, String acceptHeader, EurekaAccept eurekaAccept, Key.EntityType entityType) { if (!registry.shouldAllowAccess(false)) { return Response.status(Response.Status.FORBIDDEN).build(); } CurrentRequestVersion.set(Version.toEnum(version)); Key.KeyType keyType = Key.KeyType.JSON; if (acceptHeader == null || !acceptHeader.contains("json")) { keyType = Key.KeyType.XML; } Key cacheKey = new Key( entityType, entityName, keyType, CurrentRequestVersion.get(), eurekaAccept ); String payLoad = responseCache.get(cacheKey); if (payLoad != null) { logger.debug("Found: {}", entityName); return Response.ok(payLoad).build(); } else { logger.debug("Not Found: {}", entityName); return Response.status(Response.Status.NOT_FOUND).build(); } } }
@Override public int hashCode() { String hashKey = getHashKey(); return hashKey.hashCode(); }
/** * Invalidate the cache information given the list of keys. * * @param keys the list of keys for which the cache information needs to be invalidated. */ public void invalidate(Key... keys) { for (Key key : keys) { logger.debug("Invalidating the response cache key : {} {} {} {}, {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType(), key.getEurekaAccept()); readWriteCacheMap.invalidate(key); Collection<Key> keysWithRegions = regionSpecificKeys.get(key); if (null != keysWithRegions && !keysWithRegions.isEmpty()) { for (Key keysWithRegion : keysWithRegions) { logger.debug("Invalidating the response cache key : {} {} {} {} {}", key.getEntityType(), key.getName(), key.getVersion(), key.getType(), key.getEurekaAccept()); readWriteCacheMap.invalidate(keysWithRegion); } } } }
Key cacheKey = new Key( Key.EntityType.Application, appName,