Codota Logo
AbstractRoutingConnectionFactory
Code IndexAdd Codota to your IDE (free)

How to use
AbstractRoutingConnectionFactory
in
org.springframework.amqp.rabbit.connection

Best Java code snippets using org.springframework.amqp.rabbit.connection.AbstractRoutingConnectionFactory (Showing top 18 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Point p =
  • Codota Iconnew Point(x, y)
  • Codota Iconnew Point()
  • Codota IconMouseEvent e;e.getPoint()
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-amqp

/**
 * Retrieve the current target {@link ConnectionFactory}. Determines the
 * {@link #determineCurrentLookupKey() current lookup key}, performs
 * a lookup in the {@link #targetConnectionFactories} map,
 * falls back to the specified
 * {@link #defaultTargetConnectionFactory} if necessary.
 * @return The connection factory.
 * @see #determineCurrentLookupKey()
 */
protected ConnectionFactory determineTargetConnectionFactory() {
  Object lookupKey = determineCurrentLookupKey();
  ConnectionFactory connectionFactory = null;
  if (lookupKey != null) {
    connectionFactory = this.targetConnectionFactories.get(lookupKey);
  }
  if (connectionFactory == null && (this.lenientFallback || lookupKey == null)) {
    connectionFactory = this.defaultTargetConnectionFactory;
  }
  if (connectionFactory == null) {
    throw new IllegalStateException("Cannot determine target ConnectionFactory for lookup key ["
        + lookupKey + "]");
  }
  return connectionFactory;
}
origin: spring-projects/spring-amqp

@Override
public int getPort() {
  return this.determineTargetConnectionFactory().getPort();
}
origin: spring-projects/spring-amqp

private ConnectionFactory obtainTargetConnectionFactory(Expression expression, Object rootObject) {
  if (expression != null && getConnectionFactory() instanceof AbstractRoutingConnectionFactory) {
    AbstractRoutingConnectionFactory routingConnectionFactory =
        (AbstractRoutingConnectionFactory) getConnectionFactory();
    Object lookupKey;
    if (rootObject != null) {
      lookupKey = this.sendConnectionFactorySelectorExpression.getValue(this.evaluationContext, rootObject);
    }
    else {
      lookupKey = this.sendConnectionFactorySelectorExpression.getValue(this.evaluationContext);
    }
    if (lookupKey != null) {
      ConnectionFactory connectionFactory = routingConnectionFactory.getTargetConnectionFactory(lookupKey);
      if (connectionFactory != null) {
        return connectionFactory;
      }
      else if (!routingConnectionFactory.isLenientFallback()) {
        throw new IllegalStateException("Cannot determine target ConnectionFactory for lookup key ["
            + lookupKey + "]");
      }
    }
  }
  return getConnectionFactory();
}
origin: spring-projects/spring-amqp

@Test
public void testGetAddAndRemoveOperationsForTargetConnectionFactories() {
  ConnectionFactory targetConnectionFactory = Mockito.mock(ConnectionFactory.class);
  AbstractRoutingConnectionFactory routingFactory = new AbstractRoutingConnectionFactory() {
    @Override
    protected Object determineCurrentLookupKey() {
      return null;
    }
  };
  //Make sure map is initialized and doesn't contain lookup key "1"
  assertNull(routingFactory.getTargetConnectionFactory("1"));
  //Add one and make sure it's there
  routingFactory.addTargetConnectionFactory("1", targetConnectionFactory);
  assertEquals(targetConnectionFactory, routingFactory.getTargetConnectionFactory("1"));
  assertNull(routingFactory.getTargetConnectionFactory("2"));
  //Remove it and make sure it's gone
  ConnectionFactory removedConnectionFactory = routingFactory.removeTargetConnectionFactory("1");
  assertEquals(targetConnectionFactory, removedConnectionFactory);
  assertNull(routingFactory.getTargetConnectionFactory("1"));
}
origin: spring-projects/spring-amqp

@Test
public void testAbstractRoutingConnectionFactory() {
  ConnectionFactory connectionFactory1 = Mockito.mock(ConnectionFactory.class);
  ConnectionFactory connectionFactory2 = Mockito.mock(ConnectionFactory.class);
  Map<Object, ConnectionFactory> factories = new HashMap<Object, ConnectionFactory>(2);
  factories.put(Boolean.TRUE, connectionFactory1);
  factories.put(Boolean.FALSE, connectionFactory2);
  ConnectionFactory defaultConnectionFactory = Mockito.mock(ConnectionFactory.class);
  final AtomicBoolean lookupFlag = new AtomicBoolean(true);
  final AtomicInteger count = new AtomicInteger();
  AbstractRoutingConnectionFactory connectionFactory = new AbstractRoutingConnectionFactory() {
    @Override
    protected Object determineCurrentLookupKey() {
      return count.incrementAndGet() > 3 ? null : lookupFlag.getAndSet(!lookupFlag.get());
    }
  };
  connectionFactory.setDefaultTargetConnectionFactory(defaultConnectionFactory);
  connectionFactory.setTargetConnectionFactories(factories);
  for (int i = 0; i < 5; i++) {
    connectionFactory.createConnection();
  }
  verify(connectionFactory1, times(2)).createConnection();
  verify(connectionFactory2).createConnection();
  verify(defaultConnectionFactory, times(2)).createConnection();
}
origin: spring-projects/spring-amqp

@Test
public void testAddTargetConnectionFactoryAddsExistingConnectionListenersToConnectionFactory() {
  AbstractRoutingConnectionFactory routingFactory = new AbstractRoutingConnectionFactory() {
    @Override
    protected Object determineCurrentLookupKey() {
      return null;
    }
  };
  routingFactory.addConnectionListener(Mockito.mock(ConnectionListener.class));
  routingFactory.addConnectionListener(Mockito.mock(ConnectionListener.class));
  ConnectionFactory targetConnectionFactory = Mockito.mock(ConnectionFactory.class);
  routingFactory.addTargetConnectionFactory("1", targetConnectionFactory);
  verify(targetConnectionFactory,
      times(2)).addConnectionListener(any(ConnectionListener.class));
}
origin: spring-projects/spring-amqp

@Test
public void testSimpleRoutingConnectionFactory() throws InterruptedException {
  ConnectionFactory connectionFactory1 = Mockito.mock(ConnectionFactory.class);
  ConnectionFactory connectionFactory2 = Mockito.mock(ConnectionFactory.class);
  Map<Object, ConnectionFactory> factories = new HashMap<Object, ConnectionFactory>(2);
  factories.put("foo", connectionFactory1);
  factories.put("bar", connectionFactory2);
  final AbstractRoutingConnectionFactory connectionFactory = new SimpleRoutingConnectionFactory();
  connectionFactory.setTargetConnectionFactories(factories);
  ExecutorService executorService = Executors.newFixedThreadPool(3);
  for (int i = 0; i < 3; i++) {
    final AtomicInteger count = new AtomicInteger(i);
    executorService.execute(() -> {
      SimpleResourceHolder.bind(connectionFactory, count.get() % 2 == 0 ? "foo" : "bar");
      connectionFactory.createConnection();
      SimpleResourceHolder.unbind(connectionFactory);
    });
  }
  executorService.shutdown();
  assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
  verify(connectionFactory1, times(2)).createConnection();
  verify(connectionFactory2).createConnection();
}
origin: org.springframework.amqp/spring-rabbit

private ConnectionFactory obtainTargetConnectionFactory(Expression expression, Object rootObject) {
  if (expression != null && getConnectionFactory() instanceof AbstractRoutingConnectionFactory) {
    AbstractRoutingConnectionFactory routingConnectionFactory =
        (AbstractRoutingConnectionFactory) getConnectionFactory();
    Object lookupKey;
    if (rootObject != null) {
      lookupKey = this.sendConnectionFactorySelectorExpression.getValue(this.evaluationContext, rootObject);
    }
    else {
      lookupKey = this.sendConnectionFactorySelectorExpression.getValue(this.evaluationContext);
    }
    if (lookupKey != null) {
      ConnectionFactory connectionFactory = routingConnectionFactory.getTargetConnectionFactory(lookupKey);
      if (connectionFactory != null) {
        return connectionFactory;
      }
      else if (!routingConnectionFactory.isLenientFallback()) {
        throw new IllegalStateException("Cannot determine target ConnectionFactory for lookup key ["
            + lookupKey + "]");
      }
    }
  }
  return getConnectionFactory();
}
origin: spring-projects/spring-amqp

@Override
public String getUsername() {
  return this.determineTargetConnectionFactory().getUsername();
}
origin: org.springframework.amqp/spring-rabbit

/**
 * Retrieve the current target {@link ConnectionFactory}. Determines the
 * {@link #determineCurrentLookupKey() current lookup key}, performs
 * a lookup in the {@link #targetConnectionFactories} map,
 * falls back to the specified
 * {@link #defaultTargetConnectionFactory} if necessary.
 * @return The connection factory.
 * @see #determineCurrentLookupKey()
 */
protected ConnectionFactory determineTargetConnectionFactory() {
  Object lookupKey = determineCurrentLookupKey();
  ConnectionFactory connectionFactory = null;
  if (lookupKey != null) {
    connectionFactory = this.targetConnectionFactories.get(lookupKey);
  }
  if (connectionFactory == null && (this.lenientFallback || lookupKey == null)) {
    connectionFactory = this.defaultTargetConnectionFactory;
  }
  if (connectionFactory == null) {
    throw new IllegalStateException("Cannot determine target ConnectionFactory for lookup key ["
        + lookupKey + "]");
  }
  return connectionFactory;
}
origin: spring-projects/spring-amqp

@Override
public Connection createConnection() throws AmqpException {
  return this.determineTargetConnectionFactory().createConnection();
}
origin: org.springframework.amqp/spring-rabbit

@Override
public String getHost() {
  return this.determineTargetConnectionFactory().getHost();
}
origin: spring-projects/spring-amqp

@Override
public String getHost() {
  return this.determineTargetConnectionFactory().getHost();
}
origin: spring-projects/spring-amqp

@Override
public String getVirtualHost() {
  return this.determineTargetConnectionFactory().getVirtualHost();
}
origin: org.springframework.amqp/spring-rabbit

@Override
public Connection createConnection() throws AmqpException {
  return this.determineTargetConnectionFactory().createConnection();
}
origin: org.springframework.amqp/spring-rabbit

@Override
public String getVirtualHost() {
  return this.determineTargetConnectionFactory().getVirtualHost();
}
origin: org.springframework.amqp/spring-rabbit

@Override
public String getUsername() {
  return this.determineTargetConnectionFactory().getUsername();
}
origin: org.springframework.amqp/spring-rabbit

@Override
public int getPort() {
  return this.determineTargetConnectionFactory().getPort();
}
org.springframework.amqp.rabbit.connectionAbstractRoutingConnectionFactory

Javadoc

Abstract ConnectionFactory implementation that routes #createConnection()calls to one of various target ConnectionFactories based on a lookup key. The latter is usually (but not necessarily) determined through some thread-bound context.

Most used methods

  • getTargetConnectionFactory
  • determineCurrentLookupKey
    Determine the current lookup key. This will typically be implemented to check a thread-bound context
  • determineTargetConnectionFactory
    Retrieve the current target ConnectionFactory. Determines the #determineCurrentLookupKey(), performs
  • isLenientFallback
  • addConnectionListener
  • addTargetConnectionFactory
    Adds the given ConnectionFactory and associates it with the given lookup key.
  • createConnection
  • removeTargetConnectionFactory
    Removes the ConnectionFactory associated with the given lookup key and returns it.
  • setDefaultTargetConnectionFactory
    Specify the default target ConnectionFactory, if any.This ConnectionFactory will be used as target i
  • setTargetConnectionFactories
    Specify the map of target ConnectionFactories, with the lookup key as key.The key can be of arbitrar

Popular in Java

  • Making http requests using okhttp
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • onRequestPermissionsResult (Fragment)
  • getContentResolver (Context)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • List (java.util)
    A List is a collection which maintains an ordering for its elements. Every element in the List has a
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now