From 3328534356a2649012fa73950d9e54378aaa5071 Mon Sep 17 00:00:00 2001 From: blackopsdev Date: Thu, 11 Sep 2014 18:39:02 +0400 Subject: [PATCH 1/6] > Whitespaces were replaced to tabs. > toBuilder method which converts ApiConfiguration object to builder, based on current instance --- .../stackify/api/common/ApiConfiguration.java | 93 +++++++++++-------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/stackify/api/common/ApiConfiguration.java b/src/main/java/com/stackify/api/common/ApiConfiguration.java index 1af72fa..2e0c6fb 100644 --- a/src/main/java/com/stackify/api/common/ApiConfiguration.java +++ b/src/main/java/com/stackify/api/common/ApiConfiguration.java @@ -23,32 +23,32 @@ * @author Eric Martin */ public class ApiConfiguration { - + /** * Default API URL */ private static final String DEFAULT_API_URL = "https://api.stackify.com"; - + /** * API URL */ private final String apiUrl; - + /** * API Key */ private final String apiKey; - + /** * Application name */ private final String application; - + /** * Environment */ private final String environment; - + /** * Environment details */ @@ -93,11 +93,11 @@ public EnvironmentDetail getEnvDetail() { * @param builder The Builder object that contains all of the values for initialization */ private ApiConfiguration(final Builder builder) { - this.apiUrl = builder.apiUrl; - this.apiKey = builder.apiKey; - this.application = builder.application; - this.environment = builder.environment; - this.envDetail = builder.envDetail; + this.apiUrl = builder.apiUrl; + this.apiKey = builder.apiKey; + this.application = builder.application; + this.environment = builder.environment; + this.envDetail = builder.envDetail; } /** @@ -107,6 +107,19 @@ public static Builder newBuilder() { return new Builder(); } + + /** + * @return a Builder object based on current instance + */ + public Builder toBuilder() { + return newBuilder() + .apiUrl(apiUrl) + .apiKey(apiKey) + .application(application) + .environment(environment) + .envDetail(envDetail); + } + /** * ApiConfiguration.Builder separates the construction of a ApiConfiguration from its representation */ @@ -116,82 +129,82 @@ public static class Builder { * The builder's apiUrl */ private String apiUrl; - + /** * The builder's apiKey */ private String apiKey; - + /** * The builder's application */ private String application; - + /** * The builder's environment */ private String environment; - + /** * The builder's envDetail */ private EnvironmentDetail envDetail; - + /** * Sets the builder's apiUrl * @param apiUrl The apiUrl to be set * @return Reference to the current object */ public Builder apiUrl(final String apiUrl) { - this.apiUrl = apiUrl; - return this; + this.apiUrl = apiUrl; + return this; } - + /** * Sets the builder's apiKey * @param apiKey The apiKey to be set * @return Reference to the current object */ public Builder apiKey(final String apiKey) { - this.apiKey = apiKey; - return this; + this.apiKey = apiKey; + return this; } - + /** * Sets the builder's application * @param application The application to be set * @return Reference to the current object */ public Builder application(final String application) { - this.application = application; - return this; + this.application = application; + return this; } - + /** * Sets the builder's environment * @param environment The environment to be set * @return Reference to the current object */ public Builder environment(final String environment) { - this.environment = environment; - return this; + this.environment = environment; + return this; } - + /** * Sets the builder's envDetail * @param envDetail The envDetail to be set * @return Reference to the current object */ public Builder envDetail(final EnvironmentDetail envDetail) { - this.envDetail = envDetail; - return this; + this.envDetail = envDetail; + return this; } - + /** * @return A new object constructed from this builder */ public ApiConfiguration build() { - return new ApiConfiguration(this); + return new ApiConfiguration(this); } } @@ -201,13 +214,13 @@ public ApiConfiguration build() { */ @Override public String toString() { - return Objects.toStringHelper(this) - .omitNullValues() - .add("apiUrl", apiUrl) - .add("apiKey", apiKey) - .add("application", application) - .add("environment", environment) - .add("envDetail", envDetail) - .toString(); + return Objects.toStringHelper(this) + .omitNullValues() + .add("apiUrl", apiUrl) + .add("apiKey", apiKey) + .add("application", application) + .add("environment", environment) + .add("envDetail", envDetail) + .toString(); } } From dee1dfb0540f08d7409068a8c2ba0f0125a161d9 Mon Sep 17 00:00:00 2001 From: blackopsdev Date: Fri, 12 Sep 2014 17:00:26 +0400 Subject: [PATCH 2/6] flush method's size was reduced, by creating new one responsible for LogMsgGroup building. --- .../stackify/api/common/log/LogCollector.java | 112 ++++++++++-------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/stackify/api/common/log/LogCollector.java b/src/main/java/com/stackify/api/common/log/LogCollector.java index 22c1302..a21501d 100644 --- a/src/main/java/com/stackify/api/common/log/LogCollector.java +++ b/src/main/java/com/stackify/api/common/log/LogCollector.java @@ -37,26 +37,26 @@ * @author Eric Martin */ public class LogCollector { - + /** * The logger (project) name */ private final String logger; - + /** * Environment details */ private final EnvironmentDetail envDetail; - + /** * Application identity service */ private final AppIdentityService appIdentityService; - + /** * The queue of objects to be transmitted */ - private final Queue queue = Queues.synchronizedQueue(EvictingQueue.create(1000)); + private final Queue queue = Queues.synchronizedQueue(EvictingQueue.create(1000)); /** * Constructor @@ -72,88 +72,98 @@ public LogCollector(final String logger, final EnvironmentDetail envDetail, fina this.envDetail = envDetail; this.appIdentityService = appIdentityService; } - + /** * Queues logMsg to be sent * @param logMsg The log message */ public void addLogMsg(final LogMsg logMsg) { - Preconditions.checkNotNull(logMsg); + Preconditions.checkNotNull(logMsg); queue.offer(logMsg); } - + /** * Flushes the queue by sending all messages to Stackify * @param sender The LogMsgGroup sender * @return The number of messages sent to Stackify * @throws IOException - * @throws HttpException + * @throws HttpException */ public int flush(final LogSender sender) throws IOException, HttpException { int numSent = 0; int maxToSend = queue.size(); - + if (0 < maxToSend) { - Optional appIdentity = appIdentityService.getAppIdentity(); - + while (numSent < maxToSend) { - + // get the next batch of messages - int batchSize = Math.min(maxToSend - numSent, 20); - + List batch = Lists.newArrayListWithCapacity(batchSize); - + for (int i = 0; i < batchSize; ++i) { batch.add(queue.remove()); } - + // build the log message group testAddAndFlushrecord - - LogMsgGroup.Builder groupBuilder = LogMsgGroup.newBuilder(); - - groupBuilder.platform("java"); - groupBuilder.logger(logger); - groupBuilder.serverName(envDetail.getDeviceName()); - groupBuilder.env(envDetail.getConfiguredEnvironmentName()); - groupBuilder.appName(envDetail.getConfiguredAppName()); - groupBuilder.appLoc(envDetail.getAppLocation()); - - if (appIdentity.isPresent()) { - groupBuilder.cdId(appIdentity.get().getDeviceId()); - groupBuilder.cdAppId(appIdentity.get().getDeviceAppId()); - groupBuilder.appNameId(appIdentity.get().getAppNameId()); - groupBuilder.appEnvId(appIdentity.get().getAppEnvId()); - groupBuilder.envId(appIdentity.get().getEnvId()); - groupBuilder.env(appIdentity.get().getEnv()); - - if ((appIdentity.get().getAppName() != null) && (0 < appIdentity.get().getAppName().length())) { - groupBuilder.appName(appIdentity.get().getAppName()); - } - } - - groupBuilder.msgs(batch); - - LogMsgGroup group = groupBuilder.build(); - + LogMsgGroup group = createLogMessageGroup(batch, logger, envDetail, appIdentity); + // send the batch to Stackify - - int httpStatus = sender.send(group); - + int httpStatus = sender.send(group); + // if the batch failed to transmit, return the appropriate transmission status - if (httpStatus != HttpURLConnection.HTTP_OK) { throw new HttpException(httpStatus); } - + // next iteration - numSent += batchSize; } } - + return numSent; } + + /** + * + * @param batch - a bunch of messages that should be sent over the wire + * @param logger - logger (project) name + * @param envDetail - environment details + * @param appIdentity - application identity + * @return LogMessage group object with + */ + private LogMsgGroup createLogMessageGroup ( + final List batch, final String logger, final EnvironmentDetail envDetail, final Optional appIdentity + ) { + final LogMsgGroup.Builder groupBuilder = LogMsgGroup.newBuilder(); + + groupBuilder + .platform("java") + .logger(logger) + .serverName(envDetail.getDeviceName()) + .env(envDetail.getConfiguredEnvironmentName()) + .appName(envDetail.getConfiguredAppName()) + .appLoc(envDetail.getAppLocation()); + + if (appIdentity.isPresent()) { + groupBuilder + .cdId(appIdentity.get().getDeviceId()) + .cdAppId(appIdentity.get().getDeviceAppId()) + .appNameId(appIdentity.get().getAppNameId()) + .appEnvId(appIdentity.get().getAppEnvId()) + .envId(appIdentity.get().getEnvId()) + .env(appIdentity.get().getEnv()); + + if ((appIdentity.get().getAppName() != null) && (0 < appIdentity.get().getAppName().length())) { + groupBuilder.appName(appIdentity.get().getAppName()); + } + } + + groupBuilder.msgs(batch); + + return groupBuilder.build(); + } } From fcf8809d1aefc40fee61d4e36da42a0804f5eea9 Mon Sep 17 00:00:00 2001 From: blackopsdev Date: Mon, 15 Sep 2014 13:18:24 +0400 Subject: [PATCH 3/6] multiple applications support --- .../api/common/AppIdentityService.java | 154 +++++++++++++----- 1 file changed, 112 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/stackify/api/common/AppIdentityService.java b/src/main/java/com/stackify/api/common/AppIdentityService.java index a60170c..9b953c5 100644 --- a/src/main/java/com/stackify/api/common/AppIdentityService.java +++ b/src/main/java/com/stackify/api/common/AppIdentityService.java @@ -16,6 +16,8 @@ package com.stackify.api.common; import java.io.IOException; +import java.util.Hashtable; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,27 +46,22 @@ public class AppIdentityService { * Five minutes (in milliseconds) */ private static long FIVE_MINUTES_MILLIS = 300000; - - /** - * Timestamp of the last query - */ - private long lastQuery = 0; - + /** - * The cached app identity + * Map The cached app identity */ - private Optional appIdentity = Optional.absent(); - + private Map applicationIdentityCache = new Hashtable(); + /** * The API configuration */ - private final ApiConfiguration apiConfig; + private final ApiConfiguration defaultApiConfig; /** * Jackson object mapper */ private final ObjectMapper objectMapper; - + /** * Constructor * @param apiConfig The API configuration @@ -73,55 +70,128 @@ public class AppIdentityService { public AppIdentityService(final ApiConfiguration apiConfig, final ObjectMapper objectMapper) { Preconditions.checkNotNull(apiConfig); Preconditions.checkNotNull(objectMapper); - - this.apiConfig = apiConfig; + + this.defaultApiConfig = apiConfig; this.objectMapper = objectMapper; } - + + private boolean isCached(final String applicationName) { + Preconditions.checkNotNull(applicationName); + return applicationIdentityCache.containsKey(applicationName); + } + /** * Retrieves the application identity given the environment details * @return The application identity */ - public Optional getAppIdentity() { - if (!appIdentity.isPresent()) { - long currentTimeMillis = System.currentTimeMillis(); - - if (lastQuery + FIVE_MINUTES_MILLIS < currentTimeMillis) { - try { - lastQuery = currentTimeMillis; - appIdentity = Optional.fromNullable(identifyApp()); - LOGGER.debug("Application identity: {}", appIdentity.get()); - } catch (Throwable t) { - LOGGER.info("Unable to determine application identity", t); - } + private Optional getAppIdentity(ApiConfiguration apiConfig) { + final String applicationName = apiConfig.getApplication(); + + if (applicationName == null) + return Optional.absent(); + + // new state with current timestamp + final AppIdentityState state = new AppIdentityState(); + + final long now = System.currentTimeMillis(); + + if (state.lastModified() + FIVE_MINUTES_MILLIS < now) { + try { + final AppIdentity identity = identifyApp(apiConfig); + // Obtain AppIdentity for current app + applicationIdentityCache.put( + applicationName, state.updateAppIdentity(identity) + ); + + LOGGER.debug("Application identity: {}", identity); + + } catch (Throwable t) { + LOGGER.info("Unable to determine application identity", t); } } - - return appIdentity; + + return applicationIdentityCache.get(apiConfig.getApplication()).getAppIdentity(); } - + + + + public Optional getAppIdentity(final String applicationName) { + if (isCached(applicationName)) { + return applicationIdentityCache.get(applicationName).getAppIdentity(); + + } else { + // use existing apiConfig, with new application name + final ApiConfiguration updatedApiConfig = defaultApiConfig.toBuilder().application(applicationName).build(); + return getAppIdentity(updatedApiConfig); + } + } + + + public Optional getAppIdentity() { + return getAppIdentity(defaultApiConfig); + } + /** * Retrieves the application identity given the environment details * @return The application identity * @throws IOException - * @throws HttpException + * @throws HttpException */ - private AppIdentity identifyApp() throws IOException, HttpException { - + private AppIdentity identifyApp(ApiConfiguration apiConfig) throws IOException, HttpException { // convert to json bytes - byte[] jsonBytes = objectMapper.writer().writeValueAsBytes(apiConfig.getEnvDetail()); - + // post to stackify - - HttpClient httpClient = new HttpClient(apiConfig); - String responseString = httpClient.post("/Metrics/IdentifyApp", jsonBytes); - + final HttpClient httpClient = new HttpClient(apiConfig); + final String responseString = httpClient.post("/Metrics/IdentifyApp", jsonBytes); + // deserialize the response and return the app identity - ObjectReader jsonReader = objectMapper.reader(new TypeReference(){}); - AppIdentity appIdentity = jsonReader.readValue(responseString); - - return appIdentity; + return jsonReader.readValue(responseString); + } + + /** + * This class contains appIdentity and it's modification date + */ + private class AppIdentityState { + + private Optional mayBeAppIdentity = Optional.absent(); + private long lastQueryTimeStamp; + + public AppIdentityState() { + this.lastQueryTimeStamp = 0; + this.mayBeAppIdentity = Optional.absent(); + } + + public AppIdentityState(final AppIdentity appIdentity) { + this.touch(); + this.mayBeAppIdentity = Optional.fromNullable(appIdentity); + } + + public AppIdentityState(final AppIdentity appIdentity, long timestamp) { + this.lastQueryTimeStamp = timestamp; + this.mayBeAppIdentity = Optional.fromNullable(appIdentity); + } + + public final AppIdentityState updateAppIdentity(final AppIdentity appIdentity) { + mayBeAppIdentity = Optional.fromNullable(appIdentity); + return this; + } + + public final Optional getAppIdentity() { + this.touch(); + return mayBeAppIdentity; + } + + public final long lastModified() { + return lastQueryTimeStamp; + } + + /** + * Changes last modified date + */ + public final void touch() { + this.lastQueryTimeStamp = System.currentTimeMillis(); + } } } From 53ee9ec2f23810738245aeb089a19187d41ea1fd Mon Sep 17 00:00:00 2001 From: blackopsdev Date: Mon, 15 Sep 2014 14:10:31 +0400 Subject: [PATCH 4/6] test was fixed --- .../api/common/AppIdentityServiceTest.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/stackify/api/common/AppIdentityServiceTest.java b/src/test/java/com/stackify/api/common/AppIdentityServiceTest.java index bf16195..6e39675 100644 --- a/src/test/java/com/stackify/api/common/AppIdentityServiceTest.java +++ b/src/test/java/com/stackify/api/common/AppIdentityServiceTest.java @@ -20,6 +20,7 @@ import org.junit.runner.RunWith; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; +import static org.powermock.api.mockito.PowerMockito.*; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -39,29 +40,32 @@ public class AppIdentityServiceTest { /** * testGetAppIdentity - * @throws Exception + * @throws Exception */ @Test - public void testGetAppIdentity() throws Exception { + public void testGetAppIdentity() throws Exception { - EnvironmentDetail envDetail = EnvironmentDetail.newBuilder().deviceName("device").appName("app").build(); + final EnvironmentDetail envDetail = + EnvironmentDetail.newBuilder().deviceName("device").appName("app").build(); - AppIdentity appIdentity = AppIdentity.newBuilder().deviceId(Integer.valueOf(123)).appNameId("456").build(); + final AppIdentity appIdentity = + AppIdentity.newBuilder().deviceId(123).appNameId("456").appName("app").build(); + + final ObjectMapper objectMapper = new ObjectMapper(); - ObjectMapper objectMapper = new ObjectMapper(); - String appIdentityResponse = objectMapper.writer().writeValueAsString(appIdentity); - - HttpClient httpClient = PowerMockito.mock(HttpClient.class); - PowerMockito.whenNew(HttpClient.class).withAnyArguments().thenReturn(httpClient); - PowerMockito.when(httpClient.post(Mockito.anyString(), (byte[]) Mockito.any())).thenReturn(appIdentityResponse); - - ApiConfiguration apiConfig = ApiConfiguration.newBuilder().apiUrl("url").apiKey("key").envDetail(envDetail).build(); - + + final HttpClient httpClient = mock(HttpClient.class); + whenNew(HttpClient.class).withAnyArguments().thenReturn(httpClient); + when(httpClient.post(Mockito.anyString(), (byte[]) Mockito.any())).thenReturn(appIdentityResponse); + + ApiConfiguration apiConfig = + ApiConfiguration.newBuilder().apiUrl("url").apiKey("key").application("app").envDetail(envDetail).build(); + AppIdentityService service = new AppIdentityService(apiConfig, objectMapper); Optional rv = service.getAppIdentity(); - + Assert.assertNotNull(rv); Assert.assertTrue(rv.isPresent()); Assert.assertEquals(Integer.valueOf(123), rv.get().getDeviceId()); From c3d1712beb28c145c8813684409919c042cc6d71 Mon Sep 17 00:00:00 2001 From: blackopsdev Date: Mon, 15 Sep 2014 18:17:40 +0400 Subject: [PATCH 5/6] appConfiguredName issue fixed. logical bugs were fixed (related to isCached and etc) --- .../api/common/AppIdentityService.java | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/stackify/api/common/AppIdentityService.java b/src/main/java/com/stackify/api/common/AppIdentityService.java index 9b953c5..dc2cdaf 100644 --- a/src/main/java/com/stackify/api/common/AppIdentityService.java +++ b/src/main/java/com/stackify/api/common/AppIdentityService.java @@ -19,6 +19,7 @@ import java.util.Hashtable; import java.util.Map; +import com.stackify.api.EnvironmentDetail; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,10 +76,7 @@ public AppIdentityService(final ApiConfiguration apiConfig, final ObjectMapper o this.objectMapper = objectMapper; } - private boolean isCached(final String applicationName) { - Preconditions.checkNotNull(applicationName); - return applicationIdentityCache.containsKey(applicationName); - } + /** * Retrieves the application identity given the environment details @@ -90,18 +88,17 @@ private Optional getAppIdentity(ApiConfiguration apiConfig) { if (applicationName == null) return Optional.absent(); - // new state with current timestamp - final AppIdentityState state = new AppIdentityState(); + // If there's no record create it. + if (!applicationIdentityCache.containsKey(applicationName)) { + applicationIdentityCache.put(applicationName, new AppIdentityState()); + } - final long now = System.currentTimeMillis(); + final AppIdentityState state = applicationIdentityCache.get(applicationName) ; - if (state.lastModified() + FIVE_MINUTES_MILLIS < now) { + if (state.lastModified() + FIVE_MINUTES_MILLIS < System.currentTimeMillis()) { try { final AppIdentity identity = identifyApp(apiConfig); - // Obtain AppIdentity for current app - applicationIdentityCache.put( - applicationName, state.updateAppIdentity(identity) - ); + state.setAppIdentity(identity); LOGGER.debug("Application identity: {}", identity); @@ -120,15 +117,26 @@ public Optional getAppIdentity(final String applicationName) { return applicationIdentityCache.get(applicationName).getAppIdentity(); } else { + // Update environment detail with new configured application name + final EnvironmentDetail updatedEnvDetail = + updateEnvironmentDetail(defaultApiConfig.getEnvDetail(), applicationName); + // use existing apiConfig, with new application name - final ApiConfiguration updatedApiConfig = defaultApiConfig.toBuilder().application(applicationName).build(); + final ApiConfiguration updatedApiConfig = defaultApiConfig.toBuilder() + .application(applicationName) + .envDetail(updatedEnvDetail) + .build(); + return getAppIdentity(updatedApiConfig); } } public Optional getAppIdentity() { - return getAppIdentity(defaultApiConfig); + if (isCached(defaultApiConfig.getApplication())) + return applicationIdentityCache.get(defaultApiConfig.getApplication()).getAppIdentity(); + else + return getAppIdentity(defaultApiConfig); } /** @@ -150,6 +158,27 @@ private AppIdentity identifyApp(ApiConfiguration apiConfig) throws IOException, return jsonReader.readValue(responseString); } + + private boolean isCached(final String applicationName) { + Preconditions.checkNotNull(applicationName); + + return + applicationIdentityCache.containsKey(applicationName) && + applicationIdentityCache.get(applicationName).getAppIdentity().isPresent(); + } + + + private EnvironmentDetail updateEnvironmentDetail(final EnvironmentDetail envDetail, final String newConfAppName) { + return EnvironmentDetail.newBuilder() + .deviceName(envDetail.getDeviceName()) + .appName(envDetail.getAppName()) + .appLocation(envDetail.getAppLocation()) + .configuredAppName(newConfAppName) + .configuredEnvironmentName(envDetail.getConfiguredEnvironmentName()) + .build(); + } + + /** * This class contains appIdentity and it's modification date */ @@ -173,9 +202,8 @@ public AppIdentityState(final AppIdentity appIdentity, long timestamp) { this.mayBeAppIdentity = Optional.fromNullable(appIdentity); } - public final AppIdentityState updateAppIdentity(final AppIdentity appIdentity) { + public final void setAppIdentity(final AppIdentity appIdentity) { mayBeAppIdentity = Optional.fromNullable(appIdentity); - return this; } public final Optional getAppIdentity() { From 6977f3afc011fbbb5396ff7c9b5120c216087575 Mon Sep 17 00:00:00 2001 From: blackopsdev Date: Wed, 17 Sep 2014 01:54:30 +0400 Subject: [PATCH 6/6] chache bug was fixed --- .../api/common/AppIdentityService.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/stackify/api/common/AppIdentityService.java b/src/main/java/com/stackify/api/common/AppIdentityService.java index dc2cdaf..e73dbe4 100644 --- a/src/main/java/com/stackify/api/common/AppIdentityService.java +++ b/src/main/java/com/stackify/api/common/AppIdentityService.java @@ -93,12 +93,14 @@ private Optional getAppIdentity(ApiConfiguration apiConfig) { applicationIdentityCache.put(applicationName, new AppIdentityState()); } - final AppIdentityState state = applicationIdentityCache.get(applicationName) ; + final AppIdentityState state = applicationIdentityCache.get(applicationName); + final long now = System.currentTimeMillis(); - if (state.lastModified() + FIVE_MINUTES_MILLIS < System.currentTimeMillis()) { + if ((state.lastModified() + FIVE_MINUTES_MILLIS) < now) { + state.touch(); try { final AppIdentity identity = identifyApp(apiConfig); - state.setAppIdentity(identity); + applicationIdentityCache.put(applicationName, state.updateAppIdentity(identity)); LOGGER.debug("Application identity: {}", identity); @@ -111,7 +113,11 @@ private Optional getAppIdentity(ApiConfiguration apiConfig) { } - + /** + * Retrieves the application identity given the environment details + * @param applicationName - name of the application + * @return The application identity + */ public Optional getAppIdentity(final String applicationName) { if (isCached(applicationName)) { return applicationIdentityCache.get(applicationName).getAppIdentity(); @@ -193,7 +199,7 @@ public AppIdentityState() { } public AppIdentityState(final AppIdentity appIdentity) { - this.touch(); + this.lastQueryTimeStamp = 0; this.mayBeAppIdentity = Optional.fromNullable(appIdentity); } @@ -202,12 +208,12 @@ public AppIdentityState(final AppIdentity appIdentity, long timestamp) { this.mayBeAppIdentity = Optional.fromNullable(appIdentity); } - public final void setAppIdentity(final AppIdentity appIdentity) { + public final AppIdentityState updateAppIdentity(final AppIdentity appIdentity) { mayBeAppIdentity = Optional.fromNullable(appIdentity); + return this; } public final Optional getAppIdentity() { - this.touch(); return mayBeAppIdentity; }