Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/scoja/server/core/InternalEvent.java


1   
2   package org.scoja.server.core;
3   
4   import java.io.PrintWriter;
5   import java.util.Calendar;
6   import java.net.InetAddress;
7   
8   import org.scoja.common.PriorityUtils;
9   import org.scoja.common.DateUtils;
10  
11  /**
12   * Los eventos internos se dividen en 3 grupos.
13   * <ol>
14   * <li><i>Errors</i>, with levels less or equal to {@link PriorityUtils#ERR}.
15   * <li><i>Sensible events</i>, with levels 
16   *     {@link PriorityUtils#WARNING} and {@link PriorityUtils#NOTICE}.
17   * <li><i>Trace events</i>, with levels greater or equal to
18   *     {@link PriorityUtils#INFO}.
19   * </ol>
20   * While processing <i>trace</i> events, no other internal events are
21   * produced.
22   *
23   * <p>
24   * A table to know when to use a level:
25   * <dl>
26   * <dt>{@link PriorityUtils#EMERG}
27   * <dd>
28   * <dt>{@link PriorityUtils#ALERT}
29   * <dd>
30   * <dt>{@link PriorityUtils#CRIT}
31   * <dd>
32   * <dt>{@link PriorityUtils#ERR}
33   * <dd>
34   * <dt>{@link PriorityUtils#WARNING}
35   * <dd>
36   * <dt>{@link PriorityUtils#NOTICE}
37   * <dd>
38   * <dt>{@link PriorityUtils#INFO}
39   * <dd>
40   * <dt>{@link PriorityUtils#DEBUG}
41   * <dd>
42   * </dl>
43   */
44  public class InternalEvent extends EventSkeleton {
45      
46      protected final InetAddress address;
47      protected final int energy;
48      protected final int priority;
49      protected String data;
50      protected final String program;
51      protected final String message;
52  
53      /*    
54      public InternalEvent(final InetAddress address,
55                           final int facility, final int level,
56                           final String program, final String message) {
57          this(address,
58               DEFAULT_ENERGY, facility, level,
59               program, message);
60      }
61      */
62      
63      public InternalEvent(final InetAddress address,
64                           final int energy, final int facility, final int level,
65                           final String program, final String message) {
66          this(address,
67               energy, PriorityUtils.buildPriority(facility,level),
68               program, message);
69      }
70      
71      /*
72      public InternalEvent(final InetAddress address,
73                           final int priority,
74                           final String program, final String message) {
75          this(address,
76               DEFAULT_ENERGY, priority,
77               program, message);
78      }
79      */
80      
81      public InternalEvent(final InetAddress address,
82                           final int energy, final int priority,
83                           final String program, final String message) {
84          super();
85          this.address = address;
86          this.energy = energy;
87          this.priority = priority;
88          this.data = null;
89          this.program = program;
90          this.message = message;
91      }
92      
93      public int getEnergy() {
94          return energy;
95      }
96      
97      public int getPriority() {
98          return priority;
99      }
100 
101     public boolean isTraceable() {
102         final int level = getLevel();
103         return level != PriorityUtils.DEBUG;
104     }
105     
106     public boolean shouldLogErrors() {
107         final int level = getLevel();
108         return level != PriorityUtils.DEBUG && level != PriorityUtils.ERR;
109     }
110     
111     public String getHost() {
112         return getAddress().getHostAddress();
113     }
114     
115     public InetAddress getAddress() {
116         return address;
117     }
118     
119     public String getData() {
120         if (data == null) {
121             data = program + ": " + message;
122         }
123         return data;
124     }
125     
126     public String getProgram() {
127         return program;
128     }
129     
130     public String getMessage() {
131         return message;
132     }
133     
134     public void writeTo(final PrintWriter out) {
135         synchronized (out) {
136             DateUtils.format(out, getSendCalendar());
137             out.print(' ');
138             out.print(getHost());
139             out.print(' ');
140             out.print(getProgram());
141             out.print(": ");
142             out.print(getMessage());
143             out.print('\n');
144         }
145     }
146 }