[Design of JBossXB] - Re: SundayContentHandler: Don't add collections into collect
by adrian@jboss.org
It might also have been related to my attempt to implement
holders using a custom particle handler (I can't remember?)
but the code was below.
This basically replaced the original parent and reverted the
object at the end. It didn't do anything with the setParent()
though obviously it would use the replaced parent.
| /*
| * JBoss, Home of Professional Open Source
| * Copyright 2006, JBoss Inc., and individual contributors as indicated
| * by the @authors tag. See the copyright.txt in the distribution for a
| * full listing of individual contributors.
| *
| * This is free software; you can redistribute it and/or modify it
| * under the terms of the GNU Lesser General Public License as
| * published by the Free Software Foundation; either version 2.1 of
| * the License, or (at your option) any later version.
| *
| * This software is distributed in the hope that it will be useful,
| * but WITHOUT ANY WARRANTY; without even the implied warranty of
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
| * Lesser General Public License for more details.
| *
| * You should have received a copy of the GNU Lesser General Public
| * License along with this software; if not, write to the Free
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
| */
| package org.jboss.xb.binding.builder.runtime;
|
| import java.lang.reflect.InvocationTargetException;
| import java.util.HashMap;
| import java.util.Map;
|
| import javax.xml.namespace.NamespaceContext;
| import javax.xml.namespace.QName;
|
| import org.jboss.util.Strings;
| import org.jboss.util.collection.WeakIdentityHashMap;
| import org.jboss.xb.binding.builder.properties.Property;
| import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
| import org.jboss.xb.binding.sunday.unmarshalling.ParticleHandler;
| import org.jboss.xb.binding.sunday.unmarshalling.impl.runtime.RtElementHandler;
| import org.xml.sax.Attributes;
|
| /**
| * HolderParticleHandler.
| *
| * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
| * @version $Revision: 1.1 $
| */
| public class HolderParticleHandler implements ParticleHandler
| {
| /** The delegate */
| private ParticleHandler delegate = RtElementHandler.INSTANCE;
|
| /** The holders */
| private Map<QName, Property> holders = new HashMap<QName, Property>();
|
| /** Interposed objects TODO This is a hack! */
| private ThreadLocal<WeakIdentityHashMap> interposed = new ThreadLocal<WeakIdentityHashMap>();
|
| /**
| * Add a holder
| *
| * @param qName the qualified name to hold
| * @param property the property
| * @throws IllegalArgumentException for a null qName, property, or the property has no read method
| */
| public void addHolder(QName qName, Property property)
| {
| if (qName == null)
| throw new IllegalArgumentException("Null qName");
| if (property == null)
| throw new IllegalArgumentException("Null property");
| if (property.getRead() == null)
| throw new IllegalArgumentException("Property has no getter " + property);
| holders.put(qName, property);
| }
|
| public Object startParticle(Object parent, QName elementName, ParticleBinding particle, Attributes attrs, NamespaceContext nsCtx)
| {
| Object result = delegate.startParticle(parent, elementName, particle, attrs, nsCtx);
| Object original = result;
| if (result != null)
| {
| Property property = holders.get(elementName);
| if (property != null)
| {
| try
| {
| result = property.getRead().invoke(original, null);
| }
| catch (InvocationTargetException e)
| {
| throw new RuntimeException("Error retrieving holder " + property.getRead().getName() + " for " + Strings.defaultToString(original), e.getCause());
| }
| catch (Exception e)
| {
| throw new RuntimeException("Error retrieving holder " + property.getRead().getName() + " for " + Strings.defaultToString(original), e);
| }
| if (result == null)
| {
| if (property.getWrite() == null)
| throw new IllegalStateException("Unable to retrieve holder " + property.getRead().getName() + " for " + Strings.defaultToString(original) + " and the there is not setter method.");
| try
| {
| result = property.getPropertyImpl().newInstance();
| }
| catch (Exception e)
| {
| throw new RuntimeException("Error instantiating new holder " + property.getPropertyImpl().getName(), e);
| }
| }
| Object[] arguments = { result };
| try
| {
| property.getWrite().invoke(original, arguments);
| }
| catch (InvocationTargetException e)
| {
| throw new RuntimeException("Error setting holder " + property.getWrite().getName() + " for " + Strings.defaultToString(original) + " with " + Strings.defaultToString(result), e.getCause());
| }
| catch (Exception e)
| {
| throw new RuntimeException("Error setting holder " + property.getWrite().getName() + " for " + Strings.defaultToString(original) + " with " + Strings.defaultToString(result), e);
| }
|
| if (result != original)
| {
| WeakIdentityHashMap map = interposed.get();
| if (map == null)
| {
| map = new WeakIdentityHashMap();
| interposed.set(map);
| }
| map.put(result, original);
| }
| }
| }
| return result;
| }
|
| public Object endParticle(Object o, QName elementName, ParticleBinding particle)
| {
| WeakIdentityHashMap map = interposed.get();
| if (map != null)
| {
| Object object = map.remove(o);
| if (object != null)
| o = object;
| }
| return delegate.endParticle(o, elementName, particle);
| }
|
| public void setParent(Object parent, Object o, QName elementName, ParticleBinding particle, ParticleBinding parentParticle)
| {
| delegate.setParent(parent, o, elementName, particle, parentParticle);
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977261#3977261
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977261
19 years, 6 months
[Design of Messaging on JBoss (Messaging/JBoss)] - Re: Once and only once delivery?
by timfox
"adrian(a)jboss.org" wrote : I don't understand what you are trying to do?
|
| To solve the original problem, you create a transacted session.
|
A local jms transaction doesn't work for the reasons I mentioned earlier in the thread, and which you mention here:
anonymous wrote :
|
| It is certainly true that for a local tx, you always have the problem
| of the "transaction observer".
|
| 1) create transacted session
| 2) send 10 messages in the session
| 3) commit the session
|
| The problem being that (3) can work on the server but the network
| connection fails just at this point, so the client gets a JMSException
| rather than the commited ok message.
|
anonymous wrote :
| Tracking messages ids isn't going to work, unless you
| are prepared to hold all messages that were ever sent.
|
This is why I suggested having an expiry on them, so you only keep the ids for a maximum period of time.
Obviously this means that you can send duplicates of messages that were sent before that time, but as you point out this solution won't work 100% of the time unless you have an infinite amount of storage.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977253#3977253
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977253
19 years, 6 months
[Design of Messaging on JBoss (Messaging/JBoss)] - Re: Once and only once delivery?
by adrian@jboss.org
I don't understand what you are trying to do?
To solve the original problem, you create a transacted session.
It is certainly true that for a local tx, you always have the problem
of the "transaction observer".
1) create transacted session
2) send 10 messages in the session
3) commit the session
The problem being that (3) can work on the server but the network
connection fails just at this point, so the client gets a JMSException
rather than the commited ok message.
Using 2PC certainly solves the problem, because you can prepare()
and once you get the ok from that, you are done.
If the commit fails (network connection),
you can always retry it later using recover().
Tracking messages ids isn't going to work, unless you
are prepared to hold all messages that were ever sent.
1) Client send 10 messages with some identitier on them
(commit seems to fail because of network connection).
2) Server deliver 10 messages to receiver which are then
ACK and removed from the store.
3) Client resend 10 messages with the same identiter
4) Server happily resends them because it no longer has
the original 10 in its store.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3977249#3977249
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3977249
19 years, 6 months