public abstract class AbstractCompositeService<T extends Service<I,O>,I extends Request,O extends Response> extends Object implements Service<I,O>
Service implementation that enables composing multiple Services into one.
Extend this class to build your own composite Service. e.g.
public class MyService extends AbstractCompositeService<HttpService, HttpRequest, HttpResponse> {
public MyService() {
super(CompositeServiceEntry.ofPrefix("/foo/", new FooService()),
CompositeServiceEntry.ofPrefix("/bar/", new BarService()),
CompositeServiceEntry.ofCatchAll(new OtherService()));
}
}
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractCompositeService(CompositeServiceEntry<T>... services)
Creates a new instance with the specified
CompositeServiceEntrys. |
protected |
AbstractCompositeService(Iterable<CompositeServiceEntry<T>> services)
Creates a new instance with the specified
CompositeServiceEntrys. |
| Modifier and Type | Method and Description |
|---|---|
protected Routed<T> |
findService(RoutingContext routingCtx)
|
O |
serve(ServiceRequestContext ctx,
I req)
Serves an incoming
Request. |
void |
serviceAdded(ServiceConfig cfg)
Invoked when this service has been added to a
Server with the specified
configuration. |
protected T |
serviceAt(int index)
|
protected List<CompositeServiceEntry<T>> |
services()
Returns the list of
CompositeServiceEntrys added to this composite Service. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitas, decorate, shouldCachePath@SafeVarargs protected AbstractCompositeService(CompositeServiceEntry<T>... services)
CompositeServiceEntrys.protected AbstractCompositeService(Iterable<CompositeServiceEntry<T>> services)
CompositeServiceEntrys.public void serviceAdded(ServiceConfig cfg) throws Exception
ServiceServer with the specified
configuration. Please note that this method can be invoked more than once if this service
has been added more than once.protected List<CompositeServiceEntry<T>> services()
CompositeServiceEntrys added to this composite Service.protected T serviceAt(int index)
protected Routed<T> findService(RoutingContext routingCtx)
routingCtx - a context to find the Service.Service wrapped by Routed if there's a match.
Routed.empty() if there's no match.Copyright © 2020 LeanCloud. All rights reserved.