001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package org.anarres.qemu.exec; 006 007import java.util.List; 008import javax.annotation.Nonnull; 009 010/** 011 * 012 * @author shevek 013 */ 014public class QEmuCpusOption extends AbstractQEmuOption { 015 016 private String model; 017 private int cpus = 1; 018 private Integer cores = -1; 019 private Integer threads = -1; 020 private Integer sockets = -1; 021 private Integer maxcpus = -1; 022 023 public QEmuCpusOption(int cpus) { 024 this.cpus = cpus; 025 } 026 027 @Nonnull 028 public QEmuCpusOption withModel(@Nonnull String model) { 029 this.model = model; 030 return this; 031 } 032 033 @Nonnull 034 public QEmuCpusOption withCores(@Nonnull int cores) { 035 this.cores = cores; 036 return this; 037 } 038 039 @Nonnull 040 public QEmuCpusOption withThreads(@Nonnull int threads) { 041 this.threads = threads; 042 return this; 043 } 044 045 @Nonnull 046 public QEmuCpusOption withSockets(@Nonnull int sockets) { 047 this.sockets = sockets; 048 return this; 049 } 050 051 @Nonnull 052 public QEmuCpusOption withMaxCpus(@Nonnull int maxcpus) { 053 this.maxcpus = maxcpus; 054 return this; 055 } 056 057 @Override 058 public void appendTo(List<? super String> line) { 059 if (model != null) 060 add(line, "-cpu", model); 061 StringBuilder smp = new StringBuilder(); 062 appendTo(smp, "cpus", cpus); 063 if (cores > 0) 064 appendTo(smp, "cores", cores); 065 if (threads > 0) 066 appendTo(smp, "threads", threads); 067 if (sockets > 0) 068 appendTo(smp, "sockets", sockets); 069 if (maxcpus > 0) 070 appendTo(smp, "maxcpus", maxcpus); 071 add(line, "-smp", smp.toString()); 072 } 073}