Search in sources :

Example 96 with Dictionary

use of java.util.Dictionary in project opennms by OpenNMS.

the class KarafExtender method init.

public void init() throws InterruptedException {
    Objects.requireNonNull(m_configurationAdmin, "configurationAdmin");
    Objects.requireNonNull(m_mavenResolver, "mavenResolver");
    Objects.requireNonNull(m_featuresService, "featuresService");
    List<Repository> repositories;
    try {
        repositories = getRepositories();
    } catch (IOException e) {
        LOG.error("Failed to retrieve the list of repositories. Aborting.", e);
        return;
    }
    // Prepend the featuresBoot from the repository definitions
    List<Feature> featuresBoot = repositories.stream().flatMap(r -> r.getFeaturesBoot().stream()).collect(Collectors.toList());
    try {
        featuresBoot.addAll(getFeaturesBoot());
    } catch (IOException e) {
        LOG.error("Failed to retrieve the list of features to boot. Aborting.", e);
        return;
    }
    // Filter the list of features
    filterFeatures(featuresBoot);
    // Build a comma separated list of our Maven repositories
    StringBuilder mavenReposSb = new StringBuilder();
    for (Repository repository : repositories) {
        if (mavenReposSb.length() != 0) {
            mavenReposSb.append(",");
        }
        mavenReposSb.append(repository.toMavenUri());
    }
    LOG.info("Updating Maven repositories to include: {}", mavenReposSb);
    try {
        final Configuration config = m_configurationAdmin.getConfiguration(PAX_MVN_PID);
        if (config == null) {
            throw new IOException("The OSGi configuration (admin) registry was found for pid " + PAX_MVN_PID + ", but a configuration could not be located/generated.  This shouldn't happen.");
        }
        final Dictionary<String, Object> props = config.getProperties();
        props.put(PAX_MVN_REPOSITORIES, mavenReposSb.toString());
        config.update(props);
    } catch (IOException e) {
        LOG.error("Failed to update the list of Maven repositories to '{}'. Aborting.", mavenReposSb, e);
        return;
    }
    // The configuration update is async, we need to wait for the feature URLs to be resolvable before we use them
    LOG.info("Waiting up-to 30 seconds for the Maven repositories to be updated...");
    // Attempting to resolve a missing features writes an exception to the log
    // We sleep fix a fixed amount of time before our first try in order to help minimize the logged
    // exceptions, even if we catch them
    Thread.sleep(2000);
    for (int i = 28; i > 0 && !canResolveAllFeatureUris(repositories); i--) {
        Thread.sleep(1000);
    }
    for (Repository repository : repositories) {
        for (URI featureUri : repository.getFeatureUris()) {
            try {
                LOG.info("Adding feature repository: {}", featureUri);
                m_featuresService.addRepository(featureUri);
                m_featuresService.refreshRepository(featureUri);
            } catch (Exception e) {
                LOG.error("Failed to add feature repository '{}'. Skipping.", featureUri, e);
            }
        }
    }
    final Set<String> featuresToInstall = featuresBoot.stream().map(f -> f.getVersion() != null ? f.getName() + "/" + f.getVersion() : f.getName()).collect(Collectors.toCollection(LinkedHashSet::new));
    try {
        LOG.info("Installing features: {}", featuresToInstall);
        m_featuresService.installFeatures(featuresToInstall, EnumSet.noneOf(Option.class));
    } catch (Exception e) {
        LOG.error("Failed to install one or more features.", e);
    }
}
Also used : Option(org.apache.karaf.features.FeaturesService.Option) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) FeaturesService(org.apache.karaf.features.FeaturesService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DirectoryStream(java.nio.file.DirectoryStream) Matcher(java.util.regex.Matcher) Lists(com.google.common.collect.Lists) Configuration(org.osgi.service.cm.Configuration) URI(java.net.URI) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) LinkedHashSet(java.util.LinkedHashSet) MavenResolver(org.ops4j.pax.url.mvn.MavenResolver) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Files(java.nio.file.Files) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Paths(java.nio.file.Paths) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) IOException(java.io.IOException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Option(org.apache.karaf.features.FeaturesService.Option)

Example 97 with Dictionary

use of java.util.Dictionary in project opennms by OpenNMS.

the class EchoRpcThreadIT method addServicesOnStartup.

@SuppressWarnings("rawtypes")
@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
    services.put(MinionIdentity.class.getName(), new KeyValueHolder<Object, Dictionary>(new MockMinionIdentity(REMOTE_LOCATION_NAME), new Properties()));
    Properties props = new Properties();
    props.setProperty("alias", "opennms.broker");
    services.put(Component.class.getName(), new KeyValueHolder<Object, Dictionary>(queuingservice, props));
    services.put(RpcModule.class.getName(), new KeyValueHolder<Object, Dictionary>(lockingRpcModule, new Properties()));
}
Also used : Dictionary(java.util.Dictionary) EchoRpcModule(org.opennms.core.rpc.echo.EchoRpcModule) RpcModule(org.opennms.core.rpc.api.RpcModule) MinionIdentity(org.opennms.minion.core.api.MinionIdentity) Properties(java.util.Properties) Component(org.apache.camel.Component)

Example 98 with Dictionary

use of java.util.Dictionary in project opennms by OpenNMS.

the class LocationAwareSnmpClientIT method addServicesOnStartup.

@SuppressWarnings("rawtypes")
@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
    services.put(MinionIdentity.class.getName(), new KeyValueHolder<Object, Dictionary>(new MinionIdentity() {

        @Override
        public String getId() {
            return "0";
        }

        @Override
        public String getLocation() {
            return REMOTE_LOCATION_NAME;
        }
    }, new Properties()));
    Properties props = new Properties();
    props.setProperty("alias", "opennms.broker");
    services.put(Component.class.getName(), new KeyValueHolder<Object, Dictionary>(queuingservice, props));
}
Also used : Dictionary(java.util.Dictionary) MinionIdentity(org.opennms.minion.core.api.MinionIdentity) Properties(java.util.Properties) Component(org.apache.camel.Component)

Example 99 with Dictionary

use of java.util.Dictionary in project intellij-community by JetBrains.

the class JavadocGenerationPanel method handleSlider.

private void handleSlider() {
    int value = myScopeSlider.getValue();
    Dictionary labelTable = myScopeSlider.getLabelTable();
    for (Enumeration enumeration = labelTable.keys(); enumeration.hasMoreElements(); ) {
        Integer key = (Integer) enumeration.nextElement();
        JLabel label = (JLabel) labelTable.get(key);
        label.setForeground(key.intValue() <= value ? Color.black : Gray._100);
    }
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration)

Example 100 with Dictionary

use of java.util.Dictionary in project intellij-community by JetBrains.

the class SliderSelectorAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final JPanel result = new JPanel(new BorderLayout());
    final JLabel label = new JLabel(myConfiguration.getSelectText());
    label.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 0));
    JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(label, BorderLayout.NORTH);
    final Dictionary dictionary = myConfiguration.getDictionary();
    final Enumeration elements = dictionary.elements();
    final JSlider slider = new JSlider(SwingConstants.HORIZONTAL, myConfiguration.getMin(), myConfiguration.getMax(), myConfiguration.getSelected()) {

        Integer myWidth = null;

        @Override
        public Dimension getPreferredSize() {
            final Dimension size = super.getPreferredSize();
            if (myWidth == null) {
                myWidth = 10;
                final FontMetrics fm = getFontMetrics(getFont());
                while (elements.hasMoreElements()) {
                    String text = ((JLabel) elements.nextElement()).getText();
                    myWidth += fm.stringWidth(text + "W");
                }
            }
            return new Dimension(myWidth, size.height);
        }
    };
    slider.setMinorTickSpacing(1);
    slider.setPaintTicks(true);
    slider.setPaintTrack(true);
    slider.setSnapToTicks(true);
    UIUtil.setSliderIsFilled(slider, true);
    slider.setPaintLabels(true);
    slider.setLabelTable(dictionary);
    if (!myConfiguration.isShowOk()) {
        result.add(wrapper, BorderLayout.WEST);
        result.add(slider, BorderLayout.CENTER);
    } else {
        result.add(wrapper, BorderLayout.WEST);
        result.add(slider, BorderLayout.CENTER);
    }
    final Runnable saveSelection = () -> {
        int value = slider.getModel().getValue();
        myConfiguration.getResultConsumer().consume(value);
    };
    final Ref<JBPopup> popupRef = new Ref<>(null);
    final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(result, slider).setMovable(true).setCancelOnWindowDeactivation(true).setCancelKeyEnabled(myConfiguration.isShowOk()).setKeyboardActions(Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveSelection.run();
            popupRef.get().closeOk(null);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)))).createPopup();
    popupRef.set(popup);
    if (myConfiguration.isShowOk()) {
        final JButton done = new JButton("Done");
        final JBPanel doneWrapper = new JBPanel(new BorderLayout());
        doneWrapper.add(done, BorderLayout.NORTH);
        result.add(doneWrapper, BorderLayout.EAST);
        done.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                saveSelection.run();
                popup.closeOk(null);
            }
        });
    } else {
        popup.setFinalRunnable(saveSelection);
    }
    InputEvent inputEvent = e.getInputEvent();
    show(e, result, popup, inputEvent);
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Ref(com.intellij.openapi.util.Ref) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

Dictionary (java.util.Dictionary)161 Hashtable (java.util.Hashtable)61 Test (org.junit.Test)48 Configuration (org.osgi.service.cm.Configuration)33 Enumeration (java.util.Enumeration)27 Properties (java.util.Properties)24 BundleContext (org.osgi.framework.BundleContext)21 ServiceReference (org.osgi.framework.ServiceReference)21 HashMap (java.util.HashMap)19 ServiceRegistration (org.osgi.framework.ServiceRegistration)19 Map (java.util.Map)17 ArrayList (java.util.ArrayList)15 Bundle (org.osgi.framework.Bundle)15 IOException (java.io.IOException)13 LinkedHashMap (java.util.LinkedHashMap)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)10 ComponentContext (org.osgi.service.component.ComponentContext)10 TreeMap (java.util.TreeMap)9 MinionIdentity (org.opennms.minion.core.api.MinionIdentity)9