1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.monitor.jmx;
20
21
22 /* ------------------------------------------------------------ */
23 /**
24 * ConsoleNotifier
25 *
26 * Provides a way to output notification messages to the server console
27 */
28 public class ConsoleNotifier implements EventNotifier
29 {
30 String _messageFormat;
31
32
33 /* ------------------------------------------------------------ */
34 /**
35 * Constructs a new notifier with specified format string
36 *
37 * @param format the {@link java.util.Formatter format string}
38 * @throws IllegalArgumentException
39 */
40 public ConsoleNotifier(String format)
41 throws IllegalArgumentException
42 {
43 if (format == null)
44 throw new IllegalArgumentException("Message format cannot be null");
45
46 _messageFormat = format;
47 }
48
49 /* ------------------------------------------------------------ */
50 /**
51 * @see org.eclipse.jetty.monitor.jmx.EventNotifier#notify(org.eclipse.jetty.monitor.jmx.EventTrigger, org.eclipse.jetty.monitor.jmx.EventState, long)
52 */
53 public void notify(EventTrigger trigger, EventState<?> state, long timestamp)
54 {
55 String output = String.format("%1$tF %1$tT.%1$tL:NOTIFY::", timestamp);
56
57 output += String.format(_messageFormat, state);
58
59 System.out.println(output);
60 }
61 }