You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Jaco Prinsloo <ja...@gmail.com> on 2009/10/14 12:11:42 UTC

Jackrabbit Session inside Stateless Session EJB

Hi Experts,

What is the "correct" way to access a Jackrabbit session from within a
stateless session EJB:

1) Every request (method) opens a session, performs the work and then closes
the session again.
2) There is one session per SLSB which is opened in PostConstruct and closed
in PreDestroy.

Are there any advantages/disadvantages to these two approaches?

Thanks,
Jaco

Jackrabbit with a web service project

Posted by "Phukan, Anit" <An...@intuit.com>.
Hi,

I am having problems reading from my repository.xml file when I try to
call a web service for a jackrabbit operation from a client project. 

I am not sure if it is due to the location of the repository.xml not
being correct because it tries to read the db conn parameters of the
default repository.

My assumption would be that the class loader should load the
repository.xml file if it is in the classpath.

Please let me know if anyone has any suggestions.

Thanks
Anit

-----Original Message-----
From: Guo Du [mailto:mrduguo@gmail.com] 
Sent: Wednesday, October 14, 2009 2:04 PM
To: users@jackrabbit.apache.org
Subject: Re: Jackrabbit Session inside Stateless Session EJB

On Wed, Oct 14, 2009 at 11:11 AM, Jaco Prinsloo <ja...@gmail.com>
wrote:
> 1) Every request (method) opens a session, performs the work and then
closes
> the session again.
In general, we have a session open to process the request, works like
jdbc data source. It doesn't matter what environment you are using,
servlet container, ejb or standalone application.

> 2) There is one session per SLSB which is opened in PostConstruct and
closed
> in PreDestroy.
This is how you actual implement the session management in EJB
container.

> Are there any advantages/disadvantages to these two approaches?

I couldn't see the difference in your approaches.

-Guo

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Anton Gavazuk <an...@gmail.com>.
Hi community,
this discussion has been started long time ago but final aswer has not been
provided,
is anyone find right approach ?


2009/10/16 Jaco Prinsloo <ja...@gmail.com>

> Stateless beans are exclusively available for one user at a time, but it
> might be used by multiple users in sequence. In other words, members of a
> SLSB don't have to be thread-safe, but they may not be tight to a specific
> user either. So just to confirm, there should be no problem with multiple
> users using the same Session instance, as long as they don't do so
> concurrently?
>
> Thanks,
> Jaco
>
> On Thu, Oct 15, 2009 at 2:58 PM, Guo Du <mr...@gmail.com> wrote:
>
> > On Thu, Oct 15, 2009 at 1:26 PM, Jaco Prinsloo <ja...@gmail.com>
> > wrote:
> > > Thanks, so I assume there isn't any problem with reusing a session (as
> > > subsequent requests to the EJB could be made by different users)?
> >
> > I am not familiar with EJB. The bottom line is that jcr session
> > shouldn't be used by different user at the same time if they are going
> > to perform updates. If Stateless bean is exclusive available for one
> > user, it's safe to reuse the session for different methods. But if
> > multiple user could access the same bean instance, the session
> > shouldn't be reused.
> >
> > -Guo
> >
>

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Jaco Prinsloo <ja...@gmail.com>.
Stateless beans are exclusively available for one user at a time, but it
might be used by multiple users in sequence. In other words, members of a
SLSB don't have to be thread-safe, but they may not be tight to a specific
user either. So just to confirm, there should be no problem with multiple
users using the same Session instance, as long as they don't do so
concurrently?

Thanks,
Jaco

On Thu, Oct 15, 2009 at 2:58 PM, Guo Du <mr...@gmail.com> wrote:

> On Thu, Oct 15, 2009 at 1:26 PM, Jaco Prinsloo <ja...@gmail.com>
> wrote:
> > Thanks, so I assume there isn't any problem with reusing a session (as
> > subsequent requests to the EJB could be made by different users)?
>
> I am not familiar with EJB. The bottom line is that jcr session
> shouldn't be used by different user at the same time if they are going
> to perform updates. If Stateless bean is exclusive available for one
> user, it's safe to reuse the session for different methods. But if
> multiple user could access the same bean instance, the session
> shouldn't be reused.
>
> -Guo
>

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Guo Du <mr...@gmail.com>.
On Thu, Oct 15, 2009 at 1:26 PM, Jaco Prinsloo <ja...@gmail.com> wrote:
> Thanks, so I assume there isn't any problem with reusing a session (as
> subsequent requests to the EJB could be made by different users)?

I am not familiar with EJB. The bottom line is that jcr session
shouldn't be used by different user at the same time if they are going
to perform updates. If Stateless bean is exclusive available for one
user, it's safe to reuse the session for different methods. But if
multiple user could access the same bean instance, the session
shouldn't be reused.

-Guo

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Jaco Prinsloo <ja...@gmail.com>.
Thanks, so I assume there isn't any problem with reusing a session (as
subsequent requests to the EJB could be made by different users)?

On Thu, Oct 15, 2009 at 11:28 AM, Guo Du <mr...@gmail.com> wrote:

> On Thu, Oct 15, 2009 at 7:41 AM, Jaco Prinsloo <ja...@gmail.com>
> wrote:
> > Thanks for clarifying.
> > Perhaps I can clarify the difference with two pseudo-ish code examples:
> >
> > (1)
> > @Stateless
> > public class RepositoryEJB {
> >  @Resource private Repository repository;
> >
> >  public String getMimeType(String path) {
> >    Session session = repository.login( .. );
> >    String mimeType =
> > (String)session.getRootNode().getNode(path).getProperties().get( .. );
> >    session.logout();
> >    return mimeType;
> >  }
>
> >1) Every request (method) opens a session, performs the work and then
> closes
> > the session again.
>
> Sorry, I was missed the keywords "method" at first place. Open session
> COULD be expensive operation. I was never thought such a way to
> process request :(
>
> So the second is the right approach. Just make sure you closed the
> session properly at the end.
>
> -Guo
>

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Guo Du <mr...@gmail.com>.
On Thu, Oct 15, 2009 at 7:41 AM, Jaco Prinsloo <ja...@gmail.com> wrote:
> Thanks for clarifying.
> Perhaps I can clarify the difference with two pseudo-ish code examples:
>
> (1)
> @Stateless
> public class RepositoryEJB {
>  @Resource private Repository repository;
>
>  public String getMimeType(String path) {
>    Session session = repository.login( .. );
>    String mimeType =
> (String)session.getRootNode().getNode(path).getProperties().get( .. );
>    session.logout();
>    return mimeType;
>  }

>1) Every request (method) opens a session, performs the work and then closes
> the session again.

Sorry, I was missed the keywords "method" at first place. Open session
COULD be expensive operation. I was never thought such a way to
process request :(

So the second is the right approach. Just make sure you closed the
session properly at the end.

-Guo

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Jaco Prinsloo <ja...@gmail.com>.
Thanks for clarifying.
Perhaps I can clarify the difference with two pseudo-ish code examples:

(1)
@Stateless
public class RepositoryEJB {
  @Resource private Repository repository;

  public String getMimeType(String path) {
    Session session = repository.login( .. );
    String mimeType =
(String)session.getRootNode().getNode(path).getProperties().get( .. );
    session.logout();
    return mimeType;
  }

  public Long getSize(String path) {
    Session session = repository.login( .. );
    Long size =
(Long)session.getRootNode().getNode(path).getProperties().get( .. );
    session.logout();
    return size;
  }
}

(2)
@Stateless
public class RepositoryEJB {
  @Resource private Repository repository;

  private Session session;

  @PostConstruct
  public void postConstruct() {
    Session session = repository.login( .. );
  }

  @PreDestroy
  public void preDestroy() {
    session.logout();
  }

  public String getMimeType(String path) {
    return (String)session.getRootNode().getNode(path).getProperties().get(
.. );
  }

  public Long getSize(String path) {
    return (Long)session.getRootNode().getNode(path).getProperties().get( ..
);
  }
}

Which one is better?

Thank you,
Jaco

On Wed, Oct 14, 2009 at 11:04 PM, Guo Du <mr...@gmail.com> wrote:

> On Wed, Oct 14, 2009 at 11:11 AM, Jaco Prinsloo <ja...@gmail.com>
> wrote:
> > 1) Every request (method) opens a session, performs the work and then
> closes
> > the session again.
> In general, we have a session open to process the request, works like
> jdbc data source. It doesn't matter what environment you are using,
> servlet container, ejb or standalone application.
>
> > 2) There is one session per SLSB which is opened in PostConstruct and
> closed
> > in PreDestroy.
> This is how you actual implement the session management in EJB container.
>
> > Are there any advantages/disadvantages to these two approaches?
>
> I couldn't see the difference in your approaches.
>
> -Guo
>

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Guo Du <mr...@gmail.com>.
On Wed, Oct 14, 2009 at 11:11 AM, Jaco Prinsloo <ja...@gmail.com> wrote:
> 1) Every request (method) opens a session, performs the work and then closes
> the session again.
In general, we have a session open to process the request, works like
jdbc data source. It doesn't matter what environment you are using,
servlet container, ejb or standalone application.

> 2) There is one session per SLSB which is opened in PostConstruct and closed
> in PreDestroy.
This is how you actual implement the session management in EJB container.

> Are there any advantages/disadvantages to these two approaches?

I couldn't see the difference in your approaches.

-Guo

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Jaco Prinsloo <ja...@gmail.com>.
Hi Guo,

Sorry, I don't understand what you mean. Would you mind to elaborate?

Thank you,
Jaco

On Wed, Oct 14, 2009 at 1:14 PM, Guo Du <mr...@gmail.com> wrote:

> On Wed, Oct 14, 2009 at 11:11 AM, Jaco Prinsloo <ja...@gmail.com>
> wrote:
> > Hi Experts,
> >
> > What is the "correct" way to access a Jackrabbit session from within a
> > stateless session EJB:
> >
> > 1) Every request (method) opens a session, performs the work and then
> closes
> > the session again.
> > 2) There is one session per SLSB which is opened in PostConstruct and
> closed
> > in PreDestroy.
> >
> > Are there any advantages/disadvantages to these two approaches?
>
> They are different topic for "these two approaches".
>
> Point 1 is the session management strategy.
> Point 2 is the actual implementation in your EJB environment.
>
> -Guo
>

Re: Jackrabbit Session inside Stateless Session EJB

Posted by Guo Du <mr...@gmail.com>.
On Wed, Oct 14, 2009 at 11:11 AM, Jaco Prinsloo <ja...@gmail.com> wrote:
> Hi Experts,
>
> What is the "correct" way to access a Jackrabbit session from within a
> stateless session EJB:
>
> 1) Every request (method) opens a session, performs the work and then closes
> the session again.
> 2) There is one session per SLSB which is opened in PostConstruct and closed
> in PreDestroy.
>
> Are there any advantages/disadvantages to these two approaches?

They are different topic for "these two approaches".

Point 1 is the session management strategy.
Point 2 is the actual implementation in your EJB environment.

-Guo