Giter VIP home page Giter VIP logo

Comments (15)

dbu avatar dbu commented on June 30, 2024

hi, glad to hear you are as interested in jcr/phpcr as we are!

the best place to discuss is problably the mailinglist https://groups.google.com/forum/#!forum/jackalope-dev

i will try to answer your questions here:

as i understand locking, you can indeed write concurrently, and each operation overwrites what the previous one did (unless that is impossible because the node has been deleted). the best thing to be really sure is playing with https://github.com/jackalope/JavaDavexClient to see what the java client-server combination is doing, or using the phpcr-api-tests. there are some about locks and concurrency, for example https://github.com/phpcr/phpcr-api-tests/blob/master/tests/10_Writing/AddMethodsTest.php#L252 and https://github.com/phpcr/phpcr-api-tests/blob/master/tests/10_Writing/CombinedManipulationsTest.php and https://github.com/phpcr/phpcr-api-tests/tree/master/tests/17_Locking

however, looking at the locking tests i see we don't actually test if violating a lock leads to the expected error. if you want to improve the tests, we would appreciate a pull request for that.

note that we did not implement lock tokens and non-session locks. such locks could be useful in a cms, notably with php which kills the session on each request... jackalope/jackalope#67

one question: when you write you built abstractions on top of jackalope, what do you mean? tools for working with phpcr? there is phpcr-utils for some operations, and the phpcr-shell and a phpcr-browser: http://phpcr.github.io/tools/ - and then there is doctrine phpcr-odm that provides an object-document mapper with phpcr. and the symfony cmf providing building blocks for content management application. what are your abstractions doing? maybe you can join some effort, or if its something different, we can make them more known if they are of general interest...

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

Thanks for your response. The link on locking tests was most helpful. Haven't looked into the forums yet, will do so soon.

As you pointed out, data from the last edit/write in the timeline of a node will overwrite all other stuff. I think it would be extremely rare that a node is edited at the very same instant (given that we are writing only a handful of properties/ nodes) causing a conflict in timelines of a node. I assume, and it is most likely a wrong assumption, that violations (of which I was thinking of earlier and you also mention) maybe too rare to safely ignore.

To test this, I will try to make a simulation that locks and edits the same node using different sessions at the very same instant and we will see what happens (It maybe interesting to find a way to arrive at a statistic, running the test n number of times). There can ofcourse be many variants (how to handle locked child nodes for example). To begin with, I'll assume that the node is a leaf (thus a shallow lock). Perhaps this test maybe included in your project if you find it useful. (Can't commit to and do a pull request just now, am swamped with many projects. But I'll keep on working on this test, already have your library set up and working!)

In case there are violations and exceptions do show up, I think a very simple mechanism of checking back every 10/20/50 ms would do the trick (it would have to be blocking** in the sense that the end-user will have to wait). With such a lock listener (if we can call it that), perhaps the need of tokens in the context of locking/ unlocking will be diminished, maybe even forgone.

** [Note: I use ActiveMQ-PHP for many asynchronous tasks - mailing, etc. It maybe fun to explore how to make ActiveMQ-PHP-JCR talk and work together. The most obvious drawback is that such a setup will be good when JCR is used as for content read/write only. Also, I haven't really though what would happen if there were multiple listeners. But oh well, I like to fantasise.]

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

On abstractions: They are a bunch of classes and methods that are built for content management and serving purposes. Having searched for and looked at various tools you mention (phpcr-shell, phpcr-browser, phpcr-utils, etc), I'll say these abstractions are most like Symfony** CMF bundles (not quite as complete or complex though, I'm only three weeks into JCR). I'll cite 4 bundles:

A CRUD class -- Does simple CRUD operations.
A Fetch class -- Simple class that gets content.

Content emitter API -- Currently, to retrieve and display content using Jackalope this is the process,

  • Open session
  • Write a query
  • Store it in a variable
  • Pass it to view for rendering

This emitter API aims to make content accessible directly though a URL. This class uses the Fetch class.

What this would mean is that one could directly echo stuff into views without having to query and pass a variable. This API is too rudimentary right now, I just started working on it last week.

A d3 tree browser/editor -- I've also recently started working on a AJAX-powered tree editor. I'm working on something along the lines of this example (in terms of look and feel). Right now I have a very simple JS class that can do CRUD operations. It'll take quite a lot of work before it can be practical in the face of hundreds of nodes.

This class uses the emitter API to get node data and an updater API to update a property (the update API can only update properties at the moment).

** I've felt like switching over to Symfony for a long time but can't because my company has it's own CMS framework (it does what it has to so no one can complain, plus we mostly make apps and not websites). While Symfony is pure awesome, we'r just habituated too much to our own stuff. Had I dived deep into the Symfony CMF, I'm sure I could have saved quite a lot of time.

I'm open to contributing stuff or joining some efforts. Does this library need some work? Apart from being the author of this library, what is your relation to these projects? Is there anyplace I should look to get started?

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

I'll write here again with the test results within 2 weeks.

from jackalope-jackrabbit.

dantleech avatar dantleech commented on June 30, 2024

@dbx834 tou might alao be interested in https://github.com/dantleech/slinp. It is a framework inspired by Apache Sling (recommend you look it up), and is all about exposing the PHPCR content repository to the web - it also has components, so no Symfony dependency. It is however in a very early stage of development and not very close to being stable...

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

@dantleech, Hello. Yes, I know about Sling and it is a brilliant project!

I've looked at your library and it's an excellent idea. It's objectives are the ones that come to mind when I think of what a PHP sling should be. Did you come up with the idea? I really like it.

I've started too on a similar concept with the same goals but my codes are not so clean nor the coding (pattern) as well thought out, but it does simple read-write operations reliably in a narrow context.

Would you like me to join dev? I'll drop work on my project (we won't lose much, I'll extract the good ideas from my codes) and go full-time on Slinp. I like how it's an independent library. If I join, I request we agree to keep it this way. The library can of course be ported anytime as a Symfony CMF bundle if it is stable and useful. Somewhere down the line, I'll use the same library for my web-projects but we can keep on working on the library and take it forward and see what happens.

I believe there is great scope if we are able to make a full-featured PHP-Sling.

from jackalope-jackrabbit.

dantleech avatar dantleech commented on June 30, 2024

You are more than welcome to join in the dev :) At the moment I am just slowly building up the idea, seeing what works and what doesn't. The current version differs from Sling in some ways, e.g. controller and templates are currently NOT in the content repository - I plan eventually to allow this, but am concentrating on getting a minimally viable application at the moment.

Also, although the components do not depend on Symfony, the SlinpBundle does, and it is this bundle that configures and uses the components and creates the application.

See: https://github.com/dantleech/slinp/wiki for instructions on getting started and running the test application.

Feel free to open an issue with any questions you have and we can go from there :)

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

@dantleech Okay, I'll start exploring and tinkering around.

About the SlinpBundle, I would like to explore if it is possible to make it (Slinp) available as a stand-alone library too. I'm totally fine with the library being used to further SlinpBundle at the same time.

Thanks for writing the wiki, I'll get started.

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

On the original topic of this thread -- Here is a helpful SO post on JCR I stumbled upon.

Quoted,

"If a node is likely to be modified by 2 concurrent sessions then you should always lock the node. Which ever session gets there last should wait for the lock to be released. If you don't lock then at least one of the sessions will throw an exception."

A helpful document on JCR node locking referenced in the SO post.

Maybe this is in favour of the idea of having a lock listener?

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

Now I'm wondering what happens if there are three or more concurrent sessions all trying at the same time 😃

from jackalope-jackrabbit.

dbu avatar dbu commented on June 30, 2024

cool, sounds like interesting stuff coming up here :-D

the cmf Routing is a component independant of the full stack symfony framwork (but the using symfony routing library standalone). this might be an alternative to your content emitter api if it needs to get more complex - not sure if slinp is using it as well.

for the browser thing, i would really look into the marmelab browser before doing your own ;-)

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

Hmmmm, I had a look at the Symfony routing lib as well as the CMF routing lib. Definitely a much better alternative to the routing I've used. Think I'll migrate the routing mechanism over to CMF routing, it would be a solid foundation.

I would like to ask, is there any particular reason you suggested CMF router rather than Symfony router?

Thanks for the pointers to marmelab browser, I'll look it up.

from jackalope-jackrabbit.

dbu avatar dbu commented on June 30, 2024

we should move this discussion to the cmf mailinglist ;-)

the difference is that the core symfony router is configured with a set of routes on instantiation. that works well for an application with a finite set of route patterns that map to controller. but for content management, the users create new urls all the time. rather than have one route that matches all and find the content in a controller, we opted to load routes from a database (orm, phpcr, phpcr-odm, ...) based on the request - that is what the DynamicRouter does. a good read is http://symfony.com/doc/current/cmf/components/routing/index.html - though if you are not familiar with the concept, you might want to browse http://symfony.com/doc/current/components/routing/introduction.html a bit to get an idea.

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

I've had a look at the CMF Router, I'll need to spend some time getting a good grasp on it. But I understand it in it's essence - a glorified post-modern switch-board for the web, very brilliant.

For now, I'm going to finish completing a minimum-viable, stable and standalone URL print/update engine built for & using PHPCR/Jackalope independent of CMF router.

Sure, I'll ask questions either on the Jackalope or the CMF mailing list from now on.

from jackalope-jackrabbit.

dbx834 avatar dbx834 commented on June 30, 2024

In regards to the original subject of this topic, for posterity and if anyone faces the same issue...

The conclusion is: If a node is likely to be modified by 2 concurrent sessions then you should always lock the node. Which ever session gets there last should wait for the lock to be released. If you don't lock then at least one of the sessions will throw an exception.

A simple lock listener could be wrapped in an OOP function/ class like so,

protected function lockListner($node){
    $isLocked   = function($node){return $this->lockManager->isLocked($node);};
    $x          = 0;
    $return     = true;
    do{
        $x++;
        if($x==100){
            $return = false;
            break;
        }
        usleep(50000);
    }while($isLocked($node));
    return $return;
}

PS: Lock manager is defined somewhere else in the class (the constructor for me). Note. This function will be blocking.

This function waits for 5 seconds for a lock to open. It depends on the implementation how a fail-case (node is still locked) is managed.

Have implemented it like so,

if($this->isLocked($someNode)===false){
    $this->lockNode($someNode);
}else{
    $wait   =   $this->lockListner($someNode); // Wait 5 seconds for node to unlock
    if($wait===true){
        $this->lockNode($someNode);
    }else{
        die('Node could not be unlocked, try again later.');
    }
}

from jackalope-jackrabbit.

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.