Search in sources :

Example 1 with Service

use of org.jvnet.hk2.annotations.Service in project jersey by jersey.

the class JettyContainerTest method testParentServiceLocator.

/**
     * Test that defined ServiceLocator becomes a parent of the newly created service locator.
     */
@Test
public void testParentServiceLocator() {
    final ServiceLocator locator = new ServiceLocatorImpl("MyServiceLocator", null);
    final Server server = JettyHttpContainerFactory.createServer(URI.create("http://localhost:9876"), new ResourceConfig(Resource.class), false, locator);
    JettyHttpContainer container = (JettyHttpContainer) server.getHandler();
    InjectionManager injectionManager = container.getApplicationHandler().getInjectionManager();
    HK2InjectionManager hk2InjectionManager = (HK2InjectionManager) injectionManager;
    ServiceLocator serviceLocator = hk2InjectionManager.getServiceLocator();
    assertTrue("Application injection manager was expected to have defined parent locator", serviceLocator.getParent() == locator);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Server(org.eclipse.jetty.server.Server) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) JettyHttpContainer(org.glassfish.jersey.jetty.JettyHttpContainer) ServiceLocatorImpl(org.jvnet.hk2.internal.ServiceLocatorImpl) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 2 with Service

use of org.jvnet.hk2.annotations.Service in project jersey by jersey.

the class ServiceLocatorGenerator method create.

@Override
public ServiceLocator create(final String name, final ServiceLocator parent) {
    if (parent != null && !(parent instanceof ServiceLocatorImpl)) {
        throw new AssertionError("parent must be a " + ServiceLocatorImpl.class.getName() + " instead it is a " + parent.getClass().getName());
    }
    final ServiceLocatorImpl sli = new CustomServiceLocator(name, (ServiceLocatorImpl) parent);
    final DynamicConfigurationImpl dci = new DynamicConfigurationImpl(sli);
    // The service locator itself
    dci.bind(Utilities.getLocatorDescriptor(sli));
    // The injection resolver for three thirty
    dci.addActiveDescriptor(Utilities.getThreeThirtyDescriptor(sli));
    // The dynamic configuration utility
    dci.bind(BuilderHelper.link(DynamicConfigurationServiceImpl.class, false).to(DynamicConfigurationService.class).in(Singleton.class.getName()).localOnly().build());
    dci.bind(BuilderHelper.createConstantDescriptor(new DefaultClassAnalyzer(sli)));
    dci.commit();
    return sli;
}
Also used : DynamicConfigurationImpl(org.jvnet.hk2.internal.DynamicConfigurationImpl) DefaultClassAnalyzer(org.jvnet.hk2.internal.DefaultClassAnalyzer) DynamicConfigurationServiceImpl(org.jvnet.hk2.internal.DynamicConfigurationServiceImpl) ServiceLocatorImpl(org.jvnet.hk2.internal.ServiceLocatorImpl)

Example 3 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class GrizzlyConfigSchemaMigrator method promoteVirtualServerProperties.

private void promoteVirtualServerProperties(HttpService service) throws TransactionFailure {
    for (VirtualServer virtualServer : service.getVirtualServer()) {
        ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {

            @Override
            public Object run(VirtualServer param) throws PropertyVetoException {
                if (param.getHttpListeners() != null && !"".equals(param.getHttpListeners())) {
                    param.setNetworkListeners(param.getHttpListeners());
                }
                param.setHttpListeners(null);
                final List<Property> propertyList = new ArrayList<Property>(param.getProperty());
                final Iterator<Property> it = propertyList.iterator();
                while (it.hasNext()) {
                    final Property property = it.next();
                    if ("docroot".equals(property.getName())) {
                        param.setDocroot(property.getValue());
                        it.remove();
                    } else if ("accesslog".equals(property.getName())) {
                        param.setAccessLog(property.getValue());
                        it.remove();
                    } else if ("sso-enabled".equals(property.getName())) {
                        param.setSsoEnabled(property.getValue());
                        it.remove();
                    }
                }
                param.getProperty().clear();
                param.getProperty().addAll(propertyList);
                return null;
            }
        }, virtualServer);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 4 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class MonitoringService method bootstrapNotifierList.

/**
 * Starts notifiers that are enabled with the monitoring service
 * @since 4.1.2.174
 */
public void bootstrapNotifierList() {
    notifierExecutionOptionsList = new ArrayList<>();
    if (configuration.getNotifierList() != null) {
        for (Notifier notifier : configuration.getNotifierList()) {
            ConfigView view = ConfigSupport.getImpl(notifier);
            NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
            notifierExecutionOptionsList.add(executionOptionsFactoryStore.get(annotation.type()).build(notifier));
        }
    }
    if (notifierExecutionOptionsList.isEmpty()) {
        // Add logging execution options by default
        LogNotifierExecutionOptions logNotifierExecutionOptions = new LogNotifierExecutionOptions();
        logNotifierExecutionOptions.setEnabled(true);
        notifierExecutionOptionsList.add(logNotifierExecutionOptions);
    }
}
Also used : NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) ConfigView(org.jvnet.hk2.config.ConfigView) Notifier(fish.payara.nucleus.notification.configuration.Notifier) LogNotifierExecutionOptions(fish.payara.nucleus.notification.log.LogNotifierExecutionOptions)

Example 5 with Service

use of org.jvnet.hk2.annotations.Service 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);
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) Notifier(fish.payara.nucleus.notification.configuration.Notifier) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)34 PropertyVetoException (java.beans.PropertyVetoException)26 ActionReport (org.glassfish.api.ActionReport)25 Config (com.sun.enterprise.config.serverbeans.Config)21 Property (org.jvnet.hk2.config.types.Property)17 ArrayList (java.util.ArrayList)9 Properties (java.util.Properties)9 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)7 Service (org.jvnet.hk2.annotations.Service)7 File (java.io.File)6 HashMap (java.util.HashMap)6 List (java.util.List)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 ObservableBean (org.jvnet.hk2.config.ObservableBean)4 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)4 Transactions (org.jvnet.hk2.config.Transactions)4 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)4 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)4