blob: 0f1ec44ab9866fc886423fba07a27cd534577cf8 [file] [log] [blame]
Jake Slack03928ae2014-05-13 18:41:56 -07001//
2// ========================================================================
3// Copyright (c) 1995-2014 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
19package org.eclipse.jetty.util.component;
20
21import java.io.FileWriter;
22
23import org.eclipse.jetty.util.log.Log;
24import org.eclipse.jetty.util.log.Logger;
25
26
27/* ------------------------------------------------------------ */
28/** A LifeCycle Listener that writes state changes to a file.
29 * <p>This can be used with the jetty.sh script to wait for successful startup.
30 */
31public class FileNoticeLifeCycleListener implements LifeCycle.Listener
32{
33 Logger LOG = Log.getLogger(FileNoticeLifeCycleListener.class);
34
35 private final String _filename;
36
37 public FileNoticeLifeCycleListener(String filename)
38 {
39 _filename=filename;
40 }
41
42 private void writeState(String action, LifeCycle lifecycle)
43 {
44 try
45 {
46 FileWriter out = new FileWriter(_filename,true);
47 out.append(action).append(" ").append(lifecycle.toString()).append("\n");
48 out.close();
49 }
50 catch(Exception e)
51 {
52 LOG.warn(e);
53 }
54 }
55
56 public void lifeCycleStarting(LifeCycle event)
57 {
58 writeState("STARTING",event);
59 }
60
61 public void lifeCycleStarted(LifeCycle event)
62 {
63 writeState("STARTED",event);
64 }
65
66 public void lifeCycleFailure(LifeCycle event, Throwable cause)
67 {
68 writeState("FAILED",event);
69 }
70
71 public void lifeCycleStopping(LifeCycle event)
72 {
73 writeState("STOPPING",event);
74 }
75
76 public void lifeCycleStopped(LifeCycle event)
77 {
78 writeState("STOPPED",event);
79 }
80}