コード例 #1
0
ファイル: JMSBridgeImpl.java プロジェクト: dcaillia/hornetq
  private Connection createConnection(
      final String username,
      final String password,
      final ConnectionFactoryFactory cff,
      final String clientID,
      final boolean isXA)
      throws Exception {
    Connection conn;

    Object cf = cff.createConnectionFactory();

    if (qualityOfServiceMode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE
        && !(cf instanceof XAConnectionFactory)) {
      throw new IllegalArgumentException("Connection factory must be XAConnectionFactory");
    }

    if (username == null) {
      if (isXA) {
        if (JMSBridgeImpl.trace) {
          HornetQJMSServerLogger.LOGGER.trace("Creating an XA connection");
        }
        conn = ((XAConnectionFactory) cf).createXAConnection();
      } else {
        if (JMSBridgeImpl.trace) {
          HornetQJMSServerLogger.LOGGER.trace("Creating a non XA connection");
        }
        conn = ((ConnectionFactory) cf).createConnection();
      }
    } else {
      if (isXA) {
        if (JMSBridgeImpl.trace) {
          HornetQJMSServerLogger.LOGGER.trace("Creating an XA connection");
        }
        conn = ((XAConnectionFactory) cf).createXAConnection(username, password);
      } else {
        if (JMSBridgeImpl.trace) {
          HornetQJMSServerLogger.LOGGER.trace("Creating a non XA connection");
        }
        conn = ((ConnectionFactory) cf).createConnection(username, password);
      }
    }

    if (clientID != null) {
      conn.setClientID(clientID);
    }

    conn.setExceptionListener(new BridgeExceptionListener());

    return conn;
  }
コード例 #2
0
ファイル: BridgeTestBase.java プロジェクト: kabuky/hornetq
  protected void setUpAdministeredObjects() throws Exception {
    cff0LowProducerWindow =
        new ConnectionFactoryFactory() {
          public ConnectionFactory createConnectionFactory() throws Exception {
            HornetQConnectionFactory cf =
                HornetQJMSClient.createConnectionFactoryWithoutHA(
                    JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

            // Note! We disable automatic reconnection on the session factory. The bridge needs to
            // do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            cf.setProducerWindowSize(100);

            return cf;
          }
        };

    cff0 =
        new ConnectionFactoryFactory() {
          public ConnectionFactory createConnectionFactory() throws Exception {
            HornetQConnectionFactory cf =
                HornetQJMSClient.createConnectionFactoryWithoutHA(
                    JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

            // Note! We disable automatic reconnection on the session factory. The bridge needs to
            // do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);

            return cf;
          }
        };

    cff0xa =
        new ConnectionFactoryFactory() {
          public Object createConnectionFactory() throws Exception {
            HornetQXAConnectionFactory cf =
                (HornetQXAConnectionFactory)
                    HornetQJMSClient.createConnectionFactoryWithoutHA(
                        JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

            // Note! We disable automatic reconnection on the session factory. The bridge needs to
            // do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);

            return cf;
          }
        };

    cf0 = (ConnectionFactory) cff0.createConnectionFactory();
    cf0xa = (XAConnectionFactory) cff0xa.createConnectionFactory();

    cff1 =
        new ConnectionFactoryFactory() {

          public ConnectionFactory createConnectionFactory() throws Exception {
            HornetQJMSConnectionFactory cf =
                (HornetQJMSConnectionFactory)
                    HornetQJMSClient.createConnectionFactoryWithoutHA(
                        JMSFactoryType.CF,
                        new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));

            // Note! We disable automatic reconnection on the session factory. The bridge needs to
            // do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);

            return cf;
          }
        };

    cff1xa =
        new ConnectionFactoryFactory() {

          public XAConnectionFactory createConnectionFactory() throws Exception {
            HornetQXAConnectionFactory cf =
                (HornetQXAConnectionFactory)
                    HornetQJMSClient.createConnectionFactoryWithoutHA(
                        JMSFactoryType.XA_CF,
                        new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));

            // Note! We disable automatic reconnection on the session factory. The bridge needs to
            // do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);

            return cf;
          }
        };

    cf1 = (ConnectionFactory) cff1.createConnectionFactory();
    cf1xa = (XAConnectionFactory) cff1xa.createConnectionFactory();

    sourceQueueFactory =
        new DestinationFactory() {
          public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/queue/sourceQueue");
          }
        };

    sourceQueue = (Queue) sourceQueueFactory.createDestination();

    targetQueueFactory =
        new DestinationFactory() {
          public Destination createDestination() throws Exception {
            return (Destination) context1.lookup("/queue/targetQueue");
          }
        };

    targetQueue = (Queue) targetQueueFactory.createDestination();

    sourceTopicFactory =
        new DestinationFactory() {
          public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/topic/sourceTopic");
          }
        };

    sourceTopic = (Topic) sourceTopicFactory.createDestination();

    localTargetQueueFactory =
        new DestinationFactory() {
          public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/queue/localTargetQueue");
          }
        };

    localTargetQueue = (Queue) localTargetQueueFactory.createDestination();
  }