org.glassfish.jersey.netty.httpserver.NettyHttpContainer Maven / Gradle / Ivy
/*
* Copyright (c) 2016, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.jersey.netty.httpserver;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.server.ApplicationHandler;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spi.Container;
import org.glassfish.jersey.spi.ExecutorServiceProvider;
import org.glassfish.jersey.spi.ScheduledExecutorServiceProvider;
/**
* Netty based implementation of a {@link Container}.
*
* @author Pavel Bucek
*/
class NettyHttpContainer implements Container {
private volatile ApplicationHandler appHandler;
public NettyHttpContainer(Application application) {
this.appHandler = new ApplicationHandler(application);
this.appHandler.onStartup(this);
}
@Override
public ResourceConfig getConfiguration() {
return appHandler.getConfiguration();
}
@Override
public ApplicationHandler getApplicationHandler() {
return appHandler;
}
@Override
public void reload() {
reload(new ResourceConfig(appHandler.getConfiguration()));
}
@Override
public void reload(ResourceConfig configuration) {
appHandler.onShutdown(this);
appHandler = new ApplicationHandler(configuration);
appHandler.onReload(this);
appHandler.onStartup(this);
}
/**
* Get {@link java.util.concurrent.ExecutorService}.
*
* @return Executor service associated with this container.
*/
ExecutorService getExecutorService() {
return appHandler.getInjectionManager().getInstance(ExecutorServiceProvider.class).getExecutorService();
}
/**
* Get {@link ScheduledExecutorService}.
*
* @return Scheduled executor service associated with this container.
*/
ScheduledExecutorService getScheduledExecutorService() {
return appHandler.getInjectionManager().getInstance(ScheduledExecutorServiceProvider.class).getExecutorService();
}
}