Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Resource Streams in Apache Sling

Avatar

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile
dan_klco
Level 5

09-10-2018

Latest Feature in Apache Sling: Resource Streams!

Replies

Avatar

Avatar
Validate 25
MVP
PuzanovsP
MVP

Likes

135 likes

Total Posts

541 posts

Correct Reply

164 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 10
View profile

Avatar
Validate 25
MVP
PuzanovsP
MVP

Likes

135 likes

Total Posts

541 posts

Correct Reply

164 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Contributor 2
Ignite 10
View profile
PuzanovsP
MVP

10-10-2018

Dear Dan,

Thank you for sharing this useful information,

Is there any need to close Stream ourselves or would it be hanlded by Sling?

Regards,

Peter

Avatar

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile
dan_klco
Level 5

10-10-2018

PuzanovsP​ - The Stream in question is a java.util.stream.Stream so it doesn't need to be closed.

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,155 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,155 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

10-10-2018

Thanks dan.klco​ for sharing this.

When ResourceStream traverse resource or resource tree , is it using kind of index? I am just wondering if it is not using index while search then query should be costly as compare to JCR queries.

Avatar

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile
dan_klco
Level 5

10-10-2018

Arun Patidar​ - It is doing repository traversals, not using indices. Similar to SlingQuery, it's going to be best for relatively shallow or targeted Resources structures vs. JCR Queries which are more appropriate for deeper structures or searches across the entire repository.

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,089 likes

Total Posts

3,122 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,089 likes

Total Posts

3,122 posts

Correct Reply

1,063 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

10-10-2018

But it would be definitly nice, if you could give it some hints if you expect that this is a small subtree and you expect a lot of results, or if you rather have a large subtree with a unknown (possible zero) number of results in the stream.

At least there is the nodeCounter Mbean [1] which could be queried to get a rough estimation of the number of nodes in a certain subtree. Maybe just based on that you could say "with more than 10'000 nodes let's try a query instead of a traversal". Then you could construct a query and see if it's backed by an index ([2],[3]). And if you also pass this you could do the query, which is then probably much faster than a traversal. Yes, you need at least OAK 1.6 (AEM 6.3) to have the chance to detect the existence of an index.

That's something which came to mind when I read about this. Because that's a huge bonus over rolling your own traversal.

[1] localhost:4502/system/console/jmx/org.apache.jackrabbit.oak%3Aname%3DnodeCounter%2Ctype%3DNodeCounter

[2] select * from [nt:unstructured] as n where n.someProperty = "value" option (traversal fail)

[3] Jackrabbit Oak – The Query Engine

Avatar

Avatar
Validate 10
Level 3
Radha_Krishna_N
Level 3

Likes

15 likes

Total Posts

51 posts

Correct Reply

4 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile

Avatar
Validate 10
Level 3
Radha_Krishna_N
Level 3

Likes

15 likes

Total Posts

51 posts

Correct Reply

4 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 10
View profile
Radha_Krishna_N
Level 3

28-10-2018

Thanks dan.klco​ for the article.

1. Can this API be used to set properties on the resource while traversing?

2. If yes, how do we pass resource resolver to commit?

Thanks,

Radha Krishna N

Avatar

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile

Avatar
Validate 1
Level 5
dan_klco
Level 5

Likes

53 likes

Total Posts

88 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Shape 1
Ignite 5
Ignite 40
Ignite 30
View profile
dan_klco
Level 5

31-10-2018

Yes, once you have a stream of resources you could perform a forEach action upon those resources. In this case you would probably commit your changes once complete rather than passing in the resolver and committing after every update.