|
30 | 30 |
|
31 | 31 | public class NativeTransport extends AbstractMessageTransport {
|
32 | 32 | private final BiConsumer<byte[], Object> sendMessageToNative;
|
| 33 | + private final Logger logger; |
33 | 34 |
|
34 | 35 | protected NativeTransport(Logger logger, BiConsumer<byte[], Object> sendMessageToNative) {
|
35 | 36 | super(logger);
|
| 37 | + this.logger = logger; |
36 | 38 | this.sendMessageToNative = sendMessageToNative;
|
37 | 39 | }
|
38 | 40 |
|
39 | 41 | @Override
|
40 |
| - protected void doStart() throws ProtocolException, IOException {} |
| 42 | + protected void doStart() {} |
41 | 43 |
|
42 | 44 | @Override
|
43 | 45 | protected void doClose() {}
|
44 | 46 |
|
45 | 47 | @Override
|
46 |
| - protected void doSend(Message message) throws IOException, ProtocolException { |
| 48 | + protected void doSend(Message message) { |
47 | 49 | try (var os = new ByteArrayOutputStream();
|
48 | 50 | var packer = MessagePack.newDefaultPacker(os)) {
|
49 | 51 | var encoder = new ServerMessagePackEncoder(packer);
|
50 | 52 | encoder.encode(message);
|
51 | 53 | // TODO: Propagate `handlerContext` through to `sendMessageToNative`
|
52 | 54 | sendMessageToNative.accept(os.toByteArray(), null);
|
| 55 | + } catch (IOException | ProtocolException e) { |
| 56 | + // TODO: Test that this error message is visible. |
| 57 | + logger.log(e.getMessage()); |
53 | 58 | }
|
54 | 59 | }
|
55 | 60 |
|
56 | 61 | // TODO: Propagate `handlerContext` through to `sendMessageToNative`
|
57 |
| - public void sendMessage(int length, CCharPointer ptr, VoidPointer handlerContext) |
58 |
| - throws IOException, ProtocolException { |
| 62 | + public void sendMessage(int length, CCharPointer ptr, VoidPointer handlerContext) { |
59 | 63 | try (var is = new NativeInputStream(length, ptr);
|
60 | 64 | var unpacker = MessagePack.newDefaultUnpacker(is)) {
|
61 | 65 | var message = new ServerMessagePackDecoder(unpacker).decode();
|
62 | 66 | assert message != null;
|
63 | 67 | accept(message);
|
| 68 | + } catch (IOException | ProtocolException e) { |
| 69 | + // TODO: Test that this error message is visible. |
| 70 | + logger.log(e.getMessage()); |
64 | 71 | }
|
65 | 72 | }
|
66 | 73 | }
|
0 commit comments