use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.
the class DataEncap method consume.
/**
* Middle process
*
* @param request
* @param type
*/
public static IpcData consume(final IpcRequest request, final IpcType type) {
final IpcData ipcData = new IpcData();
final IpcEnvelop envelop = request.getEnvelop();
final String data = envelop.getBody();
final JsonObject json = new JsonObject(data);
// Address convert
if (json.containsKey("address")) {
ipcData.setAddress(json.getString("address"));
json.remove("address");
}
ipcData.setData(Buffer.buffer(data));
ipcData.setType(type);
return ipcData;
}
use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.
the class UnityTunnel method build.
private IpcData build(final Envelop community, final Envelop envelop) {
// Headers and user could not be modified
if (null != envelop) {
community.setHeaders(envelop.headers());
community.setUser(envelop.user());
}
// IpcResponse -> Output Envelop
final IpcData responseData = new IpcData();
responseData.setType(IpcType.UNITY);
DataEncap.in(responseData, community);
return responseData;
}
use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.
the class RpcClientImpl method connect.
@Override
public RpcClient connect(final JsonObject config, final JsonObject data, final Handler<AsyncResult<JsonObject>> handler) {
final Record record = RpcHelper.getRecord(config);
// Service Configuration
final String name = config.getString(Key.NAME);
final String address = config.getString(Key.ADDR);
final JsonObject normalized = RpcHelper.normalize(name, config, record);
this.holder = this.lookupHolder(this.vertx, name, normalized);
// Get Channel
final IpcType type = Ut.toEnum(IpcType.class, config.getString(Key.TYPE));
final RpcStub stub = this.getStub(type);
// Future result return to client.
final IpcData request = new IpcData();
request.setType(type);
request.setAddress(address);
// The same operation for request.
DataEncap.in(request, record);
DataEncap.in(request, Envelop.success(data));
LOGGER.info(Info.CLIENT_TRAFFIC, request.toString());
final Future<JsonObject> future = stub.traffic(request);
future.setHandler(res -> handler.handle(Future.succeededFuture(res.result())));
return this;
}
use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.
the class UnityTunnel method init.
@Override
public BindableService init(final Vertx vertx) {
return new UnityServiceGrpc.UnityServiceVertxImplBase() {
@Override
public void unityCall(final IpcRequest request, final Future<IpcResponse> future) {
// IpcData building
final IpcData data = DataEncap.consume(request, IpcType.UNITY);
// Method called with message handler
final Envelop envelop = DataEncap.consume(data);
// Method handle
final Method method = IPCS.get(data.getAddress());
// Work mode
if (null == method) {
// No Rpc Handler here
final Envelop community = Envelop.failure(new _501RpcMethodMissingException(this.getClass(), data.getAddress()));
// Build IpcData
final IpcData responseData = UnityTunnel.this.build(community, envelop);
future.complete(DataEncap.out(responseData));
} else {
// Execute Transit
final Transit transit = UnityTunnel.this.getTransit(method, vertx);
// Execute Transit
final Future<Envelop> result = transit.async(envelop);
result.setHandler(res -> {
final IpcData responseData = UnityTunnel.this.build(res.result(), envelop);
future.complete(DataEncap.out(responseData));
});
}
}
};
}
use of io.vertx.up.atom.flux.IpcData in project vertx-zero by silentbalanceyh.
the class TunnelClient method send.
public Future<Envelop> send(final Envelop envelop) {
// 1. Extract address
final String address = this.getValue("to");
final IpcType type = this.getValue("type");
// 2. Record extract
final Record record = this.findTarget();
// 3. Convert IpcData
final IpcData data = new IpcData();
data.setType(type);
data.setAddress(address);
// 4. In data
DataEncap.in(data, record);
DataEncap.in(data, envelop);
// 5. Stub
final Spear stub = STUBS.getOrDefault(type, Instance.singleton(UnitySpear.class));
return stub.send(this.vertx, data);
}
Aggregations