jmsnell 2002/10/28 22:15:08 Modified: java/src/org/apache/axis/ime MessageContextListener.java java/src/org/apache/axis/ime/internal MessageExchangeImpl.java NonPersistentMessageExchangeCorrelatorService.java Added: java/src/org/apache/axis/ime/internal/util/handler HandlerMessageExchange.java MessageExchangeHandler.java java/src/org/apache/axis/ime/internal MessageExchangeCorrelatorService.java Removed: java/src/org/apache/axis/ime MessageExchangeCorrelatorService.java java/src/org/apache/axis/ime/internal/util/handler HandlerWrapper.java Log: A few additional changes. Most significantly, a simple handler that wraps a MessageExchange.sendAndReceive operation Revision Changes Path 1.2 +0 -8 xml-axis/java/src/org/apache/axis/ime/MessageContextListener.java Index: MessageContextListener.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/ime/MessageContextListener.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MessageContextListener.java 29 Oct 2002 05:15:29 -0000 1.1 +++ MessageContextListener.java 29 Oct 2002 06:15:08 -0000 1.2 @@ -63,16 +63,8 @@ public abstract class MessageContextListener implements Serializable { - public void onFault( - MessageExchangeCorrelator correlator, - Throwable exception) {} - public void onReceive( MessageExchangeCorrelator correlator, MessageContext context) {} - - public void onStatus( - MessageExchangeCorrelator correlator, - MessageExchangeStatus status) {} } 1.1 xml-axis/java/src/org/apache/axis/ime/internal/util/handler/HandlerMessageExchange.java Index: HandlerMessageExchange.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. 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 * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * 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 APACHE SOFTWARE FOUNDATION 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. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.axis.ime.internal.util.handler; import org.apache.axis.Handler; import org.apache.axis.MessageContext; import org.apache.axis.ime.MessageExchangeCorrelator; import org.apache.axis.ime.MessageContextListener; import org.apache.axis.ime.MessageExchangeFaultListener; import org.apache.axis.ime.internal.MessageExchangeProvider; import org.apache.axis.ime.internal.MessageExchangeSendContext; import org.apache.axis.ime.internal.MessageExchangeSendListener; import org.apache.axis.ime.internal.ReceivedMessageDispatchPolicy; import org.apache.axis.ime.internal.FirstComeFirstServeDispatchPolicy; /** * Used to wrap synchronous handlers (e.g. Axis 1.0 transports) * * @author James M Snell ([EMAIL PROTECTED]) */ public class HandlerMessageExchange extends MessageExchangeProvider { private Handler handler; public HandlerMessageExchange(Handler handler) { this.handler = handler; } /** * @see org.apache.axis.ime.internal.MessageExchangeProvider1#createSendMessageContextListener() */ protected MessageExchangeSendListener getMessageExchangeSendListener() { return new Listener(handler); } protected ReceivedMessageDispatchPolicy getReceivedMessageDispatchPolicy() { return new FirstComeFirstServeDispatchPolicy(RECEIVE, RECEIVE_REQUESTS); } public class Listener implements MessageExchangeSendListener { private Handler handler; public Listener(Handler handler) { this.handler = handler; } /** * @see org.apache.axis.ime.MessageExchangeContextListener#onMessageExchangeContext(MessageExchangeContext) */ public void onSend( MessageExchangeSendContext context) { MessageExchangeFaultListener listener = context.getMessageExchangeFaultListener(); try { MessageContext msgContext = context.getMessageContext(); MessageExchangeCorrelator correlator = context.getMessageExchangeCorrelator(); // should I do init's and cleanup's in here? handler.invoke(msgContext); RECEIVE.put(correlator, context); } catch (Exception exception) { if (listener != null) listener.onFault( context.getMessageExchangeCorrelator(), exception); } } } } 1.1 xml-axis/java/src/org/apache/axis/ime/internal/util/handler/MessageExchangeHandler.java Index: MessageExchangeHandler.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. 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 * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * 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 APACHE SOFTWARE FOUNDATION 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. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.axis.ime.internal.util.handler; import org.apache.axis.AxisFault; import org.apache.axis.MessageContext; import org.apache.axis.ime.MessageExchange; import org.apache.axis.handlers.BasicHandler; /** * This could probably be a bit more sophisticated, * but it works for now * * @author James M Snell ([EMAIL PROTECTED]) */ public class MessageExchangeHandler extends BasicHandler { private MessageExchange messageExchange; public MessageExchangeHandler() {} public MessageExchangeHandler(MessageExchange exchange) { this.messageExchange = exchange; } public void invoke( MessageContext msgContext) throws AxisFault { msgContext = messageExchange.sendAndReceive(msgContext); } public MessageExchange getMessageExchange() { return this.messageExchange; } public void setMessageExchange(MessageExchange exchange) { this.messageExchange = exchange; } } 1.4 +43 -28 xml-axis/java/src/org/apache/axis/ime/internal/MessageExchangeImpl.java Index: MessageExchangeImpl.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/ime/internal/MessageExchangeImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MessageExchangeImpl.java 29 Oct 2002 05:15:29 -0000 1.3 +++ MessageExchangeImpl.java 29 Oct 2002 06:15:08 -0000 1.4 @@ -63,7 +63,6 @@ import org.apache.axis.ime.MessageExchangeFaultListener; import org.apache.axis.ime.MessageExchangeStatusListener; import org.apache.axis.ime.MessageExchangeCorrelator; -import org.apache.axis.ime.MessageExchangeCorrelatorService; import org.apache.axis.ime.MessageContextListener; import org.apache.axis.ime.MessageExchangeLifecycle; import org.apache.axis.ime.internal.util.uuid.UUIDGenFactory; @@ -74,15 +73,12 @@ public class MessageExchangeImpl implements MessageExchange, MessageExchangeLifecycle { - private static final long NO_TIMEOUT = -1; - public static final long WORKER_COUNT = 5; - public static final long DEFAULT_TIMEOUT = 1000 * 20; + public static final long NO_TIMEOUT = -1; + public static final long DEFAULT_TIMEOUT = 1000 * 30; - private MessageWorkerGroup workers = new MessageWorkerGroup(); private MessageExchangeFaultListener faultListener; private MessageExchangeStatusListener statusListener; private MessageExchangeProvider provider; - private boolean listening = false; protected Holder holder; public MessageExchangeImpl( @@ -95,7 +91,7 @@ public MessageExchangeCorrelator send( MessageContext context) throws AxisFault { - return send(context,null); // should do default listener + return send(context,null); } /** @@ -167,6 +163,7 @@ throws AxisFault { holder = new Holder(); Listener listener = new Listener(holder); + setMessageExchangeFaultListener(listener); try { this.receive(correlator,listener); if (timeout != NO_TIMEOUT) @@ -227,6 +224,7 @@ throws AxisFault { holder = new Holder(); Listener listener = new Listener(holder); + setMessageExchangeFaultListener(listener); try { this.send(context,listener); if (timeout != NO_TIMEOUT) @@ -245,6 +243,36 @@ return null; } + /** + * see org.apache.axis.ime.MessageExchange#setMessageExchangeFaultListener(MessageExchangeFaultListener) + */ + public synchronized void setMessageExchangeFaultListener( + MessageExchangeFaultListener listener) { + this.faultListener = listener; + } + + /** + * see org.apache.axis.ime.MessageExchange#getMessageExchangeFaultListener() + */ + public synchronized MessageExchangeFaultListener getMessageExchangeFaultListener() { + return this.faultListener; + } + + /** + * see org.apache.axis.ime.MessageExchange#setMessageExchangeStatusListener(MessageExchangeStatusListener) + */ + public synchronized void setMessageExchangeStatusListener( + MessageExchangeStatusListener listener) { + this.statusListener = listener; + } + + /** + * see org.apache.axis.ime.MessageExchange#getMessageExchangeStatusListener() + */ + public synchronized MessageExchangeStatusListener getMessageExchangeStatusListener() { + return this.statusListener; + } + // -- Utility Classes --- // @@ -252,12 +280,14 @@ private MessageExchangeCorrelator correlator; private MessageContext context; private Throwable exception; + private boolean done = false; public synchronized void set( MessageExchangeCorrelator correlator, MessageContext context) { this.correlator = correlator; this.context = context; + done = true; notifyAll(); } @@ -266,25 +296,27 @@ Throwable throwable) { this.correlator = correlator; this.exception = throwable; + done = true; notifyAll(); } public synchronized void waitForNotify() throws InterruptedException { - wait(); + if (!done) wait(); return; } public synchronized void waitForNotify(long timeout) throws InterruptedException { - wait(timeout); + if (!done) wait(timeout); return; } } - public class Listener - extends MessageContextListener { + public class Listener + extends MessageContextListener + implements MessageExchangeFaultListener { protected Holder holder; @@ -353,21 +385,4 @@ provider.shutdown(force); } - public synchronized void setMessageExchangeFaultListener( - MessageExchangeFaultListener listener) { - this.faultListener = listener; - } - - public synchronized MessageExchangeFaultListener getMessageExchangeFaultListener() { - return this.faultListener; - } - - public synchronized void setMessageExchangeStatusListener( - MessageExchangeStatusListener listener) { - this.statusListener = listener; - } - - public synchronized MessageExchangeStatusListener getMessageExchangeStatusListener() { - return this.statusListener; - } } 1.4 +0 -1 xml-axis/java/src/org/apache/axis/ime/internal/NonPersistentMessageExchangeCorrelatorService.java Index: NonPersistentMessageExchangeCorrelatorService.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/ime/internal/NonPersistentMessageExchangeCorrelatorService.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- NonPersistentMessageExchangeCorrelatorService.java 29 Oct 2002 05:15:29 -0000 1.3 +++ NonPersistentMessageExchangeCorrelatorService.java 29 Oct 2002 06:15:08 -0000 1.4 @@ -56,7 +56,6 @@ package org.apache.axis.ime.internal; import org.apache.axis.ime.MessageExchangeCorrelator; -import org.apache.axis.ime.MessageExchangeCorrelatorService; import java.util.Hashtable; 1.1 xml-axis/java/src/org/apache/axis/ime/internal/MessageExchangeCorrelatorService.java Index: MessageExchangeCorrelatorService.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001 The Apache Software Foundation. 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 * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * 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 APACHE SOFTWARE FOUNDATION 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. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.axis.ime.internal; import org.apache.axis.ime.MessageExchangeCorrelator; /** * @author James M Snell ([EMAIL PROTECTED]) */ public interface MessageExchangeCorrelatorService { public void put( MessageExchangeCorrelator correlator, Object context); public Object get( MessageExchangeCorrelator correlator); }