Package com.bobocode.bring.web.server
Class TomcatWebServer
java.lang.Object
com.bobocode.bring.web.server.TomcatWebServer
- All Implemented Interfaces:
WebServer
Implementation of the
WebServer
interface for the Apache Tomcat server.
This class encapsulates the embedded Tomcat server and provides methods to start,
stop, and retrieve information about the server.
The TomcatWebServer
constructor takes a configured Tomcat
instance
and initializes the server. The server is started in a separate thread to trigger
initialization listeners. Additionally, a blocking non-daemon thread is created to
prevent immediate shutdown of the server.
The start
method starts the Tomcat server, and the stop
method stops
the server. Both methods are synchronized to ensure thread safety during server
state changes.
This class uses a monitor object for synchronization and a volatile boolean flag
(started
) to track the server's state. It also contains methods for checking
whether connectors have started, getting a description of ports, and obtaining the
context path.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkConnectorHasStarted
(org.apache.catalina.connector.Connector connector) private void
private void
private String
int
getPort()
Return the port this server is listening on.private String
getPortsDescription
(boolean localPort) private void
void
start()
Starts the web server.private void
void
stop()
Stops the web server.private void
private void
-
Field Details
-
tomcat
private final org.apache.catalina.startup.Tomcat tomcat -
monitor
-
started
private volatile boolean started
-
-
Constructor Details
-
TomcatWebServer
public TomcatWebServer(org.apache.catalina.startup.Tomcat tomcat)
-
-
Method Details
-
initialize
private void initialize() -
startDaemonAwaitThread
private void startDaemonAwaitThread() -
stopSilently
private void stopSilently() -
destroySilently
private void destroySilently() -
start
public void start()Description copied from interface:WebServer
Starts the web server. Calling this method on an already started server has no effect. -
checkThatConnectorsHaveStarted
private void checkThatConnectorsHaveStarted() -
checkConnectorHasStarted
private void checkConnectorHasStarted(org.apache.catalina.connector.Connector connector) -
getPortsDescription
-
getContextPath
-
stop
public void stop()Description copied from interface:WebServer
Stops the web server. Calling this method on an already stopped server has no effect. -
stopTomcat
private void stopTomcat() throws org.apache.catalina.LifecycleException- Throws:
org.apache.catalina.LifecycleException
-
getPort
public int getPort()Description copied from interface:WebServer
Return the port this server is listening on.
-