Skip to content

Commit

Permalink
#291 create RandomAccessFile for each accepted connection
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Feb 21, 2017
1 parent c7a4fae commit c819aba
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientConfig;
import lombok.SneakyThrows;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -65,30 +65,28 @@ protected DockerClientConfig tryConfiguration(String dockerHost) {
}

@Slf4j
@RequiredArgsConstructor
static class NamedPipeProxy {

final ExecutorService executorService = Executors.newCachedThreadPool();

RandomAccessFile randomAccessFile;

@SneakyThrows(FileNotFoundException.class)
public NamedPipeProxy(File file) {
randomAccessFile = new RandomAccessFile(file, "rw");
}
final File file;

InetSocketAddress start() throws IOException {
ServerSocket listenSocket = new ServerSocket();
listenSocket.bind(new InetSocketAddress("localhost", 0));

executorService.submit(() -> {
log.debug("Listening on {} and proxying to {}", listenSocket.getLocalSocketAddress(), randomAccessFile);
log.debug("Listening on {} and proxying to {}", listenSocket.getLocalSocketAddress(), file);

try {
while (!Thread.interrupted()) {
try {
Socket incomingSocket = listenSocket.accept();
log.debug("Accepting incoming connection from {}", incomingSocket.getRemoteSocketAddress());

RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");

executorService.submit(() -> {
try (
InputStream in = incomingSocket.getInputStream();
Expand Down

0 comments on commit c819aba

Please sign in to comment.