FileDescriptor Class — spring-boot Architecture
Architecture documentation for the FileDescriptor class in FileDescriptor.java from the spring-boot codebase.
Entity Profile
Source Code
buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/FileDescriptor.java lines 29–117
class FileDescriptor {
private final Handle openHandle;
private final Handle closedHandler;
private final IntConsumer closer;
private Status status = Status.OPEN;
private int referenceCount;
FileDescriptor(int handle, IntConsumer closer) {
this.openHandle = new Handle(handle);
this.closedHandler = new Handle(-1);
this.closer = closer;
}
/**
* Acquire an instance of the actual {@link Handle}. The caller must
* {@link Handle#close() close} the resulting handle when done.
* @return the handle
*/
synchronized Handle acquire() {
this.referenceCount++;
return (this.status != Status.OPEN) ? this.closedHandler : this.openHandle;
}
private synchronized void release() {
this.referenceCount--;
if (this.referenceCount == 0 && this.status == Status.CLOSE_PENDING) {
this.closer.accept(this.openHandle.value);
this.status = Status.CLOSED;
}
}
/**
* Close the underlying file when all handles have been released.
*/
synchronized void close() {
if (this.status == Status.OPEN) {
if (this.referenceCount == 0) {
this.closer.accept(this.openHandle.value);
this.status = Status.CLOSED;
}
else {
this.status = Status.CLOSE_PENDING;
}
}
}
/**
* The status of the file descriptor.
*/
private enum Status {
OPEN, CLOSE_PENDING, CLOSED
}
/**
* Provides access to the actual file descriptor handle.
*/
final class Handle implements Closeable {
private final int value;
private Handle(int value) {
this.value = value;
}
boolean isClosed() {
return this.value == -1;
}
int intValue() {
return this.value;
}
@Override
public void close() throws IOException {
if (!isClosed()) {
release();
}
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free