View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.rt.agent;
22  
23  import net.sf.jour.util.queue.*;
24  
25  
26  /***
27   * @author Misha TODO To change the template for this generated type comment go
28   *         to Window - Preferences - Java - Code Style - Code Templates
29   */
30  public class EventQueueLogger implements EventLogger {
31      /***   DOCUMENT ME!   */
32      private static EventQueueLogger instance;
33  
34      /***   DOCUMENT ME!   */
35      private Queue eventQueue;
36  
37      /***
38       * Creates a new EventQueueLogger object.
39       */
40      private EventQueueLogger() {
41          eventQueue = new Queue();
42      }
43  
44      /***
45       * DOCUMENT ME!
46       *
47       * @return DOCUMENT ME!
48       */
49      public static EventLogger getInstance() {
50          if (instance == null) {
51              instance = new EventQueueLogger();
52          }
53  
54          return instance;
55      }
56  
57      /***
58       * DOCUMENT ME!
59       *
60       * @param event DOCUMENT ME!
61       */
62      public synchronized void logEvent(Event event) {
63          eventQueue.enqueue(event);
64      }
65      
66  	/***
67  	 * Inserts a Collection of new element at the rear of the queue.
68  	 *
69  	 * @param elements Collection to be inserted.
70  	 */
71  	public synchronized boolean enqueueAll(Queue events) {
72  		return eventQueue.enqueueAll(events);
73  	}
74  
75      /***
76       * DOCUMENT ME!
77       *
78       * @return DOCUMENT ME!
79       */
80      public synchronized Event getEvent() {
81          return (Event) eventQueue.dequeue();
82      }
83  
84      /***
85       * DOCUMENT ME!
86       *
87       * @return DOCUMENT ME!
88       */
89      public Event[] getEventsFromQueue() {
90          Event[] events = null;
91          synchronized (this) {
92              events = (Event[])eventQueue.dequeueAll(new Event[0]);
93          }
94  
95          return events;
96      }
97      
98      public void close() {
99          
100     }
101 }