FileDocCategorySizeDatePackage
MessageAcceptor.javaAPI DocGlassfish v2 API7205Fri May 04 22:30:26 BST 2007com.sun.enterprise.jbi.serviceengine.comm

MessageAcceptor

public class MessageAcceptor extends com.sun.enterprise.jbi.serviceengine.work.OneWork
Acceptor object that continuously receives messages from NMR. There is one MessageAcceptor object per WorkManager. MessageAcceptor also keeps a house keeping datastructure that holds information about all threads that are waiting for reply from on NMR for their two-way message exchange.
authod
Binod PG

Fields Summary
private HashMap
receivers
private boolean
released
Constructors Summary
Methods Summary
public voiddoWork()
Actual work happens in this method. DeliveryChannel available from the super class. If there is any MessageReceiver waiting for this message, then the MessageExchange is made avalable to that MessageReceiver. If no MessageReceiver is interested in this MEP, then a new MessageProcessor will process this message. In the latter case, the message is for a 109 webservice deployed in appserver.

        while (true) {
            try {
                
                MessageExchange me = getDeliveryChannel().accept();
                if (released) {
                    break;
                }
                
                if(me != null) {
                    
                    if(ignoreMessageExchange(me)) {
                        continue;
                    }
                    
                    String id = me.getExchangeId();
                    
                    // The full block is not synchronized since,
                    // 1. Id will always be unique
                    // 2. Service engine will register the receiver
                    //    before sending and hence we wont miss any.
                    if (receivers.containsKey(id)) {
                        synchronized(receivers) {
                            MessageReceiver receiver = receivers.remove(id);
                            receiver.setMessageExchange(me);
                            if (logger.isLoggable(Level.FINE)) {
                                logger.log(Level.FINE,
                                        "Releasing MessageReceiver:" + id + ",MEP :" + me);
                            }
                            receiver.release();
                        }
                    } else {
                        MessageProcessor processor =
                                JavaEEServiceEngineContext.getInstance().
                                getBridge().getMessageProcessor(me);
                        processor.setUseCurrentThread(false);
                        processor.setMessageExchange(me);
                        if (logger.isLoggable(Level.FINE)) {
                            logger.log(Level.FINE,
                                    "Spawning MessageProcessorfor MEP :" + me);
                        }
                        processor.process();
                    }
                }
            } catch (MessagingException ie) {
                //Someone has interrupted the acceptor. Gracefully comeout.
                logger.log(Level.FINE, "Stopping the acceptor thread");
                break;
            }
        }
    
private booleanignoreMessageExchange(javax.jbi.messaging.MessageExchange me)

        
        if(me.getRole().equals(MessageExchange.Role.PROVIDER)) {
            
            if(me.getStatus().equals(ExchangeStatus.ACTIVE)) {
                return false;
            }
            
            if(me.getStatus().equals(ExchangeStatus.DONE)) {
                if(logger.isLoggable(Level.FINE)) {
                    logger.fine("Message Exchange Completed " + me);
                }
                return true;
            }
            
            if(me.getStatus().equals(ExchangeStatus.ERROR)) {
                logger.warning("JavaEE Service Engine received unsupported Message Exchange " + me);
                return true;
            }
        }
        
        return false;
    
public voidregister(MessageReceiver receiver)
Add a MessageReceiver object that waits for a reply from from NMR on their 2-way message exchange.

param
receiver MessageReceiver instance.

        String id = receiver.getMessageExchange().getExchangeId();
        logger.log(Level.FINER, "Adding recever for " + id);
        synchronized (receivers) {
            receivers.put(id, receiver);
        }
    
public voidrelease()
Release the thread from accepting. This method doesnt interrupt the thread. It is just a soft release applicable only from the next iteration of acceptor thread.

        released = true;
    
public voidstartAccepting()
Start the acceptor thread. Note that execute() inturn call doWork method, where bulk of logic is present.

    
                          
       
        execute();