@Override public void consume(Message message) { try { String content = jsonHandler.serialize(message); byte[] contentBytes = content.getBytes(encoding); int contentLength = contentBytes.length; String header = getHeader(contentLength); byte[] headerBytes = header.getBytes(StandardCharsets.US_ASCII); synchronized (outputLock) { output.write(headerBytes); output.write(contentBytes); output.flush(); } } catch (IOException exception) { throw new JsonRpcException(exception); } }
/** * Whether the given exception indicates that the currently accessed stream has been closed. */ public static boolean indicatesStreamClosed(Throwable thr) { return thr instanceof InterruptedIOException || thr instanceof ClosedChannelException || thr instanceof SocketException && ("Connection reset".equals(thr.getMessage()) || "Socket closed".equals(thr.getMessage())) || thr instanceof JsonRpcException && indicatesStreamClosed(thr.getCause()); }
if (JsonRpcException.indicatesStreamClosed(exception)) fireStreamClosed(exception); else throw new JsonRpcException(exception); } finally { this.callback = null;
if (JsonRpcException.indicatesStreamClosed(exception)) fireStreamClosed(exception); else throw new JsonRpcException(exception); } finally { this.callback = null;
@Override public void consume(Message message) { try { String content = jsonHandler.serialize(message); byte[] contentBytes = content.getBytes(encoding); int contentLength = contentBytes.length; String header = getHeader(contentLength); byte[] headerBytes = header.getBytes(StandardCharsets.US_ASCII); synchronized (outputLock) { output.write(headerBytes); output.write(contentBytes); output.flush(); } } catch (IOException exception) { throw new JsonRpcException(exception); } }
/** * Whether the given exception indicates that the currently accessed stream has been closed. */ public static boolean indicatesStreamClosed(Throwable thr) { return thr instanceof InterruptedIOException || thr instanceof ClosedChannelException || thr instanceof SocketException && ("Connection reset".equals(thr.getMessage()) || "Socket closed".equals(thr.getMessage())) || thr instanceof JsonRpcException && indicatesStreamClosed(thr.getCause()); }
@Override public void consume(Message message) throws JsonRpcException { throw new JsonRpcException(new SocketException("Socket closed")); } };
/** * Send a notification to the remote endpoint. */ @Override public void notify(String method, Object parameter) { NotificationMessage notificationMessage = createNotificationMessage(method, parameter); try { out.consume(notificationMessage); } catch (Exception exception) { Level logLevel = JsonRpcException.indicatesStreamClosed(exception) ? Level.INFO : Level.WARNING; LOG.log(logLevel, "Failed to send notification message.", exception); } }
@Override public void consume(Message message) throws JsonRpcException { throw new JsonRpcException(new SocketException("Permission denied: connect")); } };
/** * Send a notification to the remote endpoint. */ @Override public void notify(String method, Object parameter) { NotificationMessage notificationMessage = createNotificationMessage(method, parameter); try { out.consume(notificationMessage); } catch (Exception exception) { Level logLevel = JsonRpcException.indicatesStreamClosed(exception) ? Level.INFO : Level.WARNING; LOG.log(logLevel, "Failed to send notification message.", exception); } }