Subversion Repositories programming

Rev

Rev 413 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
413 ira 1
/*******************************************************************************
2
 * LogEntry.java
3
 *
4
 * Holds the LogEntry class, which is a representation of what happened every
415 ira 5
 * during the critical parts of step() in Scheduler-derived classes.
413 ira 6
 *
7
 * Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to deal
11
 * in the Software without restriction, including without limitation the rights
12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in
17
 * all copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
 * IN THE SOFTWARE.
26
 ******************************************************************************/
27
 
415 ira 28
/**
29
 * A representation of critical events that happen in Scheduler-derived classes.
30
 *
31
 * @class CS431 Fall 2006
32
 * @author Ira W. Snyder (devel@irasnyder.com)
33
 */
34
public class LogEntry
413 ira 35
{
415 ira 36
    /** Message types that are possible */
37
    public static enum MsgType
38
    {
39
        /** Represents a Process starting on the CPU */
40
        START,
413 ira 41
 
415 ira 42
        /** Represents a Process completing this timeslice on the CPU,
43
         * but not being completely finished yet.
44
         */
45
        EXPIRE,
46
 
47
        /** Represents a Process completing its execution completely. */
48
        COMPLETE
49
    };
50
 
51
    /** The time at which this event happened */
413 ira 52
    public final int time;
415 ira 53
 
54
    /** The process that caused this event */
413 ira 55
    public final Process proc;
415 ira 56
 
57
    /** The type of message that this event represents */
413 ira 58
    public final MsgType msg;
59
 
415 ira 60
    /**
61
     * Constructor for the LogEntry class.
62
     *
63
     * @param proc the Process that caused this event
64
     * @param time the time when this event happened
65
     * @param msg the type of message that this represents
66
     */
413 ira 67
    public LogEntry (Process proc, int time, MsgType msg)
68
    {
69
        this.time = time;
70
        this.proc = proc;
71
        this.msg  = msg;
72
    }
73
 
415 ira 74
    /**
75
     * Convert this LogEntry to a String for printing.
76
     *
77
     * @return the String representation of this LogEntry
78
     */
413 ira 79
    public String toString ()
80
    {
81
        String action = new String ("invalid");
82
 
83
        switch (msg)
84
        {
85
            case START:
86
                action = "started";
87
                break;
88
            case EXPIRE:
89
                action = "expired";
90
                break;
91
            case COMPLETE:
92
                action = "finished";
93
                break;
94
        }
95
 
96
        return "@" + time + " " + proc.name + " " + action;
97
    }
98
}
99
 
100
/* vim: set ts=4 sts=4 sw=4 expandtab: */
101