use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method 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.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class ConsoleClassLoader method findModuleClassLoader.
/**
* <p> This method find the <code>ClassLoader</code> associated with the
* named module.</p>
*/
public static ClassLoader findModuleClassLoader(String moduleName) {
// System.out.println("Find module ClassLoader: " + moduleName);
// Get the ServletContext
ServletContext servletCtx = (ServletContext) (FacesContext.getCurrentInstance().getExternalContext()).getContext();
// Get the Habitat from the ServletContext
ServiceLocator habitat = (ServiceLocator) servletCtx.getAttribute(HABITAT_ATTRIBUTE);
// correct ClassLoader for the requested module (or null)
return habitat.<ConsolePluginService>getService(ConsolePluginService.class).getModuleClassLoader(moduleName);
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class DOLUtils method getModuleType.
/**
* Utility method to retrieve a {@link ArchiveType} from a stringified module type.
* Since {@link ArchiveType} is an extensible abstraction and implementations are plugged in via HK2 service
* registry, this method returns null if HK2 service registry is not setup.
*
* If null is passed to this method, it returns null instead of returning an arbitrary ArchiveType or throwing
* an exception.
*
* @param moduleType String equivalent of the module type being looked up. null is allowed.
* @return the corresponding ArchiveType, null if no such module type exists or HK2 Service registry is not set up
*/
public static ArchiveType getModuleType(String moduleType) {
if (moduleType == null) {
return null;
}
final ServiceLocator services = Globals.getDefaultHabitat();
ArchiveType result = null;
// This method is called without HK2 being setup when dol unit tests are run, so protect against NPE.
if (services != null) {
result = services.getService(ArchiveType.class, moduleType);
}
return result;
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class CompositeUtil method createConstructor.
/**
* This method creates the default constructor for the class. Default values are set for any @Attribute defined with
* a defaultValue.
*/
private void createConstructor(ClassWriter cw, String className, Map<String, Map<String, Object>> properties) {
MethodVisitor method = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
method.visitCode();
method.visitVarInsn(ALOAD, 0);
method.visitMethodInsn(INVOKESPECIAL, "org/glassfish/admin/rest/composite/RestModelImpl", "<init>", "()V");
for (Map.Entry<String, Map<String, Object>> property : properties.entrySet()) {
String fieldName = property.getKey();
String defaultValue = (String) property.getValue().get("defaultValue");
if (defaultValue != null && !defaultValue.isEmpty()) {
setDefaultValue(method, className, fieldName, (Class<?>) property.getValue().get("type"), defaultValue);
}
}
method.visitInsn(RETURN);
method.visitMaxs(1, 1);
method.visitEnd();
}
use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.
the class CompositeUtil method getModel.
/**
* This method will return a generated concrete class that implements the interface requested, as well as any
* interfaces intended to extend the base model interface. Model extensions must be annotated with
*
* @param modelIface The base interface for the desired data model
* @return An instance of a concrete class implementing the requested interfaces
* @throws Exception
* @RestModelExtension, and must be compiled with rest-annotation-processor library on the compile classpath
* for metadata generation.
*/
public synchronized <T> T getModel(Class<T> modelIface) {
String className = modelIface.getName() + "Impl";
if (!generatedClasses.containsKey(className)) {
Map<String, Map<String, Object>> properties = new HashMap<String, Map<String, Object>>();
Set<Class<?>> interfaces = getModelExtensions(modelIface);
interfaces.add(modelIface);
for (Class<?> iface : interfaces) {
analyzeInterface(iface, properties);
}
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
visitClass(classWriter, className, interfaces, properties);
for (Map.Entry<String, Map<String, Object>> entry : properties.entrySet()) {
String name = entry.getKey();
final Map<String, Object> property = entry.getValue();
Class<?> type = (Class<?>) property.get("type");
createField(classWriter, name, type);
createGettersAndSetters(classWriter, modelIface, className, name, property);
}
createConstructor(classWriter, className, properties);
classWriter.visitEnd();
Class<?> newClass;
try {
newClass = defineClass(modelIface, className, classWriter.toByteArray());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
generatedClasses.put(className, newClass);
}
try {
return (T) generatedClasses.get(className).newInstance();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
Aggregations