From: Niko P. <nik...@um...> - 2002-04-02 16:44:26
|
Hi Kal, Yes, this could be the reason for this strange behaviour. Indeed, the topicmaps I am parsing are quite small. After Your mail, I put some debug messages in XTMBuilder and the IDGeneratorImpl. I have attached the output when parsing one(!) topicmap. As one can see, there seem to be two IDGenerators active. What for ? Is one handling topics and the other associations? In fact, when parsing the TM after ID 8 was assigned, the second IDGenerator starts its work and sometimes, the id-prefix remains the same (because System.currentTimeMillis() returned the same value) -> crash! Anyways, I've solved the problem by using a static counter for creating the base-id instead of the current time (code attached). Ok - static variables are not really a clean way to solve problems in terms of OOP. But it's ok for me ;-) Thanks for the help, kind regards, Niko XTMBuilder constructor id: x1gg3aa0d0-0 id: x1gg3aa0d0-1 id: x1gg3aa0d0-2 id: x1gg3aa0d0-3 id: x1gg3aa0d0-4 id: x1gg3aa0d0-5 id: x1gg3aa0d0-6 id: x1gg3aa0d0-7 id: x1gg3aa0d0-8 id: x1gg3aa0g4-0 id: x1gg3aa0g4-1 id: x1gg3aa0g4-2 id: x1gg3aa0g4-3 id: x1gg3aa0g4-4 id: x1gg3aa0g4-5 id: x1gg3aa0d0-9 id: x1gg3aa0d0-a id: x1gg3aa0g4-6 id: x1gg3aa0d0-b id: x1gg3aa0d0-c id: x1gg3aa0d0-d id: x1gg3aa0d0-e id: x1gg3aa0d0-f id: x1gg3aa0g4-7 id: x1gg3aa0d0-10 id: x1gg3aa0d0-11 id: x1gg3aa0d0-12 id: x1gg3aa0d0-13 id: x1gg3aa0d0-14 id: x1gg3aa0g4-8 id: x1gg3aa0d0-15 id: x1gg3aa0d0-16 id: x1gg3aa0d0-17 id: x1gg3aa0d0-18 id: x1gg3aa0d0-19 id: x1gg3aa0g4-9 id: x1gg3aa0d0-1a id: x1gg3aa0d0-1b id: x1gg3aa0d0-1c id: x1gg3aa0d0-1d id: x1gg3aa0d0-1e id: x1gg3aa0g4-a id: x1gg3aa0d0-1f id: x1gg3aa0d0-20 id: x1gg3aa0d0-21 id: x1gg3aa0d0-22 id: x1gg3aa0d0-23 id: x1gg3aa0g4-b id: x1gg3aa0d0-24 id: x1gg3aa0d0-25 id: x1gg3aa0d0-26 id: x1gg3aa0d0-27 id: x1gg3aa0d0-28 id: x1gg3aa0g4-c id: x1gg3aa0d0-29 id: x1gg3aa0d0-2a id: x1gg3aa0d0-2b id: x1gg3aa0d0-2c id: x1gg3aa0d0-2d id: x1gg3aa0g4-d id: x1gg3aa0d0-2e id: x1gg3aa0d0-2f id: x1gg3aa0d0-30 id: x1gg3aa0d0-31 id: x1gg3aa0d0-32 id: x1gg3aa0g4-e id: x1gg3aa0d0-33 id: x1gg3aa0d0-34 id: x1gg3aa0d0-35 id: x1gg3aa0d0-36 id: x1gg3aa0d0-37 id: x1gg3aa0g4-f id: x1gg3aa0d0-38 id: x1gg3aa0d0-39 id: x1gg3aa0d0-3a id: x1gg3aa0d0-3b id: x1gg3aa0d0-3c id: x1gg3aa0g4-10 id: x1gg3aa0d0-3d id: x1gg3aa0d0-3e id: x1gg3aa0d0-3f id: x1gg3aa0d0-40 id: x1gg3aa0d0-41 id: x1gg3aa0g4-11 id: x1gg3aa0d0-42 id: x1gg3aa0d0-43 id: x1gg3aa0d0-44 id: x1gg3aa0d0-45 id: x1gg3aa0d0-46 id: x1gg3aa0g4-12 id: x1gg3aa0d0-47 id: x1gg3aa0d0-48 id: x1gg3aa0d0-49 id: x1gg3aa0d0-4a id: x1gg3aa0d0-4b id: x1gg3aa0g4-13 id: x1gg3aa0d0-4c id: x1gg3aa0d0-4d id: x1gg3aa0d0-4e id: x1gg3aa0d0-4f id: x1gg3aa0d0-50 id: x1gg3aa0g4-14 id: x1gg3aa0d0-51 id: x1gg3aa0d0-52 id: x1gg3aa0d0-53 id: x1gg3aa0d0-54 id: x1gg3aa0d0-55 id: x1gg3aa0g4-15 id: x1gg3aa0d0-56 id: x1gg3aa0d0-57 id: x1gg3aa0d0-58 id: x1gg3aa0d0-59 id: x1gg3aa0d0-5a id: x1gg3aa0g4-16 id: x1gg3aa0d0-5b id: x1gg3aa0d0-5c id: x1gg3aa0d0-5d id: x1gg3aa0d0-5e id: x1gg3aa0d0-5f id: x1gg3aa0g4-17 id: x1gg3aa0d0-60 id: x1gg3aa0d0-61 id: x1gg3aa0d0-62 id: x1gg3aa0d0-63 id: x1gg3aa0d0-64 id: x1gg3aa0g4-18 id: x1gg3aa0d0-65 id: x1gg3aa0d0-66 id: x1gg3aa0d0-67 id: x1gg3aa0d0-68 id: x1gg3aa0d0-69 id: x1gg3aa0g4-19 id: x1gg3aa0d0-6a id: x1gg3aa0d0-6b id: x1gg3aa0d0-6c id: x1gg3aa0d0-6d id: x1gg3aa0d0-6e id: x1gg3aa0g4-1a id: x1gg3aa0d0-6f id: x1gg3aa0d0-70 id: x1gg3aa0d0-71 id: x1gg3aa0d0-72 id: x1gg3aa0d0-73 id: x1gg3aa0g4-1b id: x1gg3aa0d0-74 id: x1gg3aa0d0-75 id: x1gg3aa0d0-76 id: x1gg3aa0d0-77 id: x1gg3aa0d0-78 id: x1gg3aa0g4-1c id: x1gg3aa0d0-79 id: x1gg3aa0d0-7a id: x1gg3aa0d0-7b id: x1gg3aa0d0-7c ------------------------------------------------------------------------------------- /* * The TM4J Software License * * * Copyright (c) 2000, 2001, 2002 The TM4J Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by * The TM4J Project (http://sourceforge.net/projects/tm4j) * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "TM4J" and "The TM4J Project" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ka...@te.... * * 5. Products derived from this software may not be called "TM4J", * nor may "TM4J" appear in their name, without prior written * permission of the TM4J Project. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE TM4J PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * */ // $Id: IDGeneratorImpl.java,v 1.4 2002/02/09 19:38:23 kal_ahmed Exp $ package org.tm4j.topicmap.utils; /** * An alternative IDGenerator implementation. * This implementation returns a two-part, pseudo-unique ID. The first part of * the ID is the number of the created IDGenerator by this JVM,. * The second part of the ID is a simple incrementing * counter. * This class does not generate truely unique IDs, but the degree of uniqueness * should be sufficient for most applications. */ public class AlternativeIDGeneratorImpl implements IDGenerator { protected String baseID; protected long counter; private static long genCounter = (long) 0; /** * Constructs a new IDGeneratorImpl object, with the * base part of the ID string set to the time of creation. */ public AlternativeIDGeneratorImpl() { baseID = "x" + ( genCounter++ ); } /** * Returns a pseudo-unique identifier as a concatenation of * the base identifier created in the object constructor * followed by a dash (-) and then a simple, incrementing * counter value (encoded in hexadecimal). */ public String getID() { String id = baseID + "-" + Long.toString(counter++, 16); return id; } } Kal Ahmed wrote: > Hi Niko, > > This seems a bit weird - the autogenerated IDs are created by an > IDGenerator which is constructed by the XTMBuilder class when it is > created. The default implementation of IDGenerator uses > System.currentTimeMillis() to generate the base ID string in its > constructor and then uses an incrementing counter as a suffix to generate > individual ids (so you get "x<time at creation of IDGenerator>-<count>" as > the id string). I was pretty sure that this should not cause a problem for > most applications. If this algorithm is working as expected, I would expect > that it would only be possible that you would see a duplicate ID being > generated if the first topic map is small enough to be processed and loaded > in the resolution of the system clock (usually currentTimeMillis() does not > update every millisecond). > > One way to test if this is the case would be to insert a sleep() into the > constructor for IDGeneratorImpl - If it was something like 300 to 700 ms, > that **should** force a new value. Alternatively you could change the > constructor to get an initial value and then to loop until it gets a new > value different to the initial value - that should guarantee that two > different IDGeneratorImpls created by the same thread will *always* have a > unique base id. > > If you try one of these approaches and have some success perhaps you could > post it back to me as a patch ? > > BTW, the IDGenerator implementation used is runtime configurable - use the > system property org.tm4j.topicmap.idGenerator to define the name of the > class to be loaded as the IDGenerator for topic map parsing - this class > must implement org.tm4j.topicmap.utils.IDGenerator. > > Cheers, > > Kal > > At 15:31 02/04/2002 +0200, Niko Popitsch wrote: > >Hi, > > > >I discovered a strange behaviour of tm4j 0.6.1 with loading topic maps. > >I load multiple TMs from disk. the first load is ok. but then successive > >loads throw DuplicateObjectIDExceptions !sometimes!. This really seems > >to be abitrary behaviour. > >I always create a new Saxparser, > > saxParser = new SAXParser(); > >a new TM Factory, > > TopicMapFactoryImpl tmfi = new TopicMapFactoryImpl(); > >a new Topic map, > > TopicMap tm = tmfi.createTopicMap( baseLocator ); > >a new XTM Builder > > XTMBuilder xtmBuilder = new XTMBuilder( tm ); > >a new XTM Parser > > XTMParser xtmParser = new XTMParser( xtmBuilder ); > >and then i parse: > > saxParser.setContentHandler( xtmParser ); > > saxParser.parse( src ); > > > >what could this be ??? > >thanks, > >Niko :) > > > > > >_______________________________________________ > >Tm4j-users mailing list > >Tm4...@li... > >https://lists.sourceforge.net/lists/listinfo/tm4j-users |