
io.datakernel.rpc.server.RpcServerConnection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datakernel-rpc Show documentation
Show all versions of datakernel-rpc Show documentation
High-performance and fault-tolerant remote procedure call module for building distributed applications.
Provides a high-performance asynchronous binary RPC streaming protocol.
The newest version!
/*
* Copyright (C) 2015-2018 SoftIndex LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datakernel.rpc.server;
import io.datakernel.common.parse.ParseException;
import io.datakernel.datastream.StreamDataAcceptor;
import io.datakernel.eventloop.jmx.EventStats;
import io.datakernel.eventloop.jmx.ExceptionStats;
import io.datakernel.eventloop.jmx.JmxRefreshable;
import io.datakernel.eventloop.jmx.ValueStats;
import io.datakernel.jmx.api.JmxAttribute;
import io.datakernel.promise.Promise;
import io.datakernel.rpc.protocol.RpcControlMessage;
import io.datakernel.rpc.protocol.RpcMessage;
import io.datakernel.rpc.protocol.RpcRemoteException;
import io.datakernel.rpc.protocol.RpcStream;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.util.Map;
public final class RpcServerConnection implements RpcStream.Listener, JmxRefreshable {
private static final Logger logger = LoggerFactory.getLogger(RpcServerConnection.class);
private StreamDataAcceptor downstreamDataAcceptor;
private final RpcServer rpcServer;
private final RpcStream stream;
private final Map, RpcRequestHandler, ?>> handlers;
private int activeRequests = 1;
// jmx
private final InetAddress remoteAddress;
private final ExceptionStats lastRequestHandlingException = ExceptionStats.create();
private final ValueStats requestHandlingTime = ValueStats.create(RpcServer.SMOOTHING_WINDOW).withUnit("milliseconds");
private final EventStats successfulRequests = EventStats.create(RpcServer.SMOOTHING_WINDOW);
private final EventStats failedRequests = EventStats.create(RpcServer.SMOOTHING_WINDOW);
private boolean monitoring = false;
RpcServerConnection(RpcServer rpcServer, InetAddress remoteAddress,
Map, RpcRequestHandler, ?>> handlers, RpcStream stream) {
this.rpcServer = rpcServer;
this.stream = stream;
this.handlers = handlers;
// jmx
this.remoteAddress = remoteAddress;
}
@SuppressWarnings("unchecked")
private Promise
© 2015 - 2025 Weber Informatics LLC | Privacy Policy