kernel.core: making some classes final
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / analysis / vm / model / VirtualMachine.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 /**
16 * This class represents a machine, host or guest, in a virtual machine model. A
17 * machine is identified by a trace's host ID.
18 *
19 * @author Geneviève Bastien
20 */
21 public final class VirtualMachine {
22
23 private static enum MachineType {
24 HOST,
25 GUEST
26 }
27
28 private final long fVmUid;
29 private final String fHostId;
30 private final MachineType fType;
31
32 /**
33 * Create a new host machine. A host is a physical machine that may contain
34 * virtual guest machines.
35 *
36 * @param hostId
37 * The host ID of the trace(s) this machine represents
38 * @return A {@link VirtualMachine} of type host
39 */
40 public static VirtualMachine newHostMachine(String hostId) {
41 return new VirtualMachine(MachineType.HOST, hostId, -1);
42 }
43
44 /**
45 * Create a new guest machine. A guest is a virtual machine with virtual
46 * CPUs running on a host.
47 *
48 * @param uid
49 * Some unique identifier of this guest machine that can be used
50 * in both the guest and the host to match both machines.
51 * @param hostId
52 * The host ID of the trace(s) this machine represents
53 * @return A {@link VirtualMachine} of type guest.
54 */
55 public static VirtualMachine newGuestMachine(long uid, String hostId) {
56 return new VirtualMachine(MachineType.GUEST, hostId, uid);
57 }
58
59 private VirtualMachine(MachineType type, String hostId, long uid) {
60 fType = type;
61 fVmUid = uid;
62 fHostId = hostId;
63 }
64
65 /**
66 * Return whether this machine is a guest or a host
67 *
68 * @return {@code true} if the machine is a guest, or {@code false} if it is
69 * a host
70 */
71 public boolean isGuest() {
72 return fType == MachineType.GUEST;
73 }
74
75 /**
76 * Get the unique identifier that is used between the host and the guest to
77 * identify this machine.
78 *
79 * @return The Virtual Machine unique ID.
80 */
81 public long getVmUid() {
82 return fVmUid;
83 }
84
85 /**
86 * Get the host ID of this machine
87 *
88 * @return The host ID of this machine
89 */
90 public String getHostId() {
91 return fHostId;
92 }
93
94 @Override
95 public String toString() {
96 return "VirtualMachine: " + fHostId; //$NON-NLS-1$
97 }
98
99 }
This page took 0.033234 seconds and 5 git commands to generate.