use of io.dingodb.common.error.DingoException in project dingo by dingodb.
the class RemoteServerCaller method call.
public static <T> T call(Supplier<Channel> channelSupplier, Message msg, Function<ByteBuffer, T> readFunction) {
Channel channel = channelSupplier.get();
CompletableFuture<T> future = new CompletableFuture<>();
channel.registerMessageListener(callHandler(future, readFunction));
channel.send(msg);
try {
return future.get(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
EXEC_INTERRUPT.throwFormatError("call remote server", currentThread().getName(), e.getMessage());
} catch (ExecutionException e) {
if (e.getCause() instanceof DingoException) {
throw (DingoException) e.getCause();
}
EXEC.throwFormatError("call remote server", currentThread().getName(), e.getMessage());
} catch (TimeoutException e) {
EXEC_TIMEOUT.throwFormatError("call remote server", currentThread().getName(), e.getMessage());
}
throw UNKNOWN.asException();
}
use of io.dingodb.common.error.DingoException in project dingo by dingodb.
the class MetaServiceHandler method onMessage.
private void onMessage(Message message, Channel channel) {
ByteBuffer buffer = ByteBuffer.wrap(message.toBytes());
MetaServiceCode code = MetaServiceCode.valueOf(PrimitiveCodec.readZigZagInt(buffer));
switch(code) {
case LISTENER_TABLE:
// todo
break;
case REFRESH_TABLES:
// todo
break;
case GET_TABLE:
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(encodeZigZagInt(ServerError.OK.getCode()));
getAndEncodeTableEntry(readString(buffer), outputStream);
channel.send(SimpleMessage.builder().content(outputStream.toByteArray()).build());
} catch (IOException e) {
log.error("Serialize/deserialize table info error.", e);
channel.send(ServerError.IO.message());
} catch (NullPointerException e) {
channel.send(ServerError.TABLE_NOT_FOUND.message());
}
break;
case CREATE_TABLE:
try {
String name = readString(buffer);
TableDefinition definition = TableDefinition.fromJson(readString(buffer));
metaService.createTable(name, definition);
channel.send(ServerError.OK.message());
} catch (IOException e) {
log.error("Serialize/deserialize table info error.", e);
channel.send(ServerError.IO.message());
} catch (DingoException error) {
channel.send(ServerError.message(error));
}
break;
case DELETE_TABLE:
try {
// todo delete table data
String name = readString(buffer);
if (metaService.dropTable(name)) {
channel.send(ServerError.OK.message());
} else {
channel.send(ServerError.UNKNOWN.message());
}
} catch (DingoException error) {
channel.send(ServerError.message(error));
}
break;
case GET_ALL:
try {
Map<String, TableDefinition> tableDefinitions = metaService.getTableDefinitions();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] size = encodeZigZagInt(tableDefinitions.size());
outputStream.write(encodeZigZagInt(ServerError.OK.getCode()));
outputStream.write(size);
outputStream.flush();
for (String name : tableDefinitions.keySet()) {
getAndEncodeTableEntry(name, outputStream);
}
channel.send(SimpleMessage.builder().content(outputStream.toByteArray()).build());
} catch (IOException e) {
log.error("Serialize/deserialize table info error.", e);
channel.send(ServerError.IO.message());
}
break;
default:
channel.send(UNSUPPORTED_CODE.message());
}
}
Aggregations