Skip to content

Commit

Permalink
Implemented register methods
Browse files Browse the repository at this point in the history
  • Loading branch information
trajano committed Dec 28, 2017
1 parent a28b795 commit e77951f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -209,56 +209,68 @@ public boolean isDone() {
return done.get();
}

/**
* {@inheritDoc}
*/
@Override
public boolean isSuspended() {

return suspended.get();
}

/**
* Not used. {@inheritDoc}
*
* @return empty set.
* {@inheritDoc}
*/
@Override
public Collection<Class<?>> register(final Class<?> callback) {
public Collection<Class<?>> register(final Class<?> callbackClass) {

return Collections.emptySet();
final Object cb = providerFactory.createProviderInstance(callbackClass);
return register(cb);
}

/**
* Not used. {@inheritDoc}
*
* @return empty map.
* {@inheritDoc}
*/
@Override
public Map<Class<?>, Collection<Class<?>>> register(final Class<?> callback,
final Class<?>... callbacks) {

return Collections.emptyMap();
final Map<Class<?>, Collection<Class<?>>> map = new HashMap<>();
map.put(callback, register(callback));
for (final Class<?> other : callbacks) {
map.put(other, register(other));
}
return map;
}

/**
* Not used. {@inheritDoc}
*
* @return empty set.
* {@inheritDoc}
*/
@Override
public Collection<Class<?>> register(final Object callback) {

return Collections.emptySet();
final List<Class<?>> registered = new LinkedList<>();
if (callback instanceof CompletionCallback) {
completionCallbacks.add((CompletionCallback) callback);
registered.add(CompletionCallback.class);
}
return registered;
}

/**
* Not used. {@inheritDoc}
*
* @return empty map.
* {@inheritDoc}
*/
@Override
public Map<Class<?>, Collection<Class<?>>> register(final Object callback,
final Object... callbacks) {

return Collections.emptyMap();
final Map<Class<?>, Collection<Class<?>>> map = new HashMap<>();
map.put(callback.getClass(), register(callback));
for (final Object other : callbacks) {
map.put(other.getClass(), register(other));
}
return map;

}

/**
Expand Down Expand Up @@ -306,7 +318,6 @@ private boolean sendData(final Object entity) {

done.set(true);
cancelTimer();
completionCallbacks.forEach(callback -> callback.onComplete(null));
return true;
} catch (final IOException e) {
throw new InternalServerErrorException(e);
Expand Down Expand Up @@ -392,8 +403,7 @@ public void setWriterInterceptors(final WriterInterceptor[] writerInterceptors)
*/
private void writeResponse(final Response response) throws IOException {

ServerResponseWriter.writeNomapResponse((BuiltResponse) response, request, new VertxHttpResponse(routingContext), providerFactory, t -> {
}, true);
ServerResponseWriter.writeNomapResponse((BuiltResponse) response, request, new VertxHttpResponse(routingContext), providerFactory, throwable -> completionCallbacks.forEach(c -> c.onComplete(throwable)), true);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class HelloResource {
public void async(@Suspended final AsyncResponse asyncResponse) throws InterruptedException,
ExecutionException {

asyncResponse.register(new TestCallback());
final Future<Response> futureResponseFromClient = jaxrsClient.target("https://accounts.google.com/.well-known/openid-configuration").request().header(javax.ws.rs.core.HttpHeaders.USER_AGENT, "curl/7.55.1").async().get();

final Response responseFromClient = futureResponseFromClient.get();
Expand Down
22 changes: 22 additions & 0 deletions sample-ms/src/main/java/net/trajano/ms/example/TestCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.trajano.ms.example;

import javax.ws.rs.container.CompletionCallback;
import javax.ws.rs.ext.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Provider
public class TestCallback implements
CompletionCallback {

private static final Logger LOG = LoggerFactory.getLogger(TestCallback.class);

@Override
public void onComplete(final Throwable throwable) {

LOG.debug("Complete throwable={}", throwable, throwable);

}

}

0 comments on commit e77951f

Please sign in to comment.