Giter Club home page Giter Club logo

Comments (4)

bjhargrave avatar bjhargrave commented on June 20, 2024

Comment author: Lars Vogel <[email protected]>

The synchronized data structure HashTable is not recommened to be used, by several tools, e.g. Sonar shows this as warning. Would be nice if we could register services without creating warnings in our code.

Example:

Dictionary<String, String> props = new Hashtable<>();
	props.put(Constants.SERVICE_VENDOR, "Eclipse"); //$NON-NLS-1$
	props.put(Constants.SERVICE_PID, SimpleConfiguratorConstants.TARGET_CONFIGURATOR_NAME);
	ServiceFactory<?> configurationFactory = new SimpleConfiguratorFactory(context);
	configuratorRegistration = context.registerService(Configurator.class.getName(), configurationFactory, props);

from design.

HannesWell avatar HannesWell commented on June 20, 2024

Comment author: Lars Vogel <[email protected]>

The synchronized data structure HashTable is not recommened to be used, by several tools, e.g. Sonar shows this as warning.

Even the Java-doc of Dictionary says that Map should be used instead.

Dictionary is referenced in the following classes (at least in the eclipse implementation org.eclipse.osgi) :

  • org.osgi.framework.Bundle
  • org.osgi.framework.BundleContext
  • org.osgi.framework.Constants
  • org.osgi.framework.Filter
  • org.osgi.framework.FrameworkUtil
  • org.osgi.framework.ServiceEvent
  • org.osgi.framework.ServiceReference
  • org.osgi.framework.ServiceRegistration
  • org.osgi.service.condpermadmin.Condition

Some of them define API using Dictionary, some only consume it. But all of them should be considered when Dictionary is replaced some day.

from design.

bjhargrave avatar bjhargrave commented on June 20, 2024

See the new FrameworkUtil.asDictionary(Map) helper method which can be used here. This method was recently added as a bridge from Maps to the OSGi API.


Map<String, String> props = new HashMap<>();
	props.put(Constants.SERVICE_VENDOR, "Eclipse"); //$NON-NLS-1$
	props.put(Constants.SERVICE_PID, SimpleConfiguratorConstants.TARGET_CONFIGURATOR_NAME);
	ServiceFactory<?> configurationFactory = new SimpleConfiguratorFactory(context);
	configuratorRegistration = context.registerService(Configurator.class.getName(), configurationFactory, FrameworkUtil.asDictionary(props));

from design.

stbischof avatar stbischof commented on June 20, 2024

I can see your problems with the dictionary. But in most cases of using dictionaries it might be better to use newer patterns.
e.g. use @ Component and other ComponentPropertType annotations and do not try to register everything by hand in the BundleActivator.

The only way i really use an dictionary is in tests. But there I use the powerfully Dictionaries class. Maybe more of the functionally should be available in the framework package.

Btw.
The javadoc does not say that you should use maps instead of dictionarys. It says only to not do new implementations.

New implementations should implement the Map interface, rather than extending this class.

from design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.