use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class RuntimeRootImpl method stopDomain.
public void stopDomain() {
final ModulesRegistry registry = InjectedValues.getInstance().getModulesRegistry();
final Collection<HK2Module> modules = registry.getModules("com.sun.enterprise.osgi-adapter");
if (modules.size() == 1) {
final HK2Module mgmtAgentModule = modules.iterator().next();
mgmtAgentModule.stop();
} else {
AMXLoggerInfo.getLogger().warning(AMXLoggerInfo.cantFindOSGIAdapter);
}
AMXLoggerInfo.getLogger().warning(AMXLoggerInfo.stoppingServerForcibly);
System.exit(0);
}
use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class DeploymentTracing method printModuleStatus.
public static void printModuleStatus(ModulesRegistry registry, Level level, Logger logger) {
if (!logger.isLoggable(level)) {
return;
}
int counter = 0;
StringBuilder sb = new StringBuilder("Module Status Report Begins\n");
for (HK2Module m : registry.getModules()) {
if (m.getState() == ModuleState.READY) {
sb.append(m).append("\n");
counter++;
}
}
sb.append("there were ").append(counter).append(" modules in ACTIVE state");
sb.append("\n");
counter = 0;
// then resolved
for (HK2Module m : registry.getModules()) {
if (m.getState() == ModuleState.RESOLVED) {
sb.append(m).append("\n");
counter++;
}
}
sb.append("there were ").append(counter).append(" modules in RESOLVED state");
sb.append("\n");
counter = 0;
// finally installed
for (HK2Module m : registry.getModules()) {
if (m.getState() != ModuleState.READY && m.getState() != ModuleState.RESOLVED) {
sb.append(m).append("\n");
counter++;
}
}
sb.append("there were ").append(counter).append(" modules in INSTALLED state");
sb.append("Module Status Report Ends");
logger.log(level, sb.toString());
}
use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class ListModulesCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
report.setActionDescription("List of modules");
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ActionReport.MessagePart top = report.getTopMessagePart();
top.setMessage("List Of Modules");
top.setChildrenType("Module");
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");
ActionReport.MessagePart childPart = top.addChild();
childPart.setMessage(sb.toString());
}
use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class ClassLoaderHierarchyImpl method createApplicationParentCL.
/**
* Sets up the parent class loader for the application class loader.
* Application class loader are under the control of the ArchiveHandler since
* a special archive file format will require a specific class loader.
*
* However GlassFish needs to be able to add capabilities to the application
* like adding APIs accessibility, this is done through its parent class loader
* which we create and maintain.
*
* @param parent the parent class loader
* @param context deployment context
* @return class loader capable of loading public APIs identified by the deployers
* @throws ResolveError if one of the deployer's public API module is not found.
*/
@Override
public ClassLoader createApplicationParentCL(ClassLoader parent, DeploymentContext context) throws ResolveError {
final ReadableArchive source = context.getSource();
List<ModuleDefinition> defs = new ArrayList<ModuleDefinition>();
// now let's see if the application is requesting any module imports
Manifest m = null;
try {
m = source.getManifest();
} catch (IOException e) {
logger.log(Level.SEVERE, "Cannot load application's manifest file :", e.getMessage());
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, e.getMessage(), e);
}
}
if (m != null) {
String importedBundles = m.getMainAttributes().getValue(ManifestConstants.BUNDLE_IMPORT_NAME);
if (importedBundles != null) {
for (String token : new Tokenizer(importedBundles, ",")) {
Collection<HK2Module> modules = modulesRegistry.getModules(token);
if (modules.size() == 1) {
defs.add(modules.iterator().next().getModuleDefinition());
} else {
throw new ResolveError("Not able to locate a unique module by name " + token);
}
}
}
// Applications can add an additional osgi repos...
String additionalRepo = m.getMainAttributes().getValue(org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_REPOSITORY);
if (additionalRepo != null) {
for (String token : new Tokenizer(additionalRepo, ",")) {
// Each entry should be name=path
int equals = token.indexOf('=');
if (equals == -1) {
// Missing '='...
throw new IllegalArgumentException("\"" + org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_REPOSITORY + ": " + additionalRepo + "\" is missing an '='. " + "It must be in the format: name=path[,name=path]...");
}
String name = token.substring(0, equals);
String path = token.substring(++equals);
addRepository(name, resolver.translate(path));
}
}
// Applications can also request to be wired to implementors of certain services.
// That means that any module implementing the requested service will be accessible
// by the parent class loader of the application.
String requestedWiring = m.getMainAttributes().getValue(org.glassfish.api.ManifestConstants.GLASSFISH_REQUIRE_SERVICES);
if (requestedWiring != null) {
for (String token : new Tokenizer(requestedWiring, ",")) {
for (Object impl : habitat.getAllServices(BuilderHelper.createContractFilter(token))) {
HK2Module wiredBundle = modulesRegistry.find(impl.getClass());
if (wiredBundle != null) {
defs.add(wiredBundle.getModuleDefinition());
}
}
}
}
}
if (defs.isEmpty()) {
return parent;
} else {
return modulesRegistry.getModulesClassLoader(parent, defs);
}
}
use of com.sun.enterprise.module.HK2Module in project Payara by payara.
the class H2Lifecycle method start.
/**
* Callback when the module enters the {@link ModuleState#READY READY} state.
* This is a good time to do any type of one time initialization
* or set up access to resources
* @param module the module instance
*/
public void start(HK2Module module) {
try {
final HK2Module myModule = module;
Thread thread = new Thread() {
public void run() {
try {
try {
Class driverClass = myModule.getClassLoader().loadClass("org.h2.Driver");
myModule.setSticky(true);
driverClass.newInstance();
} catch (ClassNotFoundException e) {
LogHelper.getDefaultLogger().log(Level.SEVERE, "Cannot load H2 Driver ", e);
} catch (java.lang.InstantiationException e) {
LogHelper.getDefaultLogger().log(Level.SEVERE, "Cannot instantiate H2 Driver", e);
} catch (IllegalAccessException e) {
LogHelper.getDefaultLogger().log(Level.SEVERE, "Cannot instantiate H2 Driver", e);
}
} catch (RuntimeException e) {
e.printStackTrace();
}
}
};
thread.start();
} catch (Throwable t) {
t.printStackTrace();
}
}
Aggregations