| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009 Ericsson |
| 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 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | package org.eclipse.linuxtools.lttng.state.model; |
| 13 | |
| 14 | /** |
| 15 | * <b>LttvSoftIRQState</b> |
| 16 | * |
| 17 | * @author alvaro |
| 18 | * |
| 19 | */ |
| 20 | public class LttngSoftIRQState implements Cloneable { |
| 21 | |
| 22 | // ======================================================================== |
| 23 | // Data |
| 24 | // ======================================================================= |
| 25 | private Long pending = null; |
| 26 | private Long running = null; |
| 27 | |
| 28 | // ======================================================================== |
| 29 | // Constructor |
| 30 | // ======================================================================= |
| 31 | public LttngSoftIRQState() { |
| 32 | pending = 0L; |
| 33 | running = 0L; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public LttngSoftIRQState clone() { |
| 38 | LttngSoftIRQState newState = null; |
| 39 | |
| 40 | try { |
| 41 | newState = (LttngSoftIRQState)super.clone(); |
| 42 | |
| 43 | // *** IMPORTANT *** |
| 44 | // Basic type in java are immutable! |
| 45 | // Thus, using assignment ("=") on basic type is CORRECT, |
| 46 | // but we should ALWAYS use "new" or "clone()" on "non basic" type |
| 47 | newState.pending = this.pending; |
| 48 | newState.running = this.running; |
| 49 | } |
| 50 | catch ( CloneNotSupportedException e ) { |
| 51 | System.out.println("Cloning failed with : " + e.getMessage() ); //$NON-NLS-1$ |
| 52 | } |
| 53 | |
| 54 | return newState; |
| 55 | } |
| 56 | |
| 57 | // ======================================================================== |
| 58 | // Methods |
| 59 | // ======================================================================= |
| 60 | /** |
| 61 | * @param pending |
| 62 | * the pending to set |
| 63 | */ |
| 64 | public void setPending(Long pending) { |
| 65 | this.pending = pending; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return the pending |
| 70 | */ |
| 71 | public Long getPending() { |
| 72 | return pending; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @param running |
| 77 | * the running to set |
| 78 | */ |
| 79 | public void setRunning(Long running) { |
| 80 | this.running = running; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return the running |
| 85 | */ |
| 86 | public Long getRunning() { |
| 87 | return running; |
| 88 | } |
| 89 | |
| 90 | public void reset() { |
| 91 | pending = 0L; |
| 92 | running = 0L; |
| 93 | } |
| 94 | |
| 95 | public void incrementRunning() { |
| 96 | running ++; |
| 97 | } |
| 98 | |
| 99 | public void incrementPending() { |
| 100 | pending ++; |
| 101 | } |
| 102 | |
| 103 | public void decrementRunning() { |
| 104 | if (running > 0L) { |
| 105 | running--; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | public void decrementPending() { |
| 110 | if (pending > 0L) { |
| 111 | pending--; |
| 112 | } |
| 113 | } |
| 114 | } |