com.hubspot.singularity.ServerProvider Maven / Gradle / Ivy
package com.hubspot.singularity;
import com.google.inject.Provider;
import io.dropwizard.lifecycle.ServerLifecycleListener;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import org.eclipse.jetty.server.Server;
public class ServerProvider
implements Provider>, ServerLifecycleListener {
private final AtomicReference serverHolder = new AtomicReference<>();
@Inject
public ServerProvider() {}
@Override
public Optional get() {
return Optional.ofNullable(serverHolder.get());
}
@Override
public void serverStarted(Server server) {
serverHolder.set(server);
}
}