Actually, there's no _logical_ problem manipulating Bitstreams and
metdata entries from within a Consumer if you follow two important rules:

1. Create a new Context for the modification operation.

2. Ensure your Consumer does NOT make any changes that cause events
   which trigger itself to run again, since this will cause an infinite loop.
   For example, say your Consumer adds thumbnail images.  Let's say it
   is coded to look for any addition of a Bitstream whose name ends in
   ".jpg", upon which it creates a miniature image and adds it as a
   Bitstream with the same name plus "-thumb.jpg" appended.  So when
   that Consumer runs on the event that created "foo.jpg", it creates a
   Bitstream named "foo.jpg-thumb.jpg" -- but *this* action also causes
   an event, that will trigger the same Consumer to create
   "foo.jpg-thumb.jpg-thumb.jpg", and so on.

   The solution is to make *sure* your Consumer cannot trigger itself.
   For the thumbnail example, that's easy -- always create the new
   Bitstreams in a THUMBNAIL Bundle, and have the Consumer ignore events
   on any Bitstream in that Bundle, so it's not triggered by its own work.

This is not to say it's a great idea; it's going to be inefficient,
since every event that prompts the changes will spawn a distinct
separate Context and transaction, which then triggers more Events that
get handled in separate batches.  If there is enough volume to be a
scaleability problem, maybe it's worth doing something more efficient
like having the events just accumulate changes in a DB table and process
them in a daily batch.

There is no need to try to trap or trace events your Consumer might
produce - just code your Consumer carefully so it won't trigger itself
and let the event system run as it is meant to.

See this wiki page for some more hints:
http://wiki.dspace.org/index.php/EventSystemPrototype#2._Consumer_execution_environment
(it describes the original form of the event system, which isn't exactly
what got adopted.)


> Excellent Question.  Having been on the team that brought that code
> into DSpace 1.5, I have rather intimate knowledge of this issue. We
> do not recommend using a Event Consumer to directly manipulate the
> Item in question by adding Bitstreams or altering its metadata
> because not only is that available Contexts transactional window is
> closed by the time you've reached processing the Event in the
> consumer, but its difficult to predict the behavior or risk of
> getting the Event System in the state of of an infinite event loop
> because your alterations will in turn, also alter the Item and
> generate new events in the process.  The event system is best for
> Consumers that do menial tasks like update the search index and which
> do not return to the object model in memory and attempt alter it
> again directly.
>
> Unfortunately, this is the sort of task most folks were hoping the
> Event System would solve in DSpace 1.5. I feel we are attempting to
> address its shortcomings in the DSpace 2.0 roadmap to come up with a
> solution.
>
> If you do decide to attempt to use the Event System in such a manner
> as to alter the Object in question and update it again, I would
> recommend using a new dspace Context and make sure you can trap the
> events in some sort of conditional check to make sure they should be
> propagated to through your Consumer again. It will be challenging to
> control the events continued propagation through the other consumers
> present in the Event Manager/Dispatcher.  The best I can advise you
> is that in some cases you will get duplicate requests to update the
> search and browse indexes.
>
> Sincerely,
> Mark
>
> On Jun 18, 2008, at 4:31 PM, John Preston wrote:
>
> > Can someone say whether it is advisable or not to use the new event
> > system under 1.5 to add metadata or bitstreams to an item.
> >
> > I am moving some of my code to event consumers that would add
> > metadata for various item types as well as add bitstreams based on
> > bitstreams already ingested. However I'm getting an exception when
> > I try to commit these additions within the consumer (either the
> > consume, end or finish methods). The particular exception is:
> >
> > java.util.ConcurrentModificationException
> >        at java.util.AbstractList$Itr.checkForComodification
> > (AbstractList.java:372)
> >        at java.util.AbstractList$Itr.next(AbstractList.java:343)
> >        at org.dspace.event.BasicDispatcher.dispatch
> > (BasicDispatcher.java:122)
> >        at org.dspace.core.Context.commit(Context.java:286)
> >        at org.ejamaica.server.dspace.DSpaceInstance.addSaying
> > (DSpaceInstance.java:1906)
> >        at org.ejamaica.server.dspace.DSpaceInstance.updateSaying
> > (DSpaceInstance.java:1060)
> >        at org.ejamaica.server.MyLibraryServiceImpl.myMethod
> > (MyLibraryServiceImpl.java:147)
> >
> > Just for info. the section in my code that triggers the initial
> > context.commit() occurs in DSpaceInstance.java:1906.
> >
> > If I don't commit after I add some metadata and/or bitstreams then
> > I don't get the error, but then the data and bitstreams don't
> > appear. If I even try and use the context.getDBConnection().commit
> > (); I get the same exception.
> >
> > John
>
>
> ~~~~~~~~~~~~~
> Mark R. Diggory - DSpace Developer and Systems Manager
> MIT Libraries, Systems and Technology Services
> Massachusetts Institute of Technology
> Home Page: http://purl.org/net/mdiggory/homepage
>
>
>
>
>
>
> --Apple-Mail-3--696615416
> Content-Transfer-Encoding: quoted-printable
> Content-Type: text/html;
>       charset=ISO-8859-1
>
> <html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
> -webkit-line-break: after-white-space; ">
> John,<div><br></div><div>Excellent Question. =A0Having been on the team =
> that brought that code into DSpace 1.5, I have rather intimate knowledge =
> of this issue. We do not recommend using a Event Consumer to directly =
> manipulate the Item in question by adding Bitstreams or altering its =
> metadata because not only is that available Contexts transactional =
> window is closed by the time you've reached=A0processing=A0the Event in =
> the consumer, but its difficult to predict the behavior or risk of =
> getting the Event System in the state of of an infinite event loop =
> because your alterations will in turn, also alter the Item and generate =
> new events in the process. =A0The event system is best for Consumers =
> that do menial tasks like update the search index and which do not =
> return to the object model in memory and attempt alter it again =
> directly.<div><br></div><div>Unfortunately, this is the sort of task =
> most folks were hoping the Event System would solve in DSpace 1.5. I =
> feel we are attempting to address its shortcomings in the DSpace 2.0 =
> roadmap to come up with a solution.</div><div><br></div><div>If you do =
> decide to=A0attempt=A0to use the Event System in such a manner as to =
> alter the Object in question and update it again, I would recommend =
> using a new dspace Context and make sure you can trap the events in some =
> sort of conditional check to make sure they should be=A0propagated=A0to =
> through your Consumer again. It will be challenging to control the =
> events continued=A0propagation=A0through the other consumers present in =
> the Event Manager/Dispatcher. =A0The best I can advise you is that in =
> some cases you will get duplicate requests to update the search and =
> browse =
> indexes.</div><div><br></div><div>Sincerely,</div><div>Mark</div><div><br>=
> <div><div>On Jun 18, 2008, at 4:31 PM, John Preston wrote:</div><br =
> class=3D"Apple-interchange-newline"><blockquote type=3D"cite">Can =
> someone say whether it is advisable or not to use the new event system =
> under 1.5 to add metadata or bitstreams to an item.<br><br>I am moving =
> some of my code to event consumers that would add metadata for various =
> item types as well as add bitstreams based on bitstreams already =
> ingested. However I'm getting an exception when I try to commit these =
> additions within the consumer (either the consume, end or finish =
> methods). The particular exception is:<br> =
> <br>java.util.ConcurrentModificationException<br><div class=3D"Ih2E3d"> =
> =A0 =A0 =A0 =A0at =
> java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)<b=
> r> =A0 =A0 =A0 =A0at =
> java.util.AbstractList$Itr.next(AbstractList.java:343)<br> =A0 =A0 =A0 =
> =A0at =
> org.dspace.event.BasicDispatcher.dispatch(BasicDispatcher.java:122)<br> =
> =A0 =A0 =A0 =A0at org.dspace.core.Context.commit(Context.java:286)<br> =A0=
>  =A0 =A0 =A0at =
> org.ejamaica.server.dspace.DSpaceInstance.addSaying(DSpaceInstance.java:19=
> 06)<br> =A0 =A0 =A0 =A0at =
> org.ejamaica.server.dspace.DSpaceInstance.updateSaying(DSpaceInstance.java=
> :1060)<br> =A0 =A0 =A0 =A0at =
> org.ejamaica.server.MyLibraryServiceImpl.myMethod(MyLibraryServiceImpl.jav=
> a:147)<br> </div><br>Just for info. the section in my code that triggers =
> the initial context.commit() occurs in =
> DSpaceInstance.java:1906.<br><br>If I don't commit after I add some =
> metadata and/or bitstreams then I don't get the error, but then the data =
> and bitstreams don't appear. If I even try and use the =
> context.getDBConnection().commit(); I get the same exception.<br> =
> <br>John</blockquote></div><div><br></div></div></div><div> <span =
> class=3D"Apple-style-span" style=3D"border-collapse: separate; color: =
> rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: =
> normal; font-variant: normal; font-weight: normal; letter-spacing: =
> normal; line-height: normal; orphans: 2; text-align: auto; text-indent: =
> 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: =
> 0px; -webkit-border-horizontal-spacing: 0px; =
> -webkit-border-vertical-spacing: 0px; =
> -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
> auto; -webkit-text-stroke-width: 0; "><span class=3D"Apple-style-span" =
> style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
> Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
> font-weight: normal; letter-spacing: normal; line-height: normal; =
> orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
> widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
> -webkit-border-vertical-spacing: 0px; =
> -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
> auto; -webkit-text-stroke-width: 0px; "><span class=3D"Apple-style-span" =
> style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
> Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
> font-weight: normal; letter-spacing: normal; line-height: normal; =
> orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
> widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
> -webkit-border-vertical-spacing: 0px; =
> -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
> auto; -webkit-text-stroke-width: 0px; "><span class=3D"Apple-style-span" =
> style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
> Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
> font-weight: normal; letter-spacing: normal; line-height: normal; =
> orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
> widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
> -webkit-border-vertical-spacing: 0px; =
> -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
> auto; -webkit-text-stroke-width: 0px; "><span class=3D"Apple-style-span" =
> style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =
> Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =
> font-weight: normal; letter-spacing: normal; line-height: normal; =
> orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; =
> widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; =
> -webkit-border-vertical-spacing: 0px; =
> -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
> auto; -webkit-text-stroke-width: 0px; "><div style=3D"word-wrap: =
> break-word; -webkit-nbsp-mode: space; -webkit-line-break: =
> after-white-space; "><span class=3D"Apple-style-span" =
> style=3D"border-collapse: separate; -webkit-border-horizontal-spacing: =
> 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); =
> font-family: Helvetica; font-size: 12px; font-style: normal; =
> font-variant: normal; font-weight: normal; letter-spacing: normal; =
> line-height: normal; -webkit-text-decorations-in-effect: none; =
> text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; =
> orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div =
> style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
> -webkit-line-break: after-white-space; "><span class=3D"Apple-style-span" =
> style=3D"border-collapse: separate; -webkit-border-horizontal-spacing: =
> 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); =
> font-family: Helvetica; font-size: 12px; font-style: normal; =
> font-variant: normal; font-weight: normal; letter-spacing: normal; =
> line-height: normal; -webkit-text-decorations-in-effect: none; =
> text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; =
> orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span =
> class=3D"Apple-style-span" style=3D"border-collapse: separate; =
> -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =
> 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =
> font-style: normal; font-variant: normal; font-weight: normal; =
> letter-spacing: normal; line-height: normal; =
> -webkit-text-decorations-in-effect: none; text-indent: 0px; =
> -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =
> white-space: normal; widows: 2; word-spacing: 0px; "><span =
> class=3D"Apple-style-span" style=3D"border-collapse: separate; =
> -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =
> 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =
> font-style: normal; font-variant: normal; font-weight: normal; =
> letter-spacing: normal; line-height: normal; =
> -webkit-text-decorations-in-effect: none; text-indent: 0px; =
> -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =
> white-space: normal; widows: 2; word-spacing: 0px; =
> "><div>~~~~~~~~~~~~~</div><div>Mark R. Diggory - DSpace Developer and =
> Systems Manager</div><div>MIT Libraries, Systems and Technology =
> Services</div><div>Massachusetts Institute of Technology</div><div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; ">Home Page:=A0<a =
> href=3D"http://purl.org/net/mdiggory/homepage";>http://purl.org/net/mdiggor=
> y/homepage</a></div></div><div><br =
> class=3D"khtml-block-placeholder"></div><br =
> class=3D"Apple-interchange-newline"></span></span></span></div></span></di=
> v></span><br class=3D"Apple-interchange-newline"></span><br =
> class=3D"Apple-interchange-newline"></span></span></span> =
> </div><br></body></html>=
>
> --Apple-Mail-3--696615416--
>
>
> --===============1565701006==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> --===============1565701006==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> _______________________________________________
> DSpace-tech mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/dspace-tech
>
> --===============1565701006==--
>


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech

Reply via email to