/** * Finds a shared {@link ObjectMapper} or makes a new one, stored against the servlet context; * returns null if a shared instance cannot be created. */ public static ObjectMapper findSharedObjectMapper(ManagementContext mgmt) { checkNotNull(mgmt, "mgmt"); synchronized (mgmt) { ConfigKey<ObjectMapper> key = ConfigKeys.newConfigKey(ObjectMapper.class, BROOKLYN_REST_OBJECT_MAPPER); ObjectMapper mapper = (ObjectMapper) mgmt.getScratchpad().get(key); if (mapper != null) return mapper; mapper = newPrivateObjectMapper(mgmt); log.debug("Storing new ObjectMapper against "+mgmt+" because no ServletContext available: "+mapper); mgmt.getScratchpad().put(key, mapper); return mapper; } }
mgmt.getScratchpad().put(BrooklynWebConfig.SECURITY_PROVIDER_INSTANCE, delegate);
public CampPlatformWithJustBrooklynMgmt(ManagementContext mgmt) { this.mgmt = mgmt; // Deprecated in 0.11.0. Add to release notes and remove in next release. ((BrooklynProperties)mgmt.getConfig()).put(BrooklynCampConstants.CAMP_PLATFORM, this); mgmt.getScratchpad().put(BrooklynCampConstants.CAMP_PLATFORM, this); }
@Test public void testScratchpadLostOnRebind() throws Exception { ConfigKey<String> myKey = ConfigKeys.newStringConfigKey("my"); origManagementContext.getScratchpad().put(myKey, "key"); assertEquals(origManagementContext.getScratchpad().get(myKey), "key"); rebind(); assertFalse(newManagementContext.getScratchpad().contains(myKey), "Scratchpad lost on rebind"); } }
@Test public void testScratchpadSurvivesReload() throws Exception { String globalPropertiesContents = "brooklyn.location.localhost.displayName=myname"; Files.write(globalPropertiesContents, globalPropertiesFile, Charsets.UTF_8); BrooklynProperties brooklynProperties = BrooklynProperties.Factory.builderDefault() .globalPropertiesFile(globalPropertiesFile.getAbsolutePath()) .build(); context = LocalManagementContextForTests.builder(true).useProperties(brooklynProperties).build(); ConfigKey<String> myKey = ConfigKeys.newStringConfigKey("my"); context.getScratchpad().put(myKey, "key"); assertEquals(context.getScratchpad().get(myKey), "key"); context.reloadBrooklynProperties(); assertEquals(context.getScratchpad().get(myKey), "key"); } }