use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class ApplicationLifecycle method startDeployer.
private Deployer startDeployer(DeploymentContext context, String containerName, EngineInfo engineInfo) throws Exception {
final ActionReport report = context.getActionReport();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE, "Deployer")) {
Deployer deployer = engineInfo.getDeployer();
if (deployer == null) {
if (!startContainers(Collections.singleton(engineInfo), logger, context)) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
deployer = engineInfo.getDeployer();
if (deployer == null) {
report.failure(logger, "Got a null deployer out of the " + engineInfo.getContainer().getClass() + " container, is it annotated with @Service ?");
throw new DeploymentException("Deployer not found for container " + containerName);
}
}
return deployer;
}
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class DynamicConfigListener method processNetworkListener.
private <T extends ConfigBeanProxy> NotProcessed processNetworkListener(Changed.TYPE type, NetworkListener listener, final PropertyChangeEvent[] changedProperties) {
if (findConfigName(listener).equals(findConfigName(config))) {
boolean isAdminListener = ADMIN_LISTENER.equals(listener.getName());
Lock portLock = null;
try {
portLock = acquirePortLock(listener);
switch(type) {
case ADD:
final int[] ports = portLock.getPorts();
if (isAdminListener && ports[ports.length - 1] == -1) {
return null;
}
final Future future = grizzlyService.createNetworkProxy(listener);
if (future != null) {
future.get(RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
grizzlyService.registerContainerAdapters();
} else {
logger.log(Level.FINE, "Skipping proxy registration for the listener {0}", listener.getName());
}
break;
case REMOVE:
if (!isAdminListener) {
grizzlyService.removeNetworkProxy(listener);
}
break;
case CHANGE:
// If the listener is the admin listener
if (isAdminListener) {
return null;
}
// Only restart the network listener if something hasn't changed
if (!isRedundantChange(changedProperties)) {
MonitoringService ms = config.getMonitoringService();
String level = ms.getModuleMonitoringLevels().getHttpService();
// We only need to throw an unprocessed change event if monitoring is enabled for the HTTP service
if (level != null && (!level.equals(OFF))) {
String eventsMessage = "Monitoring statistics will be incorrect for " + listener.findHttpProtocolName() + " until restart due to changed attribute(s): ";
// so the for loop should only run once, but it's there just in case.
for (PropertyChangeEvent event : changedProperties) {
eventsMessage += ("\"" + event.getPropertyName() + "\" changed from \"" + event.getOldValue() + "\" to \"" + event.getNewValue() + "\".\n");
}
// Still restart the network listener, as it's only the monitoring that breaks.
grizzlyService.restartNetworkListener(listener, RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
return new NotProcessed(eventsMessage);
} else {
// Restart the network listener without throwing an unprocessed change
grizzlyService.restartNetworkListener(listener, RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
}
}
break;
default:
break;
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Network listener configuration error. Type: " + type, e);
} finally {
if (portLock != null) {
releaseListenerLock(portLock);
}
}
}
return null;
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class ConfigAttributeSetTest method simpleAttributeSetTest.
@Test
public void simpleAttributeSetTest() {
CommandRunnerImpl runner = habitat.getService(CommandRunnerImpl.class);
assertNotNull(runner);
// let's find our target
NetworkListener listener = null;
NetworkListeners service = habitat.getService(NetworkListeners.class);
for (NetworkListener l : service.getNetworkListener()) {
if ("http-listener-1".equals(l.getName())) {
listener = l;
break;
}
}
assertNotNull(listener);
// Let's register a listener
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
bean.addListener(this);
// parameters to the command
ParameterMap parameters = new ParameterMap();
parameters.set("value", "8090");
parameters.set("DEFAULT", "configs.config.server-config.http-service.http-listener.http-listener-1.port");
// execute the set command.
runner.getCommandInvocation("set", new HTMLActionReporter(), adminSubject()).parameters(parameters).execute();
// check the result.
String port = listener.getPort();
assertEquals(port, "8090");
// ensure events are delivered.
habitat.<Transactions>getService(Transactions.class).waitForDrain();
// finally
bean.removeListener(this);
// check we recevied the event
assertNotNull(event);
assertEquals("8080", event.getOldValue());
assertEquals("8090", event.getNewValue());
assertEquals("port", event.getPropertyName());
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class IiopServiceSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
IiopService iiopSvc = command.config.getExtensionByType(IiopService.class);
if (iiopSvc.getSslClientConfig() != null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiopsvc.alreadyExists", "IIOP Service " + "already has been configured with SSL configuration."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopService>() {
public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
SslClientConfig newSslClientCfg = param.createChild(SslClientConfig.class);
Ssl newSsl = newSslClientCfg.createChild(Ssl.class);
command.populateSslElement(newSsl);
newSslClientCfg.setSsl(newSsl);
param.setSslClientConfig(newSslClientCfg);
return newSsl;
}
}, iiopSvc);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class WebContainer method postConstruct.
@Override
public void postConstruct() {
ReentrantReadWriteLock mapperLock = grizzlyService.obtainMapperLock();
mapperLock.writeLock().lock();
try {
createProbeProviders();
injectionMgr = serviceLocator.getService(InjectionManager.class);
invocationMgr = serviceLocator.getService(InvocationManager.class);
tldProviders = serviceLocator.getAllServices(TldProvider.class);
createStatsProviders();
setJspFactory();
_appsWorkRoot = instance.getApplicationCompileJspPath().getAbsolutePath();
_modulesRoot = instance.getApplicationRepositoryPath();
appsStubRoot = instance.getApplicationStubPath().getAbsolutePath();
// TODO: ParserUtils should become a @Service and it should initialize itself.
// TODO: there should be only one EntityResolver for both DigesterFactory
// and ParserUtils
File root = _serverContext.getInstallRoot();
File libRoot = new File(root, "lib");
File schemas = new File(libRoot, "schemas");
File dtds = new File(libRoot, "dtds");
try {
ParserUtils.setSchemaResourcePrefix(schemas.toURI().toURL().toString());
ParserUtils.setDtdResourcePrefix(dtds.toURI().toURL().toString());
ParserUtils.setEntityResolver(serviceLocator.<EntityResolver>getService(EntityResolver.class, "web"));
} catch (MalformedURLException e) {
logger.log(SEVERE, EXCEPTION_SET_SCHEMAS_DTDS_LOCATION, e);
}
instanceName = _serverContext.getInstanceName();
webContainerFeatureFactory = getWebContainerFeatureFactory();
configureDynamicReloadingSettings();
setDebugLevel();
String maxDepth = null;
org.glassfish.web.config.serverbeans.WebContainer configWC = serverConfig.getExtensionByType(org.glassfish.web.config.serverbeans.WebContainer.class);
if (configWC != null) {
maxDepth = configWC.getPropertyValue(DISPATCHER_MAX_DEPTH);
}
if (maxDepth != null) {
int depth = -1;
try {
depth = Integer.parseInt(maxDepth);
} catch (NumberFormatException e) {
}
if (depth > 0) {
Request.setMaxDispatchDepth(depth);
logger.log(FINE, MAX_DISPATCH_DEPTH_SET, maxDepth);
}
}
File currentLogFile = loggingRuntime.getCurrentLogFile();
if (currentLogFile != null) {
logServiceFile = currentLogFile.getAbsolutePath();
}
Level level = Logger.getLogger("org.apache.catalina.level").getLevel();
if (level != null) {
logLevel = level.getName();
}
_embedded = serviceLocator.getService(EmbeddedWebContainer.class);
_embedded.setWebContainer(this);
_embedded.setLogServiceFile(logServiceFile);
_embedded.setLogLevel(logLevel);
_embedded.setFileLoggerHandlerFactory(fileLoggerHandlerFactory);
_embedded.setWebContainerFeatureFactory(webContainerFeatureFactory);
_embedded.setCatalinaHome(instance.getInstanceRoot().getAbsolutePath());
_embedded.setCatalinaBase(instance.getInstanceRoot().getAbsolutePath());
_embedded.setUseNaming(false);
if (_debug > 1) {
_embedded.setDebug(_debug);
}
_embedded.setLogger(new IASLogger(logger));
engine = _embedded.createEngine();
engine.setParentClassLoader(EmbeddedWebContainer.class.getClassLoader());
engine.setService(_embedded);
_embedded.addEngine(engine);
((StandardEngine) engine).setDomain(_serverContext.getDefaultDomainName());
engine.setName(_serverContext.getDefaultDomainName());
/*
* Set the server info. By default, the server info is taken from Version#getVersion. However, customers may override it
* via the product.name system property. Some customers prefer not to disclose the server info for security reasons, in
* which case they would set the value of the product.name system property to the empty string. In this case, the server
* name will not be publicly disclosed via the "Server" HTTP response header (which will be suppressed) or any container
* generated error pages. However, it will still appear in the server logs (see IT 6900).
*/
String serverInfo = System.getProperty("product.name");
if (serverInfo == null) {
ServerInfo.setServerInfo(Version.getVersion());
ServerInfo.setPublicServerInfo(Version.getVersion());
} else if (serverInfo.isEmpty()) {
ServerInfo.setServerInfo(Version.getVersion());
ServerInfo.setPublicServerInfo(serverInfo);
} else {
ServerInfo.setServerInfo(serverInfo);
ServerInfo.setPublicServerInfo(serverInfo);
}
initInstanceSessionProperties();
configListener = addAndGetWebConfigListener();
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
bean.addListener(configListener);
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
bean.addListener(configListener);
if (serverConfig.getAvailabilityService() != null) {
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getAvailabilityService());
bean.addListener(configListener);
}
transactions.addListenerForType(SystemProperty.class, configListener);
configListener.setNetworkConfig(serverConfig.getNetworkConfig());
// embedded mode does not have manager-propertie in domain.xml
if (configListener.managerProperties != null) {
ObservableBean managerBean = (ObservableBean) ConfigSupport.getImpl(configListener.managerProperties);
managerBean.addListener(configListener);
}
if (serverConfig.getJavaConfig() != null) {
((ObservableBean) ConfigSupport.getImpl(serverConfig.getJavaConfig())).addListener(configListener);
}
configListener.setContainer(this);
configListener.setLogger(logger);
events.register(this);
grizzlyService.addMapperUpdateListener(configListener);
HttpService httpService = serverConfig.getHttpService();
NetworkConfig networkConfig = serverConfig.getNetworkConfig();
if (networkConfig != null) {
// continue;
securityService = serverConfig.getSecurityService();
// Configure HTTP listeners
NetworkListeners networkListeners = networkConfig.getNetworkListeners();
if (networkListeners != null) {
List<NetworkListener> listeners = networkListeners.getNetworkListener();
for (NetworkListener listener : listeners) {
createHttpListener(listener, httpService);
}
}
setDefaultRedirectPort(defaultRedirectPort);
// Configure virtual servers
createHosts(httpService, securityService);
}
loadSystemDefaultWebModules();
// _lifecycle.fireLifecycleEvent(START_EVENT, null);
_started = true;
/*
* Start the embedded container. Make sure to set the thread's context classloader to the classloader of this class (see
* IT 8866 for details)
*/
ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
/*
* Trigger a call to sun.awt.AppContext.getAppContext(). This will pin the classloader of this class in memory and fix a
* memory leak affecting instances of WebappClassLoader that was caused by a JRE implementation change in 1.6.0_15
* onwards. See IT 11110
*/
ImageIO.getCacheDirectory();
_embedded.start();
} catch (LifecycleException le) {
logger.log(SEVERE, UNABLE_TO_START_WEB_CONTAINER, le);
} finally {
// Restore original context classloader
Thread.currentThread().setContextClassLoader(current);
}
} finally {
mapperLock.writeLock().unlock();
}
}
Aggregations