Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
High-performance and fault-tolerant Remote Procedure Call module for building distributed applications.
Provides a high-performance asynchronous binary RPC streaming protocol.
/*
* Copyright (C) 2020 ActiveJ 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.activej.rpc.server;
import io.activej.common.exception.MalformedDataException;
import io.activej.datastream.supplier.StreamDataAcceptor;
import io.activej.jmx.api.JmxRefreshable;
import io.activej.jmx.api.attribute.JmxAttribute;
import io.activej.jmx.stats.EventStats;
import io.activej.jmx.stats.ExceptionStats;
import io.activej.jmx.stats.ValueStats;
import io.activej.promise.Promise;
import io.activej.reactor.AbstractReactive;
import io.activej.reactor.Reactor;
import io.activej.rpc.protocol.RpcControlMessage;
import io.activej.rpc.protocol.RpcMessage;
import io.activej.rpc.protocol.RpcRemoteException;
import io.activej.rpc.protocol.RpcStream;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.util.Map;
public final class RpcServerConnection extends AbstractReactive 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.builder(RpcServer.SMOOTHING_WINDOW)
.withUnit("milliseconds")
.build();
private final EventStats successfulRequests = EventStats.create(RpcServer.SMOOTHING_WINDOW);
private final EventStats failedRequests = EventStats.create(RpcServer.SMOOTHING_WINDOW);
private boolean monitoring = false;
RpcServerConnection(
Reactor reactor, RpcServer rpcServer, InetAddress remoteAddress,
Map, RpcRequestHandler, ?>> handlers, RpcStream stream
) {
super(reactor);
this.rpcServer = rpcServer;
this.stream = stream;
this.handlers = handlers;
// jmx
this.remoteAddress = remoteAddress;
}
@SuppressWarnings("unchecked")
private Promise