use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class ContainerStarter method startContainer.
public Collection<EngineInfo> startContainer(Sniffer sniffer) {
assert sniffer != null;
String containerName = sniffer.getModuleType();
assert containerName != null;
// repositories which would allow access to the container module.
try {
HK2Module[] modules = sniffer.setup(null, logger);
logger.logp(Level.FINE, "ContainerStarter", "startContainer", "Sniffer {0} set up following modules: {1}", new Object[] { sniffer, modules != null ? Arrays.toString(modules) : "" });
} catch (FileNotFoundException fnf) {
logger.log(Level.SEVERE, fnf.getMessage());
return null;
} catch (IOException ioe) {
logger.log(Level.SEVERE, ioe.getMessage(), ioe);
return null;
}
// first the right container from that module.
Map<String, EngineInfo> containers = new HashMap<String, EngineInfo>();
for (String name : sniffer.getContainersNames()) {
ServiceHandle<Container> provider = serviceLocator.getServiceHandle(Container.class, name);
if (provider == null) {
logger.severe("Cannot find Container named " + name + ", so unable to start " + sniffer.getModuleType() + " container");
return null;
}
EngineInfo info = new EngineInfo(provider, sniffer, null);
containers.put(name, info);
}
// Now that we have successfully created all containers, let's register them as well.
for (Map.Entry<String, EngineInfo> entry : containers.entrySet()) {
registry.addContainer(entry.getKey(), entry.getValue());
}
return containers.values();
}
use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class AppServerStartup method printModuleStatus.
public static void printModuleStatus(ModulesRegistry registry, Level level) {
if (!logger.isLoggable(level) || registry == null) {
return;
}
StringBuilder sb = new StringBuilder("Module Status Report Begins\n");
for (HK2Module m : registry.getModules()) {
if (m.getState() == ModuleState.READY) {
sb.append(m).append("\n");
}
}
sb.append("\n");
// then resolved
for (HK2Module m : registry.getModules()) {
if (m.getState() == ModuleState.RESOLVED) {
sb.append(m).append("\n");
}
}
sb.append("\n");
// finally installed
for (HK2Module m : registry.getModules()) {
if (m.getState() != ModuleState.READY && m.getState() != ModuleState.RESOLVED) {
sb.append(m).append("\n");
}
}
sb.append("Module Status Report Ends");
logger.log(level, sb.toString());
}
use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.
the class OSGiModulesRegistryImpl method bundleChanged.
@Override
public void bundleChanged(BundleEvent event) {
// Extender implementation.
try {
final Bundle bundle = event.getBundle();
switch(event.getType()) {
case BundleEvent.INSTALLED:
{
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "[{0}] {1} installed", new Object[] { bundle.getBundleId(), bundle.getSymbolicName() });
}
break;
}
case BundleEvent.RESOLVED:
{
// call add as it processes provider names
OSGiModuleImpl m = makeModule(bundle);
add(m);
break;
}
case BundleEvent.UNINSTALLED:
{
final HK2Module m = getModule(bundle);
if (m != null) {
// getModule can return null if some bundle got uninstalled
// before we have finished initialization. This can
// happen if framework APIs are called in parallel
// by some third party bundles.
// We need to call remove as it processes provider names
// and updates the cache.
remove(m);
}
break;
}
case BundleEvent.UPDATED:
final HK2Module m = getModule(bundle);
if (m != null) {
// getModule can return null if some bundle got uninstalled
// before we have finished initialization. This can
// happen if framework APIs are called in parallel
// by some third party bundles.
// We need to call remove as it processes provider names
// and updates the cache.
remove(m);
}
// make a new module from the updated bundle data and add it
add(makeModule(bundle));
break;
}
} catch (Exception e) {
logger.logp(Level.WARNING, "OSGiModulesRegistryImpl", "bundleChanged", e.getMessage(), e);
}
}
use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.
the class OSGiModuleImpl method getImports.
@Override
public List<HK2Module> getImports() {
List<HK2Module> result = new ArrayList<>();
RequiredBundle[] requiredBundles = registry.getPackageAdmin().getRequiredBundles(bundle.getSymbolicName());
if (requiredBundles != null) {
for (RequiredBundle rb : requiredBundles) {
HK2Module m = registry.getModule(rb.getBundle());
if (m != null) {
// module is known to the module system
result.add(m);
} else {
// module is not known to us - may be the OSgi bundle depends on a native
// OSGi bundle
}
}
}
return result;
}
use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.
the class AbstractModulesRegistryImpl method populateServiceLocator.
/**
* Creates a {@link ServiceLocator} from all the modules in this registry
*
* @param name
* Determines which descriptors are loaded.
* @param postProcessors
*/
public void populateServiceLocator(String name, ServiceLocator serviceLocator, List<PopulatorPostProcessor> postProcessors) throws MultiException {
try {
for (final HK2Module module : getModules()) {
// TODO: should get the inhabitantsParser out of Main instead since
// this could have been overridden
List<ActiveDescriptor> allDescriptors = parseInhabitants(module, name, serviceLocator, postProcessors);
if (allDescriptors == null)
continue;
if (allDescriptors.isEmpty())
continue;
Map<ServiceLocator, List<ActiveDescriptor>> descriptorByServiceLocator = moduleDescriptors.get(module);
if (descriptorByServiceLocator == null) {
descriptorByServiceLocator = new HashMap<ServiceLocator, List<ActiveDescriptor>>();
moduleDescriptors.put(module, descriptorByServiceLocator);
}
List<ActiveDescriptor> foundDs = descriptorByServiceLocator.get(serviceLocator);
if (foundDs == null) {
foundDs = new LinkedList<ActiveDescriptor>();
descriptorByServiceLocator.put(serviceLocator, foundDs);
}
foundDs.addAll(allDescriptors);
}
} catch (Exception e) {
throw new MultiException(e);
}
// From now on, we will keep this service registry up-to-date with module system state
habitats.put(serviceLocator, name);
}
Aggregations