You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Roland <wg...@ids.de> on 2013/08/23 11:14:30 UTC

OBR: discover resources who have a particular host

Hello OSGi-experts,
Is it possible to discover those resources who have a particular host?
for example...

String filter = "(host=my.host)";
repoAdmin.discoverResources(filter);

Thx,
Roland



--
View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-who-have-a-particular-host-tp5004680.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: OBR: discover resources who have a particular host

Posted by "Richard S. Hall" <he...@ungoverned.org>.
I would guess so, since I'm not aware of any "host" attribute...perhaps 
symbolicname...check in your repository.

-> richard

On 8/23/13 10:01 , Roland wrote:
> First, I also thought that it would work that way, but after several tries it
> still did not. Is the filter string incorrect?
>
>
>
> --
> View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-which-have-a-particular-host-tp5004680p5004688.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: OBR: discover resources who have a particular host

Posted by Roland <wg...@ids.de>.
First, I also thought that it would work that way, but after several tries it
still did not. Is the filter string incorrect?



--
View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-which-have-a-particular-host-tp5004680p5004688.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: OBR: discover resources who have a particular host

Posted by "Richard S. Hall" <he...@ungoverned.org>.
It appears that RepositoryAdmin.discoverResources(filterStr) pretty much 
does the same thing as your code below, no?

     public synchronized Resource[] discoverResources(String filterExpr) throws InvalidSyntaxException
     {
         initialize();

         Filter filter = filterExpr != null ? m_helper.filter(filterExpr) : null;
         Resource[] resources;
         MapToDictionary dict = new MapToDictionary(null);
         Repository[] repos = listRepositories();
         List matchList = new ArrayList();
         for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++)
         {
             resources = repos[repoIdx].getResources();
             for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++)
             {
                 dict.setSourceMap(resources[resIdx].getProperties());
                 if (filter == null || filter.match(dict))
                 {
                     matchList.add(resources[resIdx]);
                 }
             }
         }

         // Convert matching resources to an array an sort them by name.
         resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
         Arrays.sort(resources, m_nameComparator);
         return resources;
     }

-> richard


On 8/23/13 09:16 , Roland wrote:
> I can show you my workaround to illustrate what I mean:
>
>        ...
>        repository = repoAdmin.addRepository(obrfile.toURI().toURL());
>        resources = repository.getResources();
>        for(Resource resource : resources) {
>          Capability[] capabilities = resource.getCapabilities();
>          for(Capability capability : capabilities) {
>            if(capability.getName().equals("fragment")) {
>              Map<String,Object> properties = capability.getPropertiesAsMap();
>              if(properties.containsKey("host")) {
>                Object value = capability.getPropertiesAsMap().get("host");
>                if(value instanceof String) {
>                  if(hostsymbolicname.equals(value)) {
>                    discoveredresources.add(resource);
>                  }
>                }
>              }
>            }
>          }
>        }
>        ...
>
> ...but it would be fine if it looks like this:
>
>      String filter = "(host=my.host)";
>      repoAdmin.discoverResources(filter);
>
>
> Regards
> Roland
>
>
>
> --
> View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-which-have-a-particular-host-tp5004680p5004686.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


Re: OBR: discover resources who have a particular host

Posted by Roland <wg...@ids.de>.
I can show you my workaround to illustrate what I mean:

      ...
      repository = repoAdmin.addRepository(obrfile.toURI().toURL());
      resources = repository.getResources();
      for(Resource resource : resources) {
        Capability[] capabilities = resource.getCapabilities();
        for(Capability capability : capabilities) {
          if(capability.getName().equals("fragment")) {
            Map<String,Object> properties = capability.getPropertiesAsMap();
            if(properties.containsKey("host")) {
              Object value = capability.getPropertiesAsMap().get("host");
              if(value instanceof String) {
                if(hostsymbolicname.equals(value)) {
                  discoveredresources.add(resource);
                }
              }
            }
          }
        }
      }
      ...

...but it would be fine if it looks like this:

    String filter = "(host=my.host)";
    repoAdmin.discoverResources(filter); 


Regards
Roland



--
View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-which-have-a-particular-host-tp5004680p5004686.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: OBR: discover resources who have a particular host

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 8/23/13 08:45 , Richard S. Hall wrote:
> On 8/23/13 05:14 , Roland wrote:
>> Hello OSGi-experts,
>> Is it possible to discover those resources who have a particular host?
>> for example...
>>
>> String filter = "(host=my.host)";
>> repoAdmin.discoverResources(filter);
>
> I would guess no, since discovery is intended to query against 
> capabilities, not requirements.

Or are you asking to see which bundle provides which host capability?

-> richard

>>
>> -- 
>> View this message in context: 
>> http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-who-have-a-particular-host-tp5004680.html
>> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: OBR: discover resources who have a particular host

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 8/23/13 05:14 , Roland wrote:
> Hello OSGi-experts,
> Is it possible to discover those resources who have a particular host?
> for example...
>
> String filter = "(host=my.host)";
> repoAdmin.discoverResources(filter);

I would guess no, since discovery is intended to query against 
capabilities, not requirements.

-> richard

>
> Thx,
> Roland
>
>
>
> --
> View this message in context: http://apache-felix.18485.x6.nabble.com/OBR-discover-resources-who-have-a-particular-host-tp5004680.html
> Sent from the Apache Felix - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org