create(name, null);
}
@Override
public void create(String name, @Nullable Properties props) throws Exception {
Location streamLocation = streamBaseLocation.append(name);
Locations.mkdirsIfNotExists(streamLocation);
Location configLocation = streamBaseLocation.append(name).append(CONFIG_FILE_NAME);
if (!configLocation.createNew()) {
// Stream already exists
return;
}
Properties properties = (props == null) ? new Properties() : props;
long partitionDuration = Long.parseLong(properties.getProperty(Constants.Stream.PARTITION_DURATION,
cConf.get(Constants.Stream.PARTITION_DURATION)));
long indexInterval = Long.parseLong(properties.getProperty(Constants.Stream.INDEX_INTERVAL,
cConf.get(Constants.Stream.INDEX_INTERVAL)));
long ttl = Long.parseLong(properties.getProperty(Constants.Stream.TTL,
cConf.get(Constants.Stream.TTL)));
Location tmpConfigLocation = configLocation.getTempFile(null);
StreamConfig config = new StreamConfig(name, partitionDuration, indexInterval, ttl, streamLocation);
CharStreams.write(GSON.toJson(config), CharStreams.newWriterSupplier(
Locations.newOutputSupplier(tmpConfigLocation), Charsets.UTF_8));
try {
// Windows does not allow renaming if the destination file exists so we must delete the configLocation
if (OSDetector.isWindows()) {
configLocation.delete();
}
tmpConfigLocation.renameTo(streamBaseLocation.append(name).append(CONFIG_FILE_NAME));
} finally {
if (tmpConfigLocation.exists()) {
tmpConfigLocation.delete();
}
}
}