public abstract class DirectClient<T> extends Object implements org.pipservices.commons.config.IConfigurable, org.pipservices.commons.run.IOpenable, org.pipservices.commons.refer.IReferenceable
It is used when multiple microservices are deployed in a single container (monolyth) and communication between them can be done by direct calls rather then through the network.
### Configuration parameters ###
### References ###
### Example ###
class MyDirectClient extends DirectClient<IMyController> implements IMyClient {
public MyDirectClient() {
super();
this._dependencyResolver.put('controller', new Descriptor(
"mygroup", "controller", "*", "*", "*"));
}
...
public MyData getData(String correlationId, String id) {
Timing timing = this.instrument(correlationId, 'myclient.get_data');
MyData result = this._controller.getData(correlationId, id);
timing.endTiming();
return result;
}
...
}
MyDirectClient client = new MyDirectClient();
client.setReferences(References.fromTuples(
new Descriptor("mygroup","controller","default","default","1.0"), controller
));
MyData data = client.getData("123", "1");
...
| Modifier and Type | Field and Description |
|---|---|
protected T |
_controller
The controller reference.
|
protected org.pipservices.components.count.CompositeCounters |
_counters
The performance counters
|
protected org.pipservices.commons.refer.DependencyResolver |
_dependencyResolver
The dependency resolver to get controller reference.
|
protected org.pipservices.components.log.CompositeLogger |
_logger
The logger.
|
protected boolean |
_opened
The open flag.
|
| Constructor and Description |
|---|
DirectClient()
Creates a new instance of the client.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close(String correlationId)
Closes component and frees used resources.
|
void |
configure(org.pipservices.commons.config.ConfigParams config)
Configures component by passing configuration parameters.
|
protected org.pipservices.components.count.Timing |
instrument(String correlationId,
String methodName)
Adds instrumentation to log calls and measure call time.
|
boolean |
isOpen()
Checks if the component is opened.
|
void |
open(String correlationId)
Opens the component.
|
void |
setReferences(org.pipservices.commons.refer.IReferences references)
Sets references to dependent components.
|
protected T _controller
protected org.pipservices.components.log.CompositeLogger _logger
protected org.pipservices.components.count.CompositeCounters _counters
protected org.pipservices.commons.refer.DependencyResolver _dependencyResolver
protected boolean _opened
public void configure(org.pipservices.commons.config.ConfigParams config)
throws org.pipservices.commons.errors.ConfigException
configure in interface org.pipservices.commons.config.IConfigurableconfig - configuration parameters to be set.org.pipservices.commons.errors.ConfigException - when configuration is wrong.public void setReferences(org.pipservices.commons.refer.IReferences references)
throws org.pipservices.commons.refer.ReferenceException
setReferences in interface org.pipservices.commons.refer.IReferenceablereferences - references to locate the component dependencies.org.pipservices.commons.refer.ReferenceException - when no found references.protected org.pipservices.components.count.Timing instrument(String correlationId, String methodName)
correlationId - (optional) transaction id to trace execution through
call chain.methodName - a method name.public boolean isOpen()
isOpen in interface org.pipservices.commons.run.IOpenablepublic void open(String correlationId) throws org.pipservices.commons.errors.ConnectionException
open in interface org.pipservices.commons.run.IOpenablecorrelationId - (optional) transaction id to trace execution through
call chain.org.pipservices.commons.errors.ConnectionException - when controller reference is missing.public void close(String correlationId)
close in interface org.pipservices.commons.run.IClosablecorrelationId - (optional) transaction id to trace execution through
call chain.Copyright © 2018. All rights reserved.