2 // ========================================================================
3 // Copyright (c) 1995-2016 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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util.component;
21 import java.io.FileWriter;
22 import java.io.Writer;
24 import org.eclipse.jetty.util.log.Log;
25 import org.eclipse.jetty.util.log.Logger;
28 /* ------------------------------------------------------------ */
29 /** A LifeCycle Listener that writes state changes to a file.
30 * <p>This can be used with the jetty.sh script to wait for successful startup.
32 public class FileNoticeLifeCycleListener implements LifeCycle.Listener
34 private static final Logger LOG = Log.getLogger(FileNoticeLifeCycleListener.class);
36 private final String _filename;
38 public FileNoticeLifeCycleListener(String filename)
43 private void writeState(String action, LifeCycle lifecycle)
45 try (Writer out = new FileWriter(_filename,true))
47 out.append(action).append(" ").append(lifecycle.toString()).append("\n");
55 public void lifeCycleStarting(LifeCycle event)
57 writeState("STARTING",event);
60 public void lifeCycleStarted(LifeCycle event)
62 writeState("STARTED",event);
65 public void lifeCycleFailure(LifeCycle event, Throwable cause)
67 writeState("FAILED",event);
70 public void lifeCycleStopping(LifeCycle event)
72 writeState("STOPPING",event);
75 public void lifeCycleStopped(LifeCycle event)
77 writeState("STOPPED",event);