use of org.glassfish.hk2.api.Context in project Payara by payara.
the class AbstractJMSContextManager method cleanup.
// Close and remove the JMSContext instances
@PreDestroy
public synchronized void cleanup() {
ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
ComponentInvocation currentInv = invMgr.getCurrentInvocation();
for (Entry<String, JMSContextEntry> entry : contexts.entrySet()) {
JMSContextEntry contextEntry = entry.getValue();
String ipId = contextEntry.getInjectionPointId();
JMSContext context = contextEntry.getCtx();
if (context != null) {
ComponentInvocation inv = contextEntry.getComponentInvocation();
if (inv != null && currentInv != inv)
invMgr.preInvoke(inv);
try {
context.close();
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, localStrings.getLocalString("JMSContext.impl.close", "Closed JMSContext instance associated with id {0}: {1}.", ipId, context.toString()));
}
} catch (Exception e) {
logger.log(Level.SEVERE, localStrings.getLocalString("JMSContext.impl.close.failure", "Failed to close JMSContext instance associated with id {0}: {1}.", ipId, context.toString()), e);
} finally {
if (inv != null && currentInv != inv)
invMgr.postInvoke(inv);
}
}
}
contexts.clear();
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class AbstractJMSContextManager method getContext.
public synchronized JMSContext getContext(String ipId, String id, JMSContextMetadata metadata, ConnectionFactory connectionFactory) {
JMSContextEntry contextEntry = contexts.get(id);
JMSContext context = null;
if (contextEntry == null) {
context = createContext(ipId, metadata, connectionFactory);
ServiceLocator serviceLocator = Globals.get(ServiceLocator.class);
InvocationManager invMgr = serviceLocator.getService(InvocationManager.class);
contexts.put(id, new JMSContextEntry(ipId, context, invMgr.getCurrentInvocation()));
} else {
context = contextEntry.getCtx();
}
return context;
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class GetMonitoringConfiguration method execute.
/**
* Method that is invoked when the asadmin command is performed.
* Pretty prints the Monitoring Service Configuration values.
* @param context
*/
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config name: " + targetUtil);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ActionReport actionReport = context.getActionReport();
ActionReport notifiersReport = actionReport.addSubActionsReport();
ActionReport attributeReport = actionReport.addSubActionsReport();
ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
actionReport.appendMessage(StringUtils.EOL);
Map<String, Object> map = new HashMap<>();
Properties extraProps = new Properties();
map.put("enabled", monitoringConfig.getEnabled());
map.put("amx", monitoringConfig.getAmx());
map.put("logfrequency", monitoringConfig.getLogFrequency());
map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
extraProps.put("jmxmonitoringConfiguration", map);
List<Map<String, String>> monitoredAttributes = new ArrayList<>();
for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
Object[] values = new Object[3];
values[0] = monitoredBean.getObjectName();
values[1] = monitoredBean.getAttributeName();
values[2] = monitoredBean.getDescription();
Map<String, String> monitoredAttribute = new HashMap<>();
monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
monitoredAttributes.add(monitoredAttribute);
attributeColumnFormatter.addRow(values);
}
// Cannot change key in line below - required for admingui propertyDescTable.inc
extraProps.put("monitored-beans", monitoredAttributes);
actionReport.setExtraProperties(extraProps);
if (!monitoringConfig.getNotifierList().isEmpty()) {
List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {
@Override
public Class<Notifier> apply(Notifier input) {
return resolveNotifierClass(input);
}
});
Properties notifierProps = new Properties();
for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
if (notifier != null) {
ConfigView view = ConfigSupport.getImpl(notifier);
NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
if (notifierClassList.contains(view.<Notifier>getProxyType())) {
Object[] values = new Object[2];
values[0] = annotation.type();
values[1] = notifier.getEnabled();
notifiersColumnFormatter.addRow(values);
Map<String, Object> mapNotifiers = new HashMap<>(2);
mapNotifiers.put("notifierName", values[0]);
mapNotifiers.put("notifierEnabled", values[1]);
notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
}
}
actionReport.getExtraProperties().putAll(notifierProps);
}
}
notifiersReport.setMessage(notifiersColumnFormatter.toString());
notifiersReport.appendMessage(StringUtils.EOL);
attributeReport.setMessage(attributeColumnFormatter.toString());
attributeReport.appendMessage(StringUtils.EOL);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class ConnectionManager method getSecureConnection.
/**
* creates a connection to the loadbalancer
* @param contextRoot context root that will be used in constructing the URL
* @throws java.io.IOException
* @return HTTPS connection to the load balancer.
*/
private HttpsURLConnection getSecureConnection(String contextRoot) throws IOException {
if (_lbHost == null || _lbPort == null) {
String msg = LbLogUtil.getStringManager().getString("LbDeviceNotConfigured", _lbName);
throw new IOException(msg);
}
HttpsURLConnection conn = null;
URL url = null;
try {
// ---------------------------------
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance(TLS);
ServiceLocator habitat = Globals.getDefaultHabitat();
SSLUtils sslUtils = habitat.getService(SSLUtils.class);
sc.init(sslUtils.getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
// ---------------------------------
url = new URL(HTTPS_PROTOCOL, _lbHost, Integer.parseInt(_lbPort), contextRoot);
if (_lbProxyHost != null && _lbProxyPort != null) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(_lbProxyHost, Integer.parseInt(_lbProxyPort)));
conn = (HttpsURLConnection) url.openConnection(proxy);
} else {
conn = (HttpsURLConnection) url.openConnection();
}
conn.setSSLSocketFactory(sc.getSocketFactory());
HostnameVerifier hnv = new SSLHostNameVerifier();
conn.setDefaultHostnameVerifier(hnv);
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
}
return conn;
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class ACCModulesManager method initialize.
public static synchronized void initialize(final ClassLoader loader) throws URISyntaxException {
/*
* The habitat might have been initialized earlier. Currently
* we use a single habitat for the JVM.
*/
if (habitat == null) {
habitat = prepareHabitat(loader);
/*
* Set up the default habitat in Globals as soon as we know
* which habitat we'll use.
*/
Globals.setDefaultHabitat(habitat);
ServiceLocator locator = habitat;
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
/*
* Remove any already-loaded startup context so we can replace it
* with the ACC one.
*/
config.addUnbindFilter(BuilderHelper.createContractFilter(StartupContext.class.getName()));
/*
* Following the example from AppServerStartup, remove any
* pre-loaded lazy inhabitant for ProcessEnvironment that exists
* from HK2's scan for services. Then add in
* an ACC ProcessEnvironment.
*/
config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));
config.commit();
config = dcs.createDynamicConfiguration();
StartupContext startupContext = new ACCStartupContext();
AbstractActiveDescriptor<?> startupContextDescriptor = BuilderHelper.createConstantDescriptor(startupContext);
startupContextDescriptor.addContractType(StartupContext.class);
config.addActiveDescriptor(startupContextDescriptor);
ModulesRegistry modulesRegistry = new StaticModulesRegistry(ACCModulesManager.class.getClassLoader());
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(modulesRegistry));
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));
/*
* Create the ClientNamingConfigurator used by naming.
*/
ClientNamingConfigurator cnc = new ClientNamingConfiguratorImpl();
config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(cnc));
Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
AbstractActiveDescriptor<Logger> di = BuilderHelper.createConstantDescriptor(logger);
di.addContractType(Logger.class);
config.addActiveDescriptor(di);
config.commit();
}
}
Aggregations