Skip to content

Commit

Permalink
save work
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Oct 28, 2019
1 parent b455e96 commit 31ab497
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public JettyActivator( final JettyConfig config )

@Activate
public void activate( final BundleContext context )
throws Exception
{
this.context = context;
fixJettyVersion();
Expand All @@ -73,18 +74,17 @@ public void activate( final BundleContext context )

private void publishXpServletContext()
{
ServletContext xpServletContext =
this.service.handlers().stream().map( handler -> (ServletContext) ( (ServletContextHandler) handler ).getServletContext() ).
filter( servletContext -> servletContext.getVirtualServerName().
equals( DispatchConstants.VIRTUAL_HOST_PREFIX + DispatchConstants.XP_CONNECTOR ) ).
findAny().orElse( null );

xpServletContextReg = context.registerService( XpServletContextProvider.class, new XpServletContextProviderImpl( xpServletContext ),
new Hashtable<>() );
this.service.handlers().stream().map( handler -> (ServletContext) ( (ServletContextHandler) handler ).getServletContext() ).
filter( servletContext -> servletContext.getVirtualServerName().
equals( DispatchConstants.VIRTUAL_HOST_PREFIX + DispatchConstants.XP_CONNECTOR ) ).
findAny().ifPresent( xpServletContext -> xpServletContextReg =
context.registerService( XpServletContextProvider.class, new XpServletContextProviderImpl( xpServletContext ),
new Hashtable<>() ) );
}

@Deactivate
public void deactivate()
throws Exception
{
this.controllerReg.unregister();
this.statusReporterReg.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ final class JettyService

private final JettyConfig config;


private final JettySessionStorageFactories jettySessionStorageFactories;

private Server server;
Expand All @@ -43,36 +42,6 @@ public JettyService( final JettySessionStorageFactories jettySessionStorageFacto
this.config = config;
}

public void start()
{
try
{
startJetty();
}
catch ( final Exception e )
{
stop();
LOG.error( "Exception while starting Jetty", e );
}
}

public void stop()
{
if ( this.server == null )
{
return;
}

try
{
stopJetty();
}
catch ( final Exception e )
{
LOG.error( "Exception while stopping Jetty", e );
}
}

int httpPort()
{
return config.http_xp_port();
Expand All @@ -89,32 +58,32 @@ List<Handler> handlers()
return handlers == null ? List.of() : List.of( handlers );
}

private void startJetty()
public void start()
throws Exception
{
this.server = new Server();

final Server server = new Server();

new HttpConfigurator().configure( this.config, this.server );
new HttpConfigurator().configure( this.config, server );

Metrics.removeAll( Handler.class );
final InstrumentedHandler instrumentedHandler = new InstrumentedHandler( Metrics.registry(), Handler.class.getName() );
instrumentedHandler.setHandler( contexts );

this.server.setHandler( contexts );
server.setHandler( contexts );

final DefaultSessionIdManager sessionManager = new DefaultSessionIdManager( this.server );
final DefaultSessionIdManager sessionManager = new DefaultSessionIdManager( server );

if ( jettySessionStorageFactories != null )
{
this.server.addBean( jettySessionStorageFactories.getSessionDataStoreFactory() );
this.server.addBean( jettySessionStorageFactories.getSessionCacheFactory() );
server.addBean( jettySessionStorageFactories.getSessionDataStoreFactory() );
server.addBean( jettySessionStorageFactories.getSessionCacheFactory() );
sessionManager.setWorkerName( jettySessionStorageFactories.getWorkerName() );
}

this.server.setSessionIdManager( sessionManager );
server.setSessionIdManager( sessionManager );

this.server.start();
server.start();
this.server = server;
LOG.info( "Started Jetty" );
LOG.info( "Listening on ports [{}](xp), [{}](management) and [{}](monitoring)", config.http_xp_port(),
config.http_management_port(), config.http_monitor_port() );
Expand All @@ -137,12 +106,16 @@ public static ServletContextHandler initServletContextHandler( final DispatchSer
return context;
}

private void stopJetty()
public void stop()
throws Exception
{
this.server.stop();
this.server = null;
LOG.info( "Stopped Jetty" );
final Server server = this.server;
if ( server != null )
{
server.stop();
this.server = null;
LOG.info( "Stopped Jetty" );
}
}

public Server getServer()
Expand Down

0 comments on commit 31ab497

Please sign in to comment.