use of lombok.Synchronized in project pravega by pravega.
the class MockController method getSegmentsForStream.
@Synchronized
List<Segment> getSegmentsForStream(Stream stream) {
StreamConfiguration config = createdStreams.get(stream);
Preconditions.checkArgument(config != null, "Stream must be created first");
ScalingPolicy scalingPolicy = config.getScalingPolicy();
if (scalingPolicy.getScaleType() != ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS) {
throw new IllegalArgumentException("Dynamic scaling not supported with a mock controller");
}
List<Segment> result = new ArrayList<>(scalingPolicy.getMinNumSegments());
for (int i = 0; i < scalingPolicy.getMinNumSegments(); i++) {
result.add(new Segment(config.getScope(), config.getStreamName(), i));
}
return result;
}
use of lombok.Synchronized in project pravega by pravega.
the class InProcPravegaCluster method close.
@Override
@Synchronized
public void close() throws Exception {
if (isInProcSegmentStore) {
for (ServiceStarter starter : this.nodeServiceStarter) {
starter.shutdown();
}
}
if (isInProcController) {
for (ControllerServiceMain controller : this.controllerServers) {
controller.stopAsync();
}
}
if (this.zkService != null) {
this.zkService.close();
this.zkService = null;
}
}
use of lombok.Synchronized in project pravega by pravega.
the class InProcPravegaCluster method start.
/**
* Kicks off the cluster creation. right now it can be done only once in lifetime of a process.
* @throws Exception Exception thrown by ZK/HDFS etc.
*/
@Synchronized
public void start() throws Exception {
/*Start the ZK*/
if (isInProcZK) {
zkUrl = "localhost:" + zkPort;
startLocalZK();
} else {
URI zkUri = new URI("temp://" + zkUrl);
zkHost = zkUri.getHost();
zkPort = zkUri.getPort();
}
if (isInProcHDFS) {
startLocalHDFS();
hdfsUrl = String.format("hdfs://localhost:%d/", localHdfs.getNameNodePort());
}
cleanUpZK();
if (isInProcController) {
startLocalControllers();
}
if (isInProcSegmentStore) {
nodeServiceStarter = new ServiceStarter[segmentStoreCount];
startLocalSegmentStores();
}
}
use of lombok.Synchronized in project pravega by pravega.
the class S3FileSystemImpl method completeMultipartUpload.
@Synchronized
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
if (partMap == null) {
throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
}
try {
partMap.forEach((index, copyPart) -> {
if (copyPart.getKey() != copyPart.getSourceKey()) {
Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
targetChannel.transferFrom(sourceChannel, Files.size(targetPath), copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
targetChannel.close();
AclSize aclMap = this.aclMap.get(copyPart.getKey());
this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
} catch (IOException e) {
throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
}
}
});
} finally {
multipartUploads.remove(request.getKey());
}
return new CompleteMultipartUploadResult();
}
use of lombok.Synchronized in project pravega by pravega.
the class S3FileSystemImpl method putObject.
@Synchronized
@Override
public void putObject(String bucketName, String key, Range range, Object content) {
Path path = Paths.get(this.baseDir, bucketName, key);
try (FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE)) {
long startOffset = range.getFirst();
long length = range.getLast() + 1 - range.getFirst();
do {
long bytesTransferred = channel.transferFrom(Channels.newChannel((InputStream) content), range.getFirst(), range.getLast() + 1 - range.getFirst());
length -= bytesTransferred;
startOffset += bytesTransferred;
} while (length > 0);
AclSize aclKey = aclMap.get(key);
aclMap.put(key, aclKey.withSize(range.getLast() + 1));
} catch (IOException e) {
throw new S3Exception("NoObject", 404, "NoSuchKey", key);
}
}
Aggregations