class TaskManagerServices {

	@SuppressWarnings("deprecation")
	public static long calculateNetworkBufferMemory(long totalJavaMemorySize, Configuration config) {
		Preconditions.checkArgument(totalJavaMemorySize > 0);

		int segmentSize =
			checkedDownCast(MemorySize.parse(config.getString(TaskManagerOptions.MEMORY_SEGMENT_SIZE)).getBytes());

		final long networkBufBytes;
		if (TaskManagerServicesConfiguration.hasNewNetworkBufConf(config)) {
			// new configuration based on fractions of available memory with selectable min and max
			float networkBufFraction = config.getFloat(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION);
			long networkBufMin = MemorySize.parse(config.getString(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MIN)).getBytes();
			long networkBufMax = MemorySize.parse(config.getString(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX)).getBytes();

			TaskManagerServicesConfiguration
				.checkNetworkBufferConfig(segmentSize, networkBufFraction, networkBufMin, networkBufMax);

			networkBufBytes = Math.min(networkBufMax, Math.max(networkBufMin,
				(long) (networkBufFraction * totalJavaMemorySize)));

			TaskManagerServicesConfiguration
				.checkConfigParameter(networkBufBytes < totalJavaMemorySize,
					"(" + networkBufFraction + ", " + networkBufMin + ", " + networkBufMax + ")",
					"(" + TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION.key() + ", " +
						TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MIN.key() + ", " +
						TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX.key() + ")",
					"Network buffer memory size too large: " + networkBufBytes + " >= " +
						totalJavaMemorySize + " (total JVM memory size)");
			TaskManagerServicesConfiguration
				.checkConfigParameter(networkBufBytes >= segmentSize,
					"(" + networkBufFraction + ", " + networkBufMin + ", " + networkBufMax + ")",
					"(" + TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION.key() + ", " +
						TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MIN.key() + ", " +
						TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX.key() + ")",
					"Network buffer memory size too small: " + networkBufBytes + " < " +
						segmentSize + " (" + TaskManagerOptions.MEMORY_SEGMENT_SIZE.key() + ")");
		} else {
			// use old (deprecated) network buffers parameter
			int numNetworkBuffers = config.getInteger(TaskManagerOptions.NETWORK_NUM_BUFFERS);
			networkBufBytes = (long) numNetworkBuffers * (long) segmentSize;

			TaskManagerServicesConfiguration.checkNetworkConfigOld(numNetworkBuffers);

			TaskManagerServicesConfiguration
				.checkConfigParameter(networkBufBytes < totalJavaMemorySize,
					networkBufBytes, TaskManagerOptions.NETWORK_NUM_BUFFERS.key(),
					"Network buffer memory size too large: " + networkBufBytes + " >= " +
						totalJavaMemorySize + " (total JVM memory size)");
			TaskManagerServicesConfiguration
				.checkConfigParameter(networkBufBytes >= segmentSize,
					networkBufBytes, TaskManagerOptions.NETWORK_NUM_BUFFERS.key(),
					"Network buffer memory size too small: " + networkBufBytes + " < " +
						segmentSize + " (" + TaskManagerOptions.MEMORY_SEGMENT_SIZE.key() + ")");
		}

		return networkBufBytes;
	}

	  TaskManagerServices(
		TaskManagerLocation taskManagerLocation,
		MemoryManager memoryManager,
		IOManager ioManager,
		NetworkEnvironment networkEnvironment,
		BroadcastVariableManager broadcastVariableManager,
		TaskSlotTable taskSlotTable,
		JobManagerTable jobManagerTable,
		JobLeaderService jobLeaderService,
		TaskExecutorLocalStateStoresManager taskManagerStateStore);

}