Skip to content

Commit

Permalink
458527 - Implement an async proxy servlet that can perform content tr…
Browse files Browse the repository at this point in the history
…ansformations.
  • Loading branch information
sbordet committed Jan 27, 2015
1 parent 159884a commit a52703c
Show file tree
Hide file tree
Showing 7 changed files with 2,224 additions and 516 deletions.
Expand Up @@ -23,7 +23,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.util.log.Log;
Expand Down Expand Up @@ -60,7 +59,7 @@ public HttpConversation getConversation()
return request.getConversation();
}

public Request getRequest()
public HttpRequest getRequest()
{
return request;
}
Expand Down
Expand Up @@ -94,6 +94,7 @@ public class DeferredContentProvider implements AsyncContentProvider, Callback,
private final AtomicReference<Listener> listener = new AtomicReference<>();
private final DeferredContentProviderIterator iterator = new DeferredContentProviderIterator();
private final AtomicBoolean closed = new AtomicBoolean();
private long length = -1;
private int size;
private Throwable failure;

Expand All @@ -114,12 +115,23 @@ public void setListener(Listener listener)
if (!this.listener.compareAndSet(null, listener))
throw new IllegalStateException(String.format("The same %s instance cannot be used in multiple requests",
AsyncContentProvider.class.getName()));

if (isClosed())
{
synchronized (lock)
{
long total = 0;
for (AsyncChunk chunk : chunks)
total += chunk.buffer.remaining();
length = total;
}
}
}

@Override
public long getLength()
{
return -1;
return length;
}

/**
Expand Down Expand Up @@ -200,6 +212,11 @@ public void close()
offer(CLOSE);
}

public boolean isClosed()
{
return closed.get();
}

@Override
public void succeeded()
{
Expand Down

0 comments on commit a52703c

Please sign in to comment.