Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7124 - Add default methods on LifeCycle.Listener interface #7143

Merged
merged 3 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public class ServerConnectorListener extends AbstractLifeCycleListener
private String _fileName;
private String _sysPropertyName;

/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener#lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarted(LifeCycle event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
public class ServerListener implements LifeCycle.Listener
{

private String _tokenFile;

public void setTokenFile(String file)
Expand All @@ -43,18 +42,6 @@ public String getTokenFile()
return _tokenFile;
}

/**
* @see org.eclipse.jetty.util.component.LifeCycle.Listener#lifeCycleStarting(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarting(LifeCycle event)
{

}

/**
* @see org.eclipse.jetty.util.component.LifeCycle.Listener#lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarted(LifeCycle event)
{
Expand All @@ -71,31 +58,4 @@ public void lifeCycleStarted(LifeCycle event)
}
}
}

/**
* @see org.eclipse.jetty.util.component.LifeCycle.Listener#lifeCycleFailure(org.eclipse.jetty.util.component.LifeCycle, java.lang.Throwable)
*/
@Override
public void lifeCycleFailure(LifeCycle event, Throwable cause)
{

}

/**
* @see org.eclipse.jetty.util.component.LifeCycle.Listener#lifeCycleStopping(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStopping(LifeCycle event)
{

}

/**
* @see org.eclipse.jetty.util.component.LifeCycle.Listener#lifeCycleStopped(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStopped(LifeCycle event)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public class ServerConnectorListener extends AbstractLifeCycleListener
private Path _filePath;
private String _sysPropertyName;

/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener#lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarted(LifeCycle event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.webapp.Configuration;
import org.osgi.framework.BundleActivator;
Expand All @@ -47,17 +46,12 @@ public void start(BundleContext context) throws Exception
{
//For test purposes, use a random port
Server server = new Server(0);
server.getConnectors()[0].addLifeCycleListener(new AbstractLifeCycleListener()
server.getConnectors()[0].addLifeCycleListener(new LifeCycle.Listener()
{

/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener#lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle)
*/
@Override
public void lifeCycleStarted(LifeCycle event)
{
System.setProperty("bundle.server.port", String.valueOf(((ServerConnector)event).getLocalPort()));
super.lifeCycleStarted(event);
}
});
ContextHandlerCollection contexts = new ContextHandlerCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testShutdownServerWithCorrectTokenAndIP() throws Exception
start(null);

CountDownLatch stopLatch = new CountDownLatch(1);
server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener()
server.addLifeCycleListener(new LifeCycle.Listener()
{
@Override
public void lifeCycleStopped(LifeCycle event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ public void setStopTimeout(long stopTimeout)
this._stopTimeout = stopTimeout;
}

/**
* @deprecated this class is redundant now that {@link LifeCycle.Listener} has default methods.
*/
@Deprecated
public abstract static class AbstractLifeCycleListener implements LifeCycle.Listener
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,25 @@ void stop()
*/
interface Listener extends EventListener
{
void lifeCycleStarting(LifeCycle event);
default void lifeCycleStarting(LifeCycle event)
{
}

void lifeCycleStarted(LifeCycle event);
default void lifeCycleStarted(LifeCycle event)
{
}

void lifeCycleFailure(LifeCycle event, Throwable cause);
default void lifeCycleFailure(LifeCycle event, Throwable cause)
{
}

void lifeCycleStopping(LifeCycle event);
default void lifeCycleStopping(LifeCycle event)
{
}

void lifeCycleStopped(LifeCycle event);
default void lifeCycleStopped(LifeCycle event)
{
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public StopLifeCycle(LifeCycle lifecycle)
addLifeCycleListener(this);
}

@Override
public void lifeCycleStarting(LifeCycle lifecycle)
{
}

@Override
public void lifeCycleStarted(LifeCycle lifecycle)
{
Expand All @@ -53,19 +48,4 @@ public void lifeCycleStarted(LifeCycle lifecycle)
LOG.warn(e);
}
}

@Override
public void lifeCycleFailure(LifeCycle lifecycle, Throwable cause)
{
}

@Override
public void lifeCycleStopping(LifeCycle lifecycle)
{
}

@Override
public void lifeCycleStopped(LifeCycle lifecycle)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void setCause(Exception e)
}
}

private class TestListener extends AbstractLifeCycle.AbstractLifeCycleListener
private class TestListener implements LifeCycle.Listener
{
@SuppressWarnings("unused")
private boolean failure = false;
Expand All @@ -171,6 +171,7 @@ private class TestListener extends AbstractLifeCycle.AbstractLifeCycleListener

private Throwable cause = null;

@Override
public void lifeCycleFailure(LifeCycle event, Throwable cause)
{
failure = true;
Expand All @@ -182,12 +183,14 @@ public Throwable getCause()
return cause;
}

@Override
public void lifeCycleStarted(LifeCycle event)
{
started = true;
startedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
}

@Override
public void lifeCycleStarting(LifeCycle event)
{
starting = true;
Expand All @@ -205,12 +208,14 @@ public void lifeCycleStarting(LifeCycle event)
}
}

@Override
public void lifeCycleStopped(LifeCycle event)
{
stopped = true;
stoppedTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
}

@Override
public void lifeCycleStopping(LifeCycle event)
{
stopping = true;
Expand Down