~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/records/BaseRecord.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import javax.persistence.DiscriminatorColumn;
10
10
import javax.persistence.DiscriminatorType;
11
11
import javax.persistence.DiscriminatorValue;
12
 
import javax.persistence.Entity;
 
12
import org.hibernate.annotations.Entity;
13
13
import javax.persistence.EnumType;
14
14
import javax.persistence.Enumerated;
15
15
import javax.persistence.GeneratedValue;
25
25
import org.hibernate.annotations.CacheConcurrencyStrategy;
26
26
import org.hibernate.annotations.GenericGenerator;
27
27
import com.eucalyptus.bootstrap.Bootstrap;
 
28
import com.eucalyptus.entities.AbstractPersistent;
28
29
import com.google.common.collect.Lists;
29
30
 
30
31
@Entity
 
32
@javax.persistence.Entity
31
33
@PersistenceContext( name = "eucalyptus_records" )
32
34
@Table( name = "records" )
33
 
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
 
35
@Cache( usage = CacheConcurrencyStrategy.TRANSACTIONAL )
34
36
@Inheritance( strategy = InheritanceType.TABLE_PER_CLASS )
35
37
@DiscriminatorColumn( name = "record_class", discriminatorType = DiscriminatorType.STRING )
36
38
@DiscriminatorValue( value = "base" )
37
 
public class BaseRecord implements Serializable, Record {
 
39
public class BaseRecord extends AbstractPersistent implements Serializable, Record {
38
40
  @Transient
39
 
  private static Logger       LOG    = Logger.getLogger( BaseRecord.class );
40
 
  @Id
41
 
  @GeneratedValue( generator = "system-uuid" )
42
 
  @GenericGenerator( name = "system-uuid", strategy = "uuid" )
43
 
  @Column( name = "record_id" )
44
 
  String                      id;
 
41
  private static Logger                     LOG    = Logger.getLogger( BaseRecord.class );
45
42
  @Column( name = "record_timestamp" )
46
 
  private Date                timestamp;
 
43
  private Date                              timestamp;
47
44
  @Column( name = "record_type" )
48
45
  @Enumerated( EnumType.STRING )
49
 
  private EventType           type;
 
46
  private EventType                         type;
50
47
  @Column( name = "record_class" )
51
48
  @Enumerated( EnumType.STRING )
52
 
  private EventClass          eventClass;
 
49
  private EventClass                        eventClass;
53
50
  @Column( name = "record_creator" )
54
 
  private String              creator;
 
51
  private String                            creator;
55
52
  @Column( name = "record_code_location" )
56
 
  private String              codeLocation;
 
53
  private String                            codeLocation;
57
54
  @Column( name = "record_user_id" )
58
 
  private String              userId;
 
55
  private String                            userId;
59
56
  @Column( name = "record_correlation_id" )
60
 
  private String              correlationId;
 
57
  private String                            correlationId;
61
58
  @Lob
62
59
  @Column( name = "record_extra" )
63
 
  private String              extra;
 
60
  private String                            extra;
64
61
  @Column( name = "record_level" )
65
62
  @Enumerated( EnumType.STRING )
66
 
  private RecordLevel         level;
67
 
  @Transient
68
 
  private ArrayList           others = Lists.newArrayList( );
69
 
  @Transient
70
 
  private static final String ISNULL = "NULL";
71
 
  @Transient
72
 
  private static final String NEXT   = "\n";
73
 
  @Transient
74
 
  private transient String    lead;
75
 
  @Transient
76
 
  private Class               realCreator;
77
 
  @Transient
78
 
  private static BlockingQueue<EventRecord> trace = new LinkedBlockingDeque<EventRecord>( );
79
 
  @Transient
80
 
  private static BlockingQueue<EventRecord> debug = new LinkedBlockingDeque<EventRecord>( );
81
 
  @Transient
82
 
  private static BlockingQueue<EventRecord> info = new LinkedBlockingDeque<EventRecord>( );
83
 
  @Transient
84
 
  private static BlockingQueue<EventRecord> warn = new LinkedBlockingDeque<EventRecord>( );
85
 
  @Transient
86
 
  private static BlockingQueue<EventRecord> error = new LinkedBlockingDeque<EventRecord>( );
87
 
  @Transient
88
 
  private static BlockingQueue<EventRecord> fatal = new LinkedBlockingDeque<EventRecord>( );
 
63
  private RecordLevel                       level;
 
64
  @Transient
 
65
  private ArrayList                         others = Lists.newArrayList( );
 
66
  @Transient
 
67
  private static final String               ISNULL = "NULL";
 
68
  @Transient
 
69
  protected static final String             NEXT   = "\n";
 
70
  @Transient
 
71
  private transient String                  lead;
 
72
  @Transient
 
73
  private Class                             realCreator;
 
74
  @Transient
 
75
  private static BlockingQueue<EventRecord> trace  = new LinkedBlockingDeque<EventRecord>( );
 
76
  @Transient
 
77
  private static BlockingQueue<EventRecord> debug  = new LinkedBlockingDeque<EventRecord>( );
 
78
  @Transient
 
79
  private static BlockingQueue<EventRecord> info   = new LinkedBlockingDeque<EventRecord>( );
 
80
  @Transient
 
81
  private static BlockingQueue<EventRecord> warn   = new LinkedBlockingDeque<EventRecord>( );
 
82
  @Transient
 
83
  private static BlockingQueue<EventRecord> error  = new LinkedBlockingDeque<EventRecord>( );
 
84
  @Transient
 
85
  private static BlockingQueue<EventRecord> fatal  = new LinkedBlockingDeque<EventRecord>( );
 
86
  
89
87
  public BaseRecord( EventType type, EventClass clazz, Class creator, StackTraceElement codeLocation, String userId, String correlationId, String other ) {
90
88
    this.type = type;
91
89
    this.eventClass = clazz;
92
90
    this.realCreator = creator;
93
 
    this.creator = creator.getSimpleName( );
94
 
    this.codeLocation = codeLocation.toString( );
 
91
    this.creator = creator != null
 
92
      ? creator.getSimpleName( )
 
93
      : "";
 
94
    this.codeLocation = codeLocation != null
 
95
      ? codeLocation.toString( )
 
96
      : "";
95
97
    this.userId = userId;
96
98
    this.correlationId = correlationId;
97
 
    this.timestamp = new Date();
 
99
    this.timestamp = new Date( );
98
100
    this.extra = other;
99
101
    this.others.add( other );
100
102
  }
101
103
  
102
104
  public BaseRecord( ) {}
103
105
  
104
 
  /**
105
 
   * @see com.eucalyptus.records.Record#info()
106
 
   * @return
107
 
   */
108
106
  public Record info( ) {
109
107
    this.level = RecordLevel.INFO;
110
108
    Logger.getLogger( this.realCreator ).info( this );
111
109
    return this;
112
110
  }
113
111
  
114
 
  /**
115
 
   * @see com.eucalyptus.records.Record#error()
116
 
   * @return
117
 
   */
118
112
  public Record error( ) {
119
113
    this.level = RecordLevel.ERROR;
120
114
    Logger.getLogger( this.realCreator ).error( this );
121
115
    return this;
122
116
  }
123
117
  
124
 
  /**
125
 
   * @see com.eucalyptus.records.Record#trace()
126
 
   * @return
127
 
   */
128
118
  public Record trace( ) {
129
119
    this.level = RecordLevel.TRACE;
130
120
    Logger.getLogger( this.realCreator ).trace( this );
131
121
    return this;
132
122
  }
133
123
  
134
 
  /**
135
 
   * @see com.eucalyptus.records.Record#debug()
136
 
   * @return
137
 
   */
138
124
  public Record debug( ) {
139
125
    this.level = RecordLevel.DEBUG;
140
126
    Logger.getLogger( this.realCreator ).debug( this );
141
127
    return this;
142
128
  }
143
129
  
144
 
  /**
145
 
   * @see com.eucalyptus.records.Record#warn()
146
 
   * @return
147
 
   */
 
130
  @Override
 
131
  public Record extreme( ) {
 
132
    this.level = RecordLevel.TRACE;
 
133
    Logs.extreme( ).trace( this );
 
134
    return this;
 
135
  }
 
136
  
 
137
  @Override
 
138
  public Record exhaust( ) {
 
139
    this.level = RecordLevel.TRACE;
 
140
    Logs.exhaust( ).trace( this );
 
141
    return this;
 
142
  }
 
143
 
148
144
  public Record warn( ) {
149
145
    this.level = RecordLevel.WARN;
150
146
    Logger.getLogger( this.realCreator ).warn( this );
151
147
    return this;
152
148
  }
153
149
  
154
 
  /**
155
 
   * @see com.eucalyptus.records.Record#next()
156
 
   * @return
157
 
   */
158
150
  public Record next( ) {
159
 
    this.others.add( NEXT );
160
151
    this.extra = "";
161
152
    for ( Object o : this.others ) {
 
153
      if ( o == null ) continue;
162
154
      this.extra += ":" + o.toString( );
163
155
    }
164
 
    return this;
 
156
    Record newThis = new LogFileRecord( this.eventClass, this.type, this.realCreator, null, this.userId, this.correlationId, "" );
 
157
    return newThis;
165
158
  }
166
159
  
167
 
  /**
168
 
   * @see com.eucalyptus.records.Record#append(java.lang.Object)
169
 
   * @param obj
170
 
   * @return
171
 
   */
172
160
  public Record append( Object... obj ) {
173
161
    for ( Object o : obj ) {
174
 
      this.others.add( o == null ? ISNULL : "" + o );
 
162
      this.others.add( o == null
 
163
        ? ISNULL
 
164
        : "" + o );
175
165
    }
176
166
    this.extra = "";
177
167
    for ( Object o : this.others ) {
 
168
      if ( o == null ) continue;
178
169
      this.extra += ":" + o.toString( );
179
170
    }
180
171
    return this;
197
188
  }
198
189
  
199
190
  private String leadIn( ) {
200
 
    return lead == null ? ( lead = String.format( ":%010d:%s:%s:%s:%s:", this.getTimestamp( ).getTime( ), this.getCreator( ),
201
 
                                                  ( ( this.correlationId != null ) ? this.correlationId : "" ), ( ( this.userId != null ) ? this.userId : "" ),
202
 
                                                  this.type ) ) : lead;
 
191
    return lead == null
 
192
      ? ( lead = String.format( ":%010d:%s:%s:%s:%s:", this.getTimestamp( ).getTime( ), this.getCreator( ),
 
193
                                                  ( ( this.correlationId != null )
 
194
                                                    ? this.correlationId
 
195
                                                    : "" ), ( ( this.userId != null )
 
196
                                                    ? this.userId
 
197
                                                    : "" ),
 
198
                                                  this.type ) )
 
199
      : lead;
203
200
  }
204
201
  
205
 
  /**
206
 
   * @see com.eucalyptus.records.Record#toString()
207
 
   * @return
208
 
   */
209
202
  public String toString( ) {
210
203
    String ret = this.leadIn( );
211
204
    for ( Object o : this.others ) {
 
205
      if ( o == null ) continue;
212
206
      ret += ":" + o.toString( );
213
207
    }
214
208
    return ret.replaceAll( "::*", ":" ).replaceAll( NEXT, NEXT + this.leadIn( ) );
215
209
  }
216
210
  
217
 
  public String getId( ) {
218
 
    return this.id;
219
 
  }
220
 
  
221
 
  public void setId( String id ) {
222
 
    this.id = id;
223
 
  }
224
 
  
225
 
  
226
211
  public Date getTimestamp( ) {
227
212
    return this.timestamp;
228
213
  }
229
 
 
 
214
  
230
215
  public void setTimestamp( Date timestamp ) {
231
216
    this.timestamp = timestamp;
232
217
  }
233
 
 
 
218
  
234
219
  public EventType getType( ) {
235
220
    return this.type;
236
221
  }
287
272
    this.correlationId = correlationId;
288
273
  }
289
274
  
290
 
  /**
291
 
   * @see com.eucalyptus.records.Record#hashCode()
292
 
   * @return
293
 
   */
 
275
  public Record withDetails( String userId, String primaryInfo, String key, String value ) {
 
276
    this.userId = userId;
 
277
    this.correlationId = primaryInfo;
 
278
    return this.withDetails( key, value );
 
279
  }
 
280
  
 
281
  public Record withDetails( String key, String value ) {
 
282
    this.others.clear( );
 
283
    this.others.add( key );
 
284
    this.others.add( value );
 
285
    this.info( );
 
286
    return this.next( );
 
287
  }
 
288
  
294
289
  @Override
295
290
  public int hashCode( ) {
296
291
    final int prime = 31;
297
292
    int result = 1;
298
 
    result = prime * result + ( ( this.eventClass == null ) ? 0 : this.eventClass.hashCode( ) );
299
 
    result = prime * result + ( ( this.codeLocation == null ) ? 0 : this.codeLocation.hashCode( ) );
300
 
    result = prime * result + ( ( this.correlationId == null ) ? 0 : this.correlationId.hashCode( ) );
301
 
    result = prime * result + ( ( this.creator == null ) ? 0 : this.creator.hashCode( ) );
302
 
    result = prime * result + ( ( this.timestamp == null ) ? 0 : this.timestamp.hashCode( ) );
303
 
    result = prime * result + ( ( this.type == null ) ? 0 : this.type.hashCode( ) );
304
 
    result = prime * result + ( ( this.userId == null ) ? 0 : this.userId.hashCode( ) );
 
293
    result = prime * result + ( ( this.eventClass == null )
 
294
      ? 0
 
295
      : this.eventClass.hashCode( ) );
 
296
    result = prime * result + ( ( this.codeLocation == null )
 
297
      ? 0
 
298
      : this.codeLocation.hashCode( ) );
 
299
    result = prime * result + ( ( this.correlationId == null )
 
300
      ? 0
 
301
      : this.correlationId.hashCode( ) );
 
302
    result = prime * result + ( ( this.creator == null )
 
303
      ? 0
 
304
      : this.creator.hashCode( ) );
 
305
    result = prime * result + ( ( this.timestamp == null )
 
306
      ? 0
 
307
      : this.timestamp.hashCode( ) );
 
308
    result = prime * result + ( ( this.type == null )
 
309
      ? 0
 
310
      : this.type.hashCode( ) );
 
311
    result = prime * result + ( ( this.userId == null )
 
312
      ? 0
 
313
      : this.userId.hashCode( ) );
305
314
    return result;
306
315
  }
307
316