Hi Felix devs,

I'm using karaf 4.2.7 which include felix util 1.11.2

There is an interface org.osgi.resource.Capability with these methods
          /**
                * Compares this {@code Capability} to another {@code
Capability}.
                *
                 * <p>
                * This {@code Capability} is equal to another {@code
Capability} if they
                * have the same namespace, directives and attributes
and are declared by
                * the same resource.
                *
                * @param obj The object to compare against this {@code
Capability}.
                * @return {@code true} if this {@code Capability} is
equal to the other
                *         object; {@code false} otherwise.
                */
                boolean equals(Object obj);


                /**
                * Returns the hashCode of this {@code Capability}.
                *
                * @return The hashCode of this {@code Capability}.
                */

                int hashCode();

And we also implement above interface via
org.apache.felix.utils.resource.CapabilityImpl but this class does not
implement equals() and hashCode().

This will be a problem when we have the same bundles expose the same
package org.apache.felix.utils.resource.CapabilitySet#addCapability
will add dupplicate capability.

E.g. I have a feature class named "my-feature" and this feature contains
<repository>mvn:org.apache.cxf.karaf/apache-cxf/${cxf.version}/xml/features</repository>

<feature name="my-feature">
   <bundle>mvn:org.apache.cxf/cxf-core/${cxf.version}</bundle>
   ... my other bundles ...
</feature>

During startup time, felix resolve export-packages from cxf-core and found
that cxf-core packages are exposed by 2 bundles (first one from
cxf-core in repository and the other from my-feature).

{ResourceImpl@24398} "org.apache.cxf.cxf-core/3.3.4" ->{Subsystem@24381}
"root#my-feature"
{ResourceImpl@24423} "org.apache.cxf.cxf-core/3.3.4" ->{Subsystem@24414}
"root#cxf-core-3.3.4"

+ export packages from cxf-core in repository.
{CapabilityImpl@7156} "[org.apache.cxf.cxf-core/3.3.4]osgi.wiring.package;
version:Version=3.3.4;bundle-symbolic-name=org.apache.cxf.cxf-core;bundle-version:Version=3.3.4;osgi.wiring.package=org.apache.cxf.annotations"
->{RequirementImpl@8400} "[org.apache.cxf.cxf-core/3.3.4]
osgi.wiring.package;filter:="(osgi.wiring.package=org.apache.cxf.annotations)""
{CapabilityImpl@7157} "[org.apache.cxf.cxf-core/3.3.4]osgi.wiring.package;
version:Version=3.3.4;bundle-symbolic-name=org.apache.cxf.cxf-core;bundle-version:Version=3.3.4;
osgi.wiring.package=org.apache.cxf.attachment" ->{RequirementImpl@8401}
"[org.apache.cxf.cxf-core/3.3.4]
osgi.wiring.package;filter:="(osgi.wiring.package=org.apache.cxf.attachment)""

+ export packages from cxf-core in my-feature.
{CapabilityImpl@9196} "[org.apache.cxf.cxf-core/3.3.4] osgi.wiring.package;
version:Version=3.3.4;
bundle-symbolic-name=org.apache.cxf.cxf-core;bundle-version:Version=3.3.4;osgi.wiring.package=org.apache.cxf.annotations"
->{RequirementImpl@8142} "[org.apache.cxf.cxf-core/3.3.4]
osgi.wiring.package;filter:="(osgi.wiring.package=org.apache.cxf.annotations)""
{CapabilityImpl@9197} "[org.apache.cxf.cxf-core/3.3.4]osgi.wiring.package;
version:Version=3.3.4;bundle-symbolic-name=org.apache.cxf.cxf-core;bundle-version:Version=3.3.4;
osgi.wiring.package=org.apache.cxf.attachment" ->{RequirementImpl@8146}
"[org.apache.cxf.cxf-core/3.3.4]
osgi.wiring.package;filter:="(osgi.wiring.package=org.apache.cxf.attachment)""

Due to this, these export-package from cxf-core will be moved to
m_substPermutations in org.apache.felix.resolver.ResolverImpl via
org.apache.felix.resolver.ResolverImpl.ResolveSession#addPermutation.

And if m_substPermutations grow huge, this will be a performence issue as
each permutation keep ~ 1mb.

Class Name                                                        |
Shallow Heap | Retained Heap | Percentage

--------------------------------------------------------------------------------------------------------------

org.apache.felix.resolver.ResolverImpl$ResolveSession @ 0xef76ce00|
       96 |   295,635,448 |     88.67%

|- java.util.LinkedList @ 0xf5fa02f8
   |           32 |   295,621,952 |     88.67%

|  |- java.util.LinkedList$Node @ 0xf51a6168                      |
       24 |       895,824 |      0.27%

|  |- java.util.LinkedList$Node @ 0xf52a0ca0                      |
       24 |       895,824 |      0.27%

|  |- java.util.LinkedList$Node @ 0xf53db7f8                       |
        24 |       895,824 |      0.27%

|  |- java.util.LinkedList$Node @ 0xf5496320                      |
       24 |       895,824 |      0.27%

|  |- java.util.LinkedList$Node @ 0xf55b0e58                      |
       24 |       895,824 |      0.27%

--------------------------------------------------------------------------------------------------------------

Is there any reason why are we not implement equals() and hashCode() in
Capability?
I think if we implement these methods, the size of CapabilitySet can be
reduced because we don't add duplicate Capability.

Thanks,
Tuan.  



--
Sent from: 
http://apache-felix.18485.x6.nabble.com/Apache-Felix-Dev-f4846309.html

Reply via email to