summaryrefslogblamecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/Constants.java
blob: 774d1c88faa928bfcd428d98f15d4a72fc70ee2d (plain) (tree)
1
2
3
4
5
6
7
8
9
                                  
 
                                               



                                                                      
                                              
                                                                    




                                                                                                   

                                                          




                                                                                                
                                                

         
package org.openslx.bwlp.sat.util;

import org.openslx.filetransfer.util.FileChunk;

public class Constants {
	public static final String INCOMPLETE_UPLOAD_SUFFIX = ".part";
	public static final int MAX_UPLOADS;
	public static final int MAX_DOWNLOADS;
	public static final int TRANSFER_TIMEOUT = 15 * 1000; // 15s

	static {
		long maxMem = Runtime.getRuntime().maxMemory();
		if (maxMem == Long.MAX_VALUE) {
			// Apparently the JVM was started without a memory limit (no -Xmx cmdline),
			// so we assume a default of 512MB
			maxMem = 512l * 1024l * 1024l;
		}
		maxMem /= 1024l * 1024l;
		// Now maxMem is the amount of memory in MiB

		MAX_UPLOADS = (int) Math.max(1, (maxMem - 64) / (FileChunk.CHUNK_SIZE_MIB + 1));
		MAX_DOWNLOADS = MAX_UPLOADS * 2;
	}
}