use of org.glassfish.hk2.api.Context in project Payara by payara.
the class TransactionLifecycleService method postConstruct.
@Override
public void postConstruct() {
EventListener glassfishEventListener = new EventListener() {
@Override
public void event(Event event) {
if (event.is(EventTypes.SERVER_READY)) {
_logger.fine("TM LIFECYCLE SERVICE - ON READY");
onReady();
} else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
_logger.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
onShutdown();
}
}
};
events.register(glassfishEventListener);
if (nm != null) {
try {
nm.publishObject(USER_TX_NO_JAVA_COMP, new NamingObjectProxy.InitializationNamingObjectProxy() {
@Override
public Object create(Context ic) throws NamingException {
ActiveDescriptor<?> descriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("javax.transaction.UserTransaction"));
if (descriptor == null)
return null;
return habitat.getServiceHandle(descriptor).getService();
}
}, false);
} catch (NamingException e) {
_logger.warning("Can't bind \"UserTransaction\" in JNDI");
}
}
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class WeldFacesConfigProvider method getResources.
@Override
public Collection<URI> getResources(ServletContext context) {
ServiceLocator defaultServices = (ServiceLocator) context.getAttribute(HABITAT_ATTRIBUTE);
invokeMgr = defaultServices.getService(InvocationManager.class);
ComponentInvocation inv = invokeMgr.getCurrentInvocation();
WebModule webModule = (WebModule) inv.getContainer();
WebBundleDescriptor wdesc = webModule.getWebBundleDescriptor();
List<URI> list = new ArrayList<URI>(1);
if (!wdesc.hasExtensionProperty(WeldDeployer.WELD_EXTENSION)) {
return list;
}
// Don't use Util.getCurrentLoader(). This config resource should
// be available from the same classloader that loaded this instance.
// Doing so allows us to be more OSGi friendly.
ClassLoader loader = this.getClass().getClassLoader();
URL resource = loader.getResource(SERVICES_FACES_CONFIG);
if (resource != null) {
try {
list.add(resource.toURI());
} catch (URISyntaxException ex) {
if (logger.isLoggable(Level.SEVERE)) {
logger.log(Level.SEVERE, CDILoggerInfo.SEVERE_ERROR_CREATING_URI_FOR_FACES_CONFIG_XML, new Object[] { resource.toExternalForm(), ex });
}
}
}
return list;
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class DolProvider method processDeploymentMetaData.
/**
* This method populates the Application object from a ReadableArchive
* @param archive the archive for the application
*/
public Application processDeploymentMetaData(ReadableArchive archive) throws Exception {
FileArchive expandedArchive = null;
File tmpFile = null;
ExtendedDeploymentContext context = null;
Logger logger = Logger.getAnonymousLogger();
ClassLoader cl = null;
try {
String archiveName = Util.getURIName(archive.getURI());
ArchiveHandler archiveHandler = deployment.getArchiveHandler(archive);
if (archiveHandler == null) {
throw new IllegalArgumentException(localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", archiveName));
}
DeployCommandParameters parameters = new DeployCommandParameters(new File(archive.getURI()));
ActionReport report = new HTMLActionReporter();
context = new DeploymentContextImpl(report, archive, parameters, env);
context.setArchiveHandler(archiveHandler);
String appName = archiveHandler.getDefaultApplicationName(archive, context);
parameters.name = appName;
if (archive instanceof InputJarArchive) {
// we need to expand the archive first in this case
tmpFile = File.createTempFile(archiveName, "");
String path = tmpFile.getAbsolutePath();
if (!tmpFile.delete()) {
logger.log(Level.WARNING, "cannot.delete.temp.file", new Object[] { path });
}
File tmpDir = new File(path);
tmpDir.deleteOnExit();
if (!tmpDir.exists() && !tmpDir.mkdirs()) {
throw new IOException("Unable to create directory " + tmpDir.getAbsolutePath());
}
expandedArchive = (FileArchive) archiveFactory.createArchive(tmpDir);
archiveHandler.expand(archive, expandedArchive, context);
context.setSource(expandedArchive);
}
context.setPhase(DeploymentContextImpl.Phase.PREPARE);
ClassLoaderHierarchy clh = clhProvider.get();
context.createDeploymentClassLoader(clh, archiveHandler);
cl = context.getClassLoader();
deployment.getDeployableTypes(context);
deployment.getSniffers(archiveHandler, null, context);
return processDOL(context);
} finally {
if (cl != null && cl instanceof PreDestroy) {
try {
PreDestroy.class.cast(cl).preDestroy();
} catch (Exception e) {
// ignore
}
}
if (context != null) {
context.postDeployClean(true);
}
if (expandedArchive != null) {
try {
expandedArchive.close();
} catch (Exception e) {
// ignore
}
}
if (tmpFile != null && tmpFile.exists()) {
try {
FileUtils.whack(tmpFile);
} catch (Exception e) {
// ignore
}
}
}
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class GetNotificationConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ActionReport mainActionReport = context.getActionReport();
final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
String[] headers = { "Enabled", "Notifier Enabled" };
ColumnFormatter columnFormatter = new ColumnFormatter(headers);
if (configuration.getNotifierConfigurationList().isEmpty()) {
mainActionReport.setMessage("No notifier defined");
} else {
List<Class<NotifierConfiguration>> notifierConfigurationClassList = Lists.transform(configuration.getNotifierConfigurationList(), new Function<NotifierConfiguration, Class<NotifierConfiguration>>() {
@Override
public Class<NotifierConfiguration> apply(NotifierConfiguration input) {
return resolveNotifierConfigurationClass(input);
}
});
Properties extraProps = new Properties();
for (ServiceHandle<BaseNotifierService> serviceHandle : allServiceHandles) {
NotifierConfiguration notifierConfiguration = configuration.getNotifierConfigurationByType(serviceHandle.getService().getNotifierConfigType());
if (notifierConfiguration != null) {
ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
if (notifierConfigurationClassList.contains(view.<NotifierConfiguration>getProxyType())) {
Object[] values = new Object[2];
values[0] = notificationServiceConfiguration.getEnabled();
values[1] = notifierConfiguration.getEnabled();
columnFormatter.addRow(values);
Map<String, Object> map;
if (NotifierType.LOG.equals(annotation.type())) {
map = new HashMap<>(3);
map.put("enabled", values[0]);
map.put("notifierEnabled", values[1]);
LogNotifierConfiguration logNotifierConfiguration = (LogNotifierConfiguration) notifierConfiguration;
map.put("useSeparateLogFile", logNotifierConfiguration.getUseSeparateLogFile());
} else {
map = new HashMap<>(2);
map.put("enabled", values[0]);
map.put("notifierEnabled", values[1]);
}
extraProps.put("getNotificationConfiguration" + annotation.type(), map);
}
}
}
mainActionReport.setExtraProperties(extraProps);
mainActionReport.setMessage(columnFormatter.toString());
}
mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.hk2.api.Context in project Payara by payara.
the class NotifierServiceLister method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
if (allServiceHandles.isEmpty()) {
report.appendMessage(strings.getLocalString("notifier.list.services.warning", "No registered notifier service found."));
report.setActionExitCode(ActionReport.ExitCode.WARNING);
} else {
StringBuffer sb = new StringBuffer();
sb.append(strings.getLocalString("notifier.list.services.availability.info", "Available Notifier Services") + ":\n");
Properties extrasProps = new Properties();
ArrayList<String> names = new ArrayList<String>();
for (ServiceHandle serviceHandle : allServiceHandles) {
sb.append("\t" + serviceHandle.getActiveDescriptor().getName() + "\n");
names.add(serviceHandle.getActiveDescriptor().getName());
}
extrasProps.put("avaliableServices", names);
report.setMessage(sb.toString());
report.setExtraProperties(extrasProps);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
}
Aggregations