releng: Transition to jdt.annotation 2.0
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / analysis / vm / model / VirtualCPU.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.vm.model;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.eclipse.tracecompass.common.core.NonNullUtils;
17
18 import com.google.common.collect.HashBasedTable;
19 import com.google.common.collect.Table;
20
21 /**
22 * This class represents a virtual CPU, which is a CPU running on a guest. It
23 * associates the guest CPU ID to a virtual machine of the model.
24 *
25 * @author Geneviève Bastien
26 */
27 public class VirtualCPU {
28
29 private static final Table<VirtualMachine, Long, @Nullable VirtualCPU> VIRTUAL_CPU_TABLE = NonNullUtils.checkNotNull(HashBasedTable.<VirtualMachine, Long, VirtualCPU> create());
30
31 private final VirtualMachine fVm;
32 private final Long fCpuId;
33
34 /**
35 * Return the virtual CPU for to the virtual machine and requested CPU ID
36 *
37 * @param vm
38 * The virtual machine
39 * @param cpu
40 * the CPU number
41 * @return the virtual CPU
42 */
43 public static synchronized VirtualCPU getVirtualCPU(VirtualMachine vm, Long cpu) {
44 VirtualCPU ht = VIRTUAL_CPU_TABLE.get(vm, cpu);
45 if (ht == null) {
46 ht = new VirtualCPU(vm, cpu);
47 VIRTUAL_CPU_TABLE.put(vm, cpu, ht);
48 }
49 return ht;
50 }
51
52 private VirtualCPU(VirtualMachine vm, Long cpu) {
53 fVm = vm;
54 fCpuId = cpu;
55 }
56
57 /**
58 * Get the CPU ID of this virtual CPU
59 *
60 * @return The zero-based CPU ID
61 */
62 public Long getCpuId() {
63 return fCpuId;
64 }
65
66 /**
67 * Get the virtual machine object this virtual CPU belongs to
68 *
69 * @return The guest Virtual Machine
70 */
71 public VirtualMachine getVm() {
72 return fVm;
73 }
74
75 @Override
76 public String toString() {
77 return "VirtualCPU: [" + fVm + ',' + fCpuId + ']'; //$NON-NLS-1$
78 }
79
80 }
This page took 0.074608 seconds and 5 git commands to generate.