use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.
the class ContainerResource method convertToJson.
private CompletionStage<RestResponse> convertToJson(RestRequest restRequest) {
NettyRestResponse.Builder responseBuilder = checkCacheManager(restRequest);
if (responseBuilder.getHttpStatus() == NOT_FOUND)
return completedFuture(responseBuilder.build());
ContentSource contents = restRequest.contents();
ConfigurationBuilderHolder builderHolder = parserRegistry.parse(new String(contents.rawContent(), UTF_8));
Map.Entry<String, ConfigurationBuilder> entry = builderHolder.getNamedConfigurationBuilders().entrySet().iterator().next();
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
invocationHelper.getParserRegistry().serialize(w, entry.getKey(), entry.getValue().build());
}
responseBuilder.contentType(APPLICATION_JSON).entity(sw.toString());
return completedFuture(responseBuilder.build());
}
use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.
the class CounterConfigurationSerializer method serializeConfigurations.
/**
* It serializes a {@link List} of {@link AbstractCounterConfiguration} to an {@link OutputStream}.
* @param os the {@link OutputStream} to write to.
* @param configs the {@link List} if {@link AbstractCounterConfiguration}.
*/
public void serializeConfigurations(OutputStream os, Collection<AbstractCounterConfiguration> configs) {
BufferedOutputStream output = new BufferedOutputStream(os);
ConfigurationWriter writer = ConfigurationWriter.to(output).build();
writer.writeStartDocument();
writer.writeStartMap(Element.COUNTERS);
writeConfigurations(writer, configs);
writer.writeEndMap();
writer.writeEndDocument();
Util.close(writer);
}
use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.
the class OverlayLocalConfigurationStorage method persistConfigurations.
private void persistConfigurations(String prefix, File file, File lock, Set<String> configNames) {
// Renaming is done using file locks, which are acquired by the entire JVM.
// Use a regular lock as well, so another thread cannot lock the file at the same time
// and cause an OverlappingFileLockException.
persistenceLock.lock();
try {
GlobalConfiguration globalConfiguration = configurationManager.getGlobalConfiguration();
File sharedDirectory = new File(globalConfiguration.globalState().sharedPersistentLocation());
sharedDirectory.mkdirs();
File temp = File.createTempFile(prefix, null, sharedDirectory);
Map<String, Configuration> configurationMap = new HashMap<>();
for (String config : configNames) {
configurationMap.put(config, configurationManager.getConfiguration(config, true));
}
try (ConfigurationWriter writer = ConfigurationWriter.to(new FileOutputStream(temp)).clearTextSecrets(true).prettyPrint(true).build()) {
parserRegistry.serialize(writer, null, configurationMap);
}
try {
renameTempFile(temp, lock, file);
} catch (Exception e) {
throw CONFIG.cannotRenamePersistentFile(temp.getAbsolutePath(), file, e);
}
} catch (Exception e) {
throw CONFIG.errorPersistingGlobalConfiguration(e);
} finally {
persistenceLock.unlock();
}
}
use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.
the class ParserRegistry method serialize.
/**
* Serializes a full configuration to an {@link OutputStream}
*
* @param os the output stream where the configuration should be serialized to
* @param globalConfiguration the global configuration. Can be null
* @param configurations a map of named configurations
* @deprecated use {@link #serialize(ConfigurationWriter, GlobalConfiguration, Map)} instead
*/
@Deprecated
public void serialize(OutputStream os, GlobalConfiguration globalConfiguration, Map<String, Configuration> configurations) {
ConfigurationWriter writer = ConfigurationWriter.to(os).build();
serialize(writer, globalConfiguration, configurations);
try {
writer.close();
} catch (Exception e) {
throw new ConfigurationWriterException(e);
}
}
use of org.infinispan.commons.configuration.io.ConfigurationWriter in project infinispan by infinispan.
the class SerializationUtils method toJson.
public static String toJson(RemoteStoreConfiguration configuration) {
ConfigurationBuilder builder = new ConfigurationBuilder();
RemoteStoreConfigurationBuilder storeBuilder = builder.persistence().addStore(RemoteStoreConfigurationBuilder.class);
storeBuilder.read(configuration);
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).withType(APPLICATION_JSON).build()) {
parserRegistry.serialize(w, null, builder.build());
}
return Json.read(sw.toString()).at("local-cache").at("persistence").toString();
}
Aggregations