Skip to content

Commit

Permalink
Moved implementation from Adapter classes to default methods in
Browse files Browse the repository at this point in the history
the interface to avoid binary compatibility problems in case the
interface is changed.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Nov 18, 2019
1 parent 65063da commit bf2482a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,45 +551,46 @@ interface FailureListener extends RequestListener
*/
interface Listener extends QueuedListener, BeginListener, HeadersListener, CommitListener, ContentListener, SuccessListener, FailureListener
{
@Override
public default void onQueued(Request request)
{
}

@Override
public default void onBegin(Request request)
{
}

@Override
public default void onHeaders(Request request)
{
}

@Override
public default void onCommit(Request request)
{
}

@Override
public default void onContent(Request request, ByteBuffer content)
{
}

@Override
public default void onSuccess(Request request)
{
}

@Override
public default void onFailure(Request request, Throwable failure)
{
}

/**
* An empty implementation of {@link Listener}
*/
class Adapter implements Listener
{
@Override
public void onQueued(Request request)
{
}

@Override
public void onBegin(Request request)
{
}

@Override
public void onHeaders(Request request)
{
}

@Override
public void onCommit(Request request)
{
}

@Override
public void onContent(Request request, ByteBuffer content)
{
}

@Override
public void onSuccess(Request request)
{
}

@Override
public void onFailure(Request request, Throwable failure)
{
}
}
}
}
109 changes: 58 additions & 51 deletions jetty-client/src/main/java/org/eclipse/jetty/client/api/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,70 +259,77 @@ interface CompleteListener extends ResponseListener
*/
interface Listener extends BeginListener, HeaderListener, HeadersListener, ContentListener, AsyncContentListener, DemandedContentListener, SuccessListener, FailureListener, CompleteListener
{
/**
* An empty implementation of {@link Listener}
*/
class Adapter implements Listener
@Override
public default void onBegin(Response response)
{
@Override
public void onBegin(Response response)
{
}
}

@Override
public boolean onHeader(Response response, HttpField field)
{
return true;
}
@Override
public default boolean onHeader(Response response, HttpField field)
{
return true;
}

@Override
public void onHeaders(Response response)
{
}
@Override
public default void onHeaders(Response response)
{
}

@Override
public void onContent(Response response, ByteBuffer content)
{
}
@Override
default void onBeforeContent(Response response, LongConsumer demand)
{
demand.accept(1);
}

@Override
public void onContent(Response response, ByteBuffer content, Callback callback)
{
try
{
onContent(response, content);
callback.succeeded();
}
catch (Throwable x)
{
callback.failed(x);
}
}
@Override
public default void onContent(Response response, ByteBuffer content)
{
}

@Override
public void onContent(Response response, LongConsumer demand, ByteBuffer content, Callback callback)
@Override
public default void onContent(Response response, ByteBuffer content, Callback callback)
{
try
{
onContent(response, content, Callback.from(() ->
{
callback.succeeded();
demand.accept(1);
}, callback::failed));
onContent(response, content);
callback.succeeded();
}

@Override
public void onSuccess(Response response)
catch (Throwable x)
{
callback.failed(x);
}
}

@Override
public void onFailure(Response response, Throwable failure)
@Override
public default void onContent(Response response, LongConsumer demand, ByteBuffer content, Callback callback)
{
onContent(response, content, Callback.from(() ->
{
}
callback.succeeded();
demand.accept(1);
}, callback::failed));
}

@Override
public void onComplete(Result result)
{
}
@Override
public default void onSuccess(Response response)
{
}

@Override
public default void onFailure(Response response, Throwable failure)
{
}

@Override
public default void onComplete(Result result)
{
}

/**
* An empty implementation of {@link Listener}
*/
class Adapter implements Listener
{
}
}
}

0 comments on commit bf2482a

Please sign in to comment.