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.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.flink.runtime.io.network.netty;
import org.apache.flink.runtime.io.network.TaskEventDispatcher;
import org.apache.flink.runtime.io.network.partition.ResultPartitionProvider;
import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler;
import org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler;
import java.util.concurrent.TimeUnit;
import static org.apache.flink.runtime.io.network.netty.NettyMessage.NettyMessageEncoder.createFrameLengthDecoder;
/**
* Defines the server and client channel handlers, i.e. the protocol, used by netty.
*/
public class NettyProtocol {
private final NettyMessage.NettyMessageEncoder
messageEncoder = new NettyMessage.NettyMessageEncoder();
private final NettyMessage.NettyMessageDecoder messageDecoder = new NettyMessage.NettyMessageDecoder();
private final ResultPartitionProvider partitionProvider;
private final TaskEventDispatcher taskEventDispatcher;
private final boolean creditBasedEnabled;
private long idleTimeout = NettyConfig.CHANNEL_IDLE_TIMEOUT.defaultValue();
private long heartbeatTimeout = NettyConfig.CHANNEL_HEARTBEAT_TIMEOUT.defaultValue();
private boolean heartbeatEnabled = NettyConfig.CHANNEL_HEARTBEAT_ENABLED.defaultValue();
public NettyProtocol(ResultPartitionProvider partitionProvider, TaskEventDispatcher taskEventDispatcher, boolean creditBasedEnabled) {
this.partitionProvider = partitionProvider;
this.taskEventDispatcher = taskEventDispatcher;
this.creditBasedEnabled = creditBasedEnabled;
}
public NettyProtocol(ResultPartitionProvider partitionProvider,
TaskEventDispatcher taskEventDispatcher,
boolean creditBasedEnabled,
boolean heartbeatEnabled,
long idleTimeout,
long heartbeatTimeout) {
this.partitionProvider = partitionProvider;
this.taskEventDispatcher = taskEventDispatcher;
this.creditBasedEnabled = creditBasedEnabled;
this.heartbeatEnabled = heartbeatEnabled;
this.idleTimeout = idleTimeout;
this.heartbeatTimeout = heartbeatTimeout;
}
/**
* Returns the server channel handlers.
*
*
*
* @return channel handlers
*/
public ChannelHandler[] getServerChannelHandlers() {
PartitionRequestQueue queueOfPartitionQueues = new PartitionRequestQueue();
PartitionRequestServerHandler serverHandler = new PartitionRequestServerHandler(
partitionProvider, taskEventDispatcher, queueOfPartitionQueues, creditBasedEnabled);
return new ChannelHandler[] {
messageEncoder,
// TODO unify all the buffer allocation including the header buffer and the sender-side message header into NetworkBufferAllocator.
new ZeroCopyNettyMessageDecoder(null),
serverHandler,
queueOfPartitionQueues
};
}
/**
* Returns the client channel handlers.
*
*