Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: DefaultMuleConnection.java 19640 2010-09-13 22:00:05Z tcarlson $
   * --------------------------------------------------------------------------------------
   * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
 
 package org.mule.module.jca;
 
 
 import java.util.Map;
 
 import  javax.resource.ResourceException;

MuleConnection TODO
 
 public class DefaultMuleConnection implements MuleConnection
 {
     private final MuleCredentials credentials;
     private final MuleContext muleContext;
 
     public DefaultMuleConnection(MuleManagedConnection managedConnection,
                                  MuleContext muleContext,
                                  MuleCredentials credentials)
     {
         this. = muleContext;
         this. = credentials;
         this. = managedConnection;
     }

    
Dispatches an event asynchronously to a endpointUri via a mule server. the Url determines where to dispathc the event to, this can be in the form of

Parameters:
url the Mule url used to determine the destination and transport of the message
payload the object that is the payload of the event
messageProperties any properties to be associated with the payload. In the case of Jms you could set the JMSReplyTo property in these properties.
Throws:
org.mule.api.MuleException
 
     public void dispatch(String urlObject payloadMap messagePropertiesthrows MuleException
     {
         MuleMessage message = new DefaultMuleMessage(payloadmessageProperties);
         MuleEvent event = getEvent(message,endpoint);
         try
         {
             endpoint.process(event);
         }
         catch (MuleException e)
         {
             throw e;
         }
         catch (Exception e)
         {
             throw new DispatchException(ClientMessages.failedToDispatchClientEvent(), event
                 endpointe);
         }
     }

    
Sends an object (payload) synchronous to the given url and returns a MuleMessage response back.

Parameters:
url the Mule url used to determine the destination and transport of the message
payload the object that is the payload of the event
messageProperties any properties to be associated with the payload. In the case of Jms you could set the JMSReplyTo property in these properties.
Returns:
a response.
Throws:
org.mule.api.MuleException
 
    public MuleMessage send(String urlObject payloadMap messagePropertiesthrows MuleException
    {
        MuleMessage message = new DefaultMuleMessage(payloadmessageProperties);
        MuleEvent event = getEvent(messageendpoint);
        try
        {
            MuleEvent resultEvent = endpoint.process(event);
            if (resultEvent != null)
            {
                return resultEvent.getMessage();
            }
            else
            {
                return null;
            }
        }
        catch (MuleException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw new DispatchException(ClientMessages.failedToDispatchClientEvent(), event
                endpointe);
        }
    }

    
Will receive an event from an endpointUri determined by the url

Parameters:
url the Mule url used to determine the destination and transport of the message
timeout how long to block waiting to receive the event, if set to 0 the receive will not wait at all and if set to -1 the receive will wait forever
Returns:
the message received or null if no message was received
Throws:
org.mule.api.MuleException
    public MuleMessage request(String urllong timeoutthrows MuleException
    {
        try
        {
            return endpoint.request(timeout);
        }
        catch (Exception e)
        {
            throw new ReceiveException(endpointtimeoute);
        }
    }
    
    protected OutboundEndpoint getOutboundEndpoint(String uriMessageExchangePattern exchangePattern
        throws MuleException
    {
        EndpointBuilder endpointBuilder = .getRegistry()
            .lookupEndpointFactory()
            .getEndpointBuilder(uri);
        endpointBuilder.setExchangePattern(exchangePattern);
        return .getRegistry().lookupEndpointFactory().getOutboundEndpoint(endpointBuilder);
    }

    
Packages a mule event for the current request

Parameters:
message the event payload
uri the destination endpointUri
synchronous whether the event will be synchronously processed
Returns:
the MuleEvent
Throws:
MuleException in case of Mule error
    protected MuleEvent getEvent(MuleMessage messageOutboundEndpoint endpoint)
        throws MuleException
    {
        MuleSession session = new DefaultMuleSession(message, ((AbstractConnector)endpoint.getConnector()).getSessionHandler(), );
        if ( != null)
        {
            message.setOutboundProperty(."Plain " + .getToken());
        }
        return new DefaultMuleEvent(messageendpointsession);
    }

    
Retrieves a ManagedConnection.

Returns:
a ManagedConnection instance representing the physical connection to the EIS
    {
        return ;
    }

    
Closes the connection.
    public void close() throws ResourceException
    {
        if ( == null)
        {
            return// connection is already closed
        }
        .removeConnection(this);
        // Send a close event to the App Server
        .fireCloseEvent(this);
         = null;
    }

    
Associates connection handle with new managed connection.

Parameters:
newMc new managed connection
    public void associateConnection(MuleManagedConnection newMcthrows ResourceException
    {
        checkIfValid();
        // dissociate handle from current managed connection
        .removeConnection(this);
        // associate handle with new managed connection
        newMc.addConnection(this);
         = newMc;
    }

    
Checks the validity of the physical connection to the EIS.

Throws:
javax.resource.ResourceException in case of any error
    void checkIfValid() throws ResourceException
    {
        if ( == null)
        {
            throw new ResourceException(
                JcaMessages.objectMarkedInvalid("muleManagedConnection").toString());
        }
    }

    
Sets the physical connection to the EIS as invalid. The physical connection to the EIS cannot be used any more.
    void invalidate()
    {
         = null;
    }
New to GrepCode? Check out our FAQ X