/* (non-Javadoc)
@see net.timewalker.ffmq4.cluster.resolver.DestinationResolver#getDestination(net.timewalker.ffmq4.management.peer.PeerDescriptor, net.timewalker.ffmq4.management.destination.DestinationReferenceDescriptor, javax.jms.Session)
436869
@Override
	public Destination getDestination(PeerDescriptor peer, DestinationReferenceDescriptor destinationReference,Session session) throws JMSException
	{
		String destinationType = destinationReference.getDestinationType();
		String destinationName = destinationReference.getDestinationName();
		
		if (destinationType.equalsIgnoreCase("queue"))
		{
			return session.createQueue(destinationName);
		}
		else
		if (destinationType.equalsIgnoreCase("topic"))
		{
			return session.createTopic(destinationName);
		}
		else
			throw new IllegalArgumentException("Invalid destination type : "+destinationType);
	}
703313
private Destination resolveDestinationName(String name, Session session) throws JMSException {
        if (endpointConfiguration.getDestinationResolver() != null) {
            return endpointConfiguration.getDestinationResolver().resolveDestinationName(session, name, endpointConfiguration.isPubSubDomain());
        }

        return new DynamicDestinationResolver().resolveDestinationName(session, name, endpointConfiguration.isPubSubDomain());
    }
644418
public SIDestinationAddress getDestinationAddress() {

        final String methodName = "getDestinationAddress";
        if (TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName);
        }

        final SIDestinationAddress address = _delegateSession
                .getDestinationAddress();

        if (TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName, _parentConnection);
        }
        return address;

    }
369978
private DestinationHandler createForeignDestination(DestinationForeignDefinition dfd, String busName) throws SIResourceException, SINotPossibleInCurrentConfigurationException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "createForeignDestination", new Object[] { dfd, busName });

        ForeignDestinationHandler fdh = null;

        //The lock on the destinationManager is taken to stop 2 threads creating the same
        //destination and also to synchronize dynamic deletes with the
        //creation of aliases.  This stops an alias destination being created that targets a
        //destination in the process of being deleted.
        synchronized (this)
        {
            // Create a new DestinationHandler, which is created locked
            fdh = new ForeignDestinationHandler(dfd, messageProcessor, this, findBus(dfd.getBus()), busName);

            DestinationIndex.Type type = new DestinationIndex.Type();
            type.foreignDestination = Boolean.TRUE;
            type.alias = Boolean.FALSE;
            type.local = Boolean.FALSE;
            type.remote = Boolean.FALSE;
            type.queue = new Boolean(!fdh.isPubSub());
            type.state = State.ACTIVE;
            destinationIndex.put(fdh, type);

            fdh.registerControlAdapters();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "createForeignDestination", fdh);

        return fdh;
    }
1031413
private String getDestinationName(Endpoint endpoint) {
        int start = endpoint.getName().lastIndexOf('/') + 1;
        return endpoint.getName().substring(start);
    }
320383
public void createDestinationLocalization(
    DestinationDefinition destinationDefinition,
    LocalizationDefinition destinationLocalizationDefinition) 
    
    throws SIBExceptionDestinationNotFound, SIBExceptionBase, SIResourceException, SIMPDestinationAlreadyExistsException, SINotPossibleInCurrentConfigurationException                                         
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "createDestinationLocalization", 
        new Object[] {destinationDefinition, 
                      destinationLocalizationDefinition});
  
    checkStarted();
    
    // Get locality set from admin of all MEs which host the queue point.
    // Venu mock mock
    // messageProcessor.getSIBDestinationLocalitySet now returns messageprocessor LocalitySet as
       /*
    Set destinationLocalizingSet = 
      messageProcessor.getSIBDestinationLocalitySet(
        null, destinationDefinition.getUUID().toString(), true); */

    Set destinationLocalizingSet = 
        messageProcessor.getSIBDestinationLocalitySet(
          null,null, true);
      
    
  
      
    destinationManager.createDestinationLocalization(destinationDefinition,
                                                     destinationLocalizationDefinition,                                                     
                                                     destinationLocalizingSet,                                                     
                                                     false);
  
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "createDestinationLocalization");
                                                          
    return;                                                     
  }
1257881
public void createDestination(Destination dest, Reliability defaultReliability) 
    throws JMSException
  {

    try
    {
    
      if (tcInt.isEntryEnabled())
        SibTr.entry(tcInt, "createDestination(Destination)");    
         
      com.ibm.wsspi.sib.core.DestinationType destType = null;
      String name = null;
  
      try
      {
  
        // Work out which type of Destination we want to create.
        if (dest instanceof JmsQueue)
        {
          destType = com.ibm.wsspi.sib.core.DestinationType.QUEUE;
          name = ((JmsQueue) dest).getQueueName();
  
        } else if (dest instanceof JmsTopic)
        {
          destType = com.ibm.wsspi.sib.core.DestinationType.TOPICSPACE;
          name = ((JmsTopic) dest).getTopicSpace();
        } else
        {
          destType = null;
          name = null;
        }
        
        if (tcInt.isDebugEnabled())
        {
          SibTr.debug(tcInt, "    name: "+name);
          SibTr.debug(tcInt, "destType: "+destType);
        }
          
  
        if (destType != null)
        {
          // Defer to the other method.
          createDestination(name, destType, defaultReliability);
        } else
        {
          throw new JMSException("Could not create Destination - destType was null");
        }
  
      } catch (JMSException e)
      {
        // No FFDC code needed
        if (tcInt.isDebugEnabled())
          SibTr.debug(tcInt, "JMSException during createDestination", e);
          
        throw e;
  
      } catch (Exception f)
      {
        // No FFDC code needed
        if (tcInt.isDebugEnabled())
          SibTr.debug(tcInt, "Exception during createDestionation", f);
          
        JMSException jmse = new JMSException("Exception from createDestination");
        jmse.setLinkedException(f);
        jmse.initCause(f);
        throw jmse;
  
      } //try

    } finally
    {    
      if (tcInt.isEntryEnabled())
         SibTr.exit(tcInt, "createDestination(Destination)");
    }//

  }
1347885
private void callDestinationListener(String destinationName) throws SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "callDestinationListener", new Object[] { destinationName });

        DestinationListenerDataObject listenerDataObject = null;
        DestinationListener destinationListener = null;
        DestinationAvailability listenersDestinationAvailability = null;
        SICoreConnection listenersConnection = null;
        DestinationNamePattern destinationNamePattern = null;

        BaseDestinationHandler destinationHandler = null;

        try
        {
            destinationHandler = (BaseDestinationHandler) getDestination(destinationName, false);
        } catch (SIMPDestinationCorruptException e)
        {
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.impl.DestinationManager.callDestinationListener",
                                        "1:7589:1.508.1.7",
                                        this);

            SibTr.exception(tc, e);

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "callDestinationListener", "Destination corrupt");

            // Finding that a restored destination has been marked as corrupt is no
            // reason to cause the transaction to fail.  Andrew Whitfield says that
            // a destination listener will not want to know about corrupt destinations
            // so we end up just returning.
            return;
        } catch (SIException e)
        {
            FFDCFilter.processException(
                                        e,
                                        "com.ibm.ws.sib.processor.impl.DestinationManager.callDestinationListener",
                                        "1:7608:1.508.1.7",
                                        this);

            SibTr.exception(tc, e);
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "callDestinationListener", "SIResourceException");
            throw new SIResourceException(e);
        }

        if (!(destinationHandler.definition.getDestinationType() == DestinationType.TOPICSPACE))
        {

            for (int i = 0; i < destinationListeners.size(); i++)
            {
                listenerDataObject = destinationListeners.get(i);
                destinationListener = listenerDataObject.getDestinationLister();
                listenersDestinationAvailability = listenerDataObject.getDestinationAvailability();
                listenersConnection = listenerDataObject.getConnection();
                destinationNamePattern = listenerDataObject.getDestinationNamePattern();

                SIDestinationAddress destinationAddress = null;

                if (isAvailable(destinationHandler, listenersDestinationAvailability)
                    && (!(destinationHandler.isSystem()))
                    && listenerDataObject.getDestinationType() == destinationHandler.definition.getDestinationType())
                {
                    // Check whether a destination name pattern was specified
                    if (destinationNamePattern == null || destinationNamePattern.match(destinationName))
                    {
                        // No pattern or the pattern matches the name.
                        destinationAddress =
                                        (
                                        (SIDestinationAddressFactory) MessageProcessor.getSingletonInstance(
                                                        SIMPConstants.SI_DESTINATION_ADDRESS_FACTORY)).createSIDestinationAddress(
                                                                                                                                  destinationHandler.getName(),
                                                                                                                                  true);
                        // call the listener
                        destinationListener.destinationAvailable(
                                                                 listenersConnection,
                                                                 destinationAddress,
                                                                 listenersDestinationAvailability);
                    }
                }
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "callDestinationListener");
    }
169814
public BaseDestinationHandler getDestinationHandler()
  {
    if (tc.isEntryEnabled())  
    {
      SibTr.entry(tc, "getDestinationHandler");
      SibTr.exit(tc, "getDestinationHandler", destinationHandler);
    }      
    return destinationHandler;
  }
629745
public SIDestinationAddress getDestinationAddress()
  {
    if (TraceComponent.isAnyTracingEnabled() && CoreSPIProducerSession.tc.isEntryEnabled())
      SibTr.entry(
        CoreSPIProducerSession.tc,
        "getDestinationAddress", this);

//    if(_ != null)
//    {
//      if (TraceComponent.isAnyTracingEnabled() && CoreSPIProducerSession.tc.isEntryEnabled())
//        SibTr.exit(CoreSPIProducerSession.tc, "getDestinationAddress", _routingDestinationAddr);
//      return _routingDestinationAddr;
//    }

    if (_address == null)
    {
      SIDestinationAddress destAddr
        = DestinationSessionUtils.createJsDestinationAddress(_destination);
      if (TraceComponent.isAnyTracingEnabled() && CoreSPIProducerSession.tc.isEntryEnabled())
        SibTr.exit(CoreSPIProducerSession.tc, "getDestinationAddress", destAddr);
      return destAddr;
    }
    else
    {
      if (TraceComponent.isAnyTracingEnabled() && CoreSPIProducerSession.tc.isEntryEnabled())
        SibTr.exit(CoreSPIProducerSession.tc, "getDestinationAddress", _address);
      return _address;
    }
  }
1012196
@Override
	protected final void sendToDestination(Destination destination, boolean destinationOverride, Message srcMessage, int deliveryMode, int priority, long timeToLive) throws JMSException
    {
        // Check that the destination was specified
        if (destination == null)
            throw new InvalidDestinationException("Destination not specified");  // [JMS SPEC]

        // Create an internal copy if necessary
        AbstractMessage message = MessageTools.makeInternalCopy(srcMessage);
        
        externalAccessLock.readLock().lock();
        try
		{
    		checkNotClosed();
    		
	        // Dispatch to session
            ((LocalSession)session).dispatch(message);
		}
        finally
        {
        	externalAccessLock.readLock().unlock();
        }
    }
863346
public String getDestination()
  {
    if (tc.isEntryEnabled())
    {
      SibTr.entry(tc, "getDestination");
      SibTr.exit(tc, "getDestination", destination);
    }

    return destination;
  }
245349
public JmsDestinationType<WebFragmentDescriptor> getOrCreateJmsDestination()
   {
      List<Node> nodeList = model.get("jms-destination");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new JmsDestinationTypeImpl<WebFragmentDescriptor>(this, "jms-destination", model, nodeList.get(0));
      }
      return createJmsDestination();
   }
882361
public DestinationHandler getAliasDestination(SIBUuid12 gatheringTargetUuid, DestinationHandler baseDest, boolean includeInvisible)
                    throws SITemporaryDestinationNotFoundException, SINotPossibleInCurrentConfigurationException, SIMPDestinationCorruptException, SIResourceException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "getAliasDestination", new Object[] { gatheringTargetUuid, baseDest, Boolean.valueOf(includeInvisible) });

        DestinationHandler destinationHandler = getDestinationInternal(gatheringTargetUuid, includeInvisible);

        try
        {
            if (destinationHandler == null)
            {
                BaseDestinationDefinition bdd = messageProcessor.getMessagingEngine().getSIBDestinationByUuid(messageProcessor.getMessagingEngineBus(),
                                                                                                              gatheringTargetUuid.toString());

                // The returned destination can be remote or an alias.  We need to act
                // accordingly.
                if (bdd.isAlias())
                {
                    // The destination is an alias.
                    DestinationAliasDefinition add = (DestinationAliasDefinition) bdd;

                    destinationHandler = createAliasDestination(add, null, baseDest);
                }
            }
        }

        // Catch Admin's SIBExceptionDestinationNotFound exception
        catch (SIBExceptionDestinationNotFound e)
        {
            // No FFDC code needed

            SibTr.exception(tc, e);

            // Exception not fatal - just return null to show no destiation has been
            // found.
        } catch (SIBExceptionBase e)
        {
            // No FFDC code needed

            SibTr.exception(tc, e);

            // TO DO - handle this
        } catch (SIResourceException e)
        {
            // No FFDC code needed
            if (!(e instanceof SIMPResourceException))
            {
                SIMPResourceException ee = new SIMPResourceException(e);
                ee.setExceptionReason(SIRCConstants.SIRC0901_INTERNAL_MESSAGING_ERROR);
                ee.setExceptionInserts(new String[] { "com.ibm.ws.sib.processor.impl.DestinationManager.getAliasDestination",
                                                     "1:8107:1.508.1.7",
                                                     SIMPUtils.getStackTrace(e) });
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    SibTr.exit(tc, "getAliasDestination", ee);
                throw ee;
            }

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(tc, "getAliasDestination", e);
            throw e;

        }

        checkDestinationHandlerExists(
                                      destinationHandler != null,
                                      gatheringTargetUuid.toString(),
                                      messageProcessor.getMessagingEngineName());

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "getAliasDestination", destinationHandler);

        return destinationHandler;
    }
137057
@Override
    public BaseDestinationHandler getResolvedDestinationHandler()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        {
            SibTr.entry(tc, "getResolvedDestinationHandler");
            SibTr.exit(tc, "getResolvedDestinationHandler", this);
        }
        return this;
    }
417962
private Destination getDestination(Session session, String queueName) throws JMSException {
    	return new DynamicDestinationResolver().resolveDestinationName(session, queueName, false);
	}
938385
public java.util.List<Destination> getDestinations() {
        if (destinations == null) {
            destinations = new com.amazonaws.internal.SdkInternalList<Destination>();
        }
        return destinations;
    }