本文整理了Java中org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.getServerLocator()
方法的一些代码示例,展示了ActiveMQConnectionFactory.getServerLocator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ActiveMQConnectionFactory.getServerLocator()
方法的具体详情如下:
包路径:org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory
类名称:ActiveMQConnectionFactory
方法名:getServerLocator
暂无
代码示例来源:origin: apache/activemq-artemis
public static XARecoveryConfig newConfig(ActiveMQConnectionFactory factory,
String userName,
String password,
Map<String, String> properties) {
if (factory.getServerLocator().getDiscoveryGroupConfiguration() != null) {
return new XARecoveryConfig(factory.getServerLocator().isHA(), factory.getServerLocator().getDiscoveryGroupConfiguration(), userName, password, properties, factory.getServerLocator().getProtocolManagerFactory());
} else {
return new XARecoveryConfig(factory.getServerLocator().isHA(), factory.getServerLocator().getStaticTransportConfigurations(), userName, password, properties, factory.getServerLocator().getProtocolManagerFactory());
}
}
代码示例来源:origin: org.apache.activemq/artemis-service-extensions
public static XARecoveryConfig newConfig(ActiveMQConnectionFactory factory,
String userName,
String password,
Map<String, String> properties) {
if (factory.getServerLocator().getDiscoveryGroupConfiguration() != null) {
return new XARecoveryConfig(factory.getServerLocator().isHA(), factory.getServerLocator().getDiscoveryGroupConfiguration(), userName, password, properties, factory.getServerLocator().getProtocolManagerFactory());
} else {
return new XARecoveryConfig(factory.getServerLocator().isHA(), factory.getServerLocator().getStaticTransportConfigurations(), userName, password, properties, factory.getServerLocator().getProtocolManagerFactory());
}
}
代码示例来源:origin: apache/activemq-artemis
protected ActiveMQConnectionFactory setData(URI uri,
Map<String, String> query,
ActiveMQConnectionFactory factory) throws Exception {
BeanSupport.setData(uri, factory.getServerLocator(), query);
return BeanSupport.setData(uri, factory, query);
}
代码示例来源:origin: apache/activemq-artemis
protected ActiveMQConnectionFactory setData(URI uri,
Map<String, String> query,
ActiveMQConnectionFactory factory) throws Exception {
BeanSupport.setData(uri, factory.getServerLocator(), query);
return BeanSupport.setData(uri, factory, query);
}
代码示例来源:origin: org.apache.activemq/artemis-jms-client-all
protected ActiveMQConnectionFactory setData(URI uri,
Map<String, String> query,
ActiveMQConnectionFactory factory) throws Exception {
BeanSupport.setData(uri, factory.getServerLocator(), query);
return BeanSupport.setData(uri, factory, query);
}
代码示例来源:origin: apache/activemq-artemis
public synchronized ActiveMQConnectionFactory getConnectionFactory(final ConnectionFactoryProperties overrideProperties) {
ActiveMQConnectionFactory cf;
boolean known = false;
if (!knownConnectionFactories.keySet().contains(overrideProperties)) {
cf = newConnectionFactory(overrideProperties);
knownConnectionFactories.put(overrideProperties, new Pair<>(cf, new AtomicInteger(1)));
} else {
Pair<ActiveMQConnectionFactory, AtomicInteger> pair = knownConnectionFactories.get(overrideProperties);
cf = pair.getA();
pair.getB().incrementAndGet();
known = true;
}
if (known && cf.getServerLocator().isClosed()) {
knownConnectionFactories.remove(overrideProperties);
cf = newConnectionFactory(overrideProperties);
knownConnectionFactories.put(overrideProperties, new Pair<>(cf, new AtomicInteger(1)));
}
return cf;
}
代码示例来源:origin: org.apache.activemq/artemis-ra
public synchronized ActiveMQConnectionFactory getConnectionFactory(final ConnectionFactoryProperties overrideProperties) {
ActiveMQConnectionFactory cf;
boolean known = false;
if (!knownConnectionFactories.keySet().contains(overrideProperties)) {
cf = newConnectionFactory(overrideProperties);
knownConnectionFactories.put(overrideProperties, new Pair<>(cf, new AtomicInteger(1)));
} else {
Pair<ActiveMQConnectionFactory, AtomicInteger> pair = knownConnectionFactories.get(overrideProperties);
cf = pair.getA();
pair.getB().incrementAndGet();
known = true;
}
if (known && cf.getServerLocator().isClosed()) {
knownConnectionFactories.remove(overrideProperties);
cf = newConnectionFactory(overrideProperties);
knownConnectionFactories.put(overrideProperties, new Pair<>(cf, new AtomicInteger(1)));
}
return cf;
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testUseTopologyForLoadBalancing() throws Exception {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://0?useTopologyForLoadBalancing=false");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
assertFalse(((ActiveMQConnectionFactory)connectionFactory).getServerLocator().getUseTopologyForLoadBalancing());
}
}
代码示例来源:origin: apache/activemq-artemis
public static ActiveMQConnection createConnectionAndWaitForTopology(ActiveMQConnectionFactory factory,
int topologyMembers,
int timeout) throws Exception {
ActiveMQConnection conn;
CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);
ServerLocator locator = factory.getServerLocator();
locator.addClusterTopologyListener(new FailoverTestBase.LatchClusterTopologyListener(countDownLatch));
conn = (ActiveMQConnection) factory.createConnection();
boolean ok = countDownLatch.await(timeout, TimeUnit.SECONDS);
if (!ok) {
throw new IllegalStateException("timed out waiting for topology");
}
return conn;
}
代码示例来源:origin: apache/activemq-artemis
@Override
protected ActiveMQConnectionFactory internalNewObject(URI uri,
Map<String, String> query,
String name) throws Exception {
JMSConnectionOptions options = newConectionOptions(uri, query);
ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"));
BeanSupport.setData(uri, factory, query);
BeanSupport.setData(uri, factory.getServerLocator(), query);
return factory;
}
代码示例来源:origin: apache/activemq-artemis
@Override
protected ActiveMQConnectionFactory internalNewObject(URI uri,
Map<String, String> query,
String name) throws Exception {
JMSConnectionOptions options = newConectionOptions(uri, query);
ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"));
BeanSupport.setData(uri, factory, query);
BeanSupport.setData(uri, factory.getServerLocator(), query);
return factory;
}
代码示例来源:origin: org.apache.activemq/artemis-jms-client-all
@Override
protected ActiveMQConnectionFactory internalNewObject(URI uri,
Map<String, String> query,
String name) throws Exception {
JMSConnectionOptions options = newConectionOptions(uri, query);
ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"));
BeanSupport.setData(uri, factory, query);
BeanSupport.setData(uri, factory.getServerLocator(), query);
return factory;
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testInvalidConnector() throws Exception {
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.HOST_PROP_NAME, "0.0.0.0");
List<TransportConfiguration> connectorConfigs = new ArrayList<>();
connectorConfigs.add(new TransportConfiguration(NETTY_CONNECTOR_FACTORY, params));
int retryInterval = 1000;
double retryIntervalMultiplier = 1.0;
int reconnectAttempts = -1;
int callTimeout = 30000;
jmsServer.createConnectionFactory("invalid-cf", false, JMSFactoryType.CF, registerConnectors(server, connectorConfigs), null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, callTimeout, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, retryInterval, retryIntervalMultiplier, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, reconnectAttempts, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/invalid-cf");
ActiveMQConnectionFactory invalidCf = (ActiveMQConnectionFactory) namingContext.lookup("/invalid-cf");
TransportConfiguration[] tcs = invalidCf.getServerLocator().getStaticTransportConfigurations();
TransportConfiguration tc = tcs[0];
assertNotSame(tc.getParams().get(TransportConstants.HOST_PROP_NAME), "0.0.0.0");
assertEquals(tc.getParams().get(TransportConstants.HOST_PROP_NAME), InetAddress.getLocalHost().getHostName());
}
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testBrowse2() throws Exception {
conn = getConnectionFactory().createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue1);
ActiveMQConnectionFactory cf1 = (ActiveMQConnectionFactory) getConnectionFactory();
ClientSession coreSession = cf1.getServerLocator().createSessionFactory().createSession(true, true);
coreSession.start();
ClientConsumer browser = coreSession.createConsumer("Queue1", true);
conn.start();
Message m = session.createMessage();
m.setIntProperty("cnt", 0);
producer.send(m);
Assert.assertNotNull(browser.receiveImmediate());
coreSession.close();
drainDestination(getConnectionFactory(), queue1);
}
代码示例来源:origin: apache/activemq-artemis
public void performCoreManagement(ManagementCallback<ClientMessage> cb) throws Exception {
try (ActiveMQConnectionFactory factory = createCoreConnectionFactory();
ServerLocator locator = factory.getServerLocator();
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE)) {
session.start();
ClientRequestor requestor = new ClientRequestor(session, "activemq.management");
ClientMessage message = session.createMessage(false);
cb.setUpInvocation(message);
ClientMessage reply = requestor.request(message);
if (ManagementHelper.hasOperationSucceeded(reply)) {
cb.requestSuccessful(reply);
} else {
cb.requestFailed(reply);
}
}
}
代码示例来源:origin: org.apache.activemq/artemis-cli
public void performCoreManagement(ManagementCallback<ClientMessage> cb) throws Exception {
try (ActiveMQConnectionFactory factory = createCoreConnectionFactory();
ServerLocator locator = factory.getServerLocator();
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE)) {
session.start();
ClientRequestor requestor = new ClientRequestor(session, "activemq.management");
ClientMessage message = session.createMessage(false);
cb.setUpInvocation(message);
ClientMessage reply = requestor.request(message);
if (ManagementHelper.hasOperationSucceeded(reply)) {
cb.requestSuccessful(reply);
} else {
cb.requestFailed(reply);
}
}
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testParseURIs() throws Throwable {
ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name");
Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length);
ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false");
Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length);
ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false");
Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length);
ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false");
Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length);
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testCreateConnectionFactoryMultipleConnectorsOverride() {
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY);
ConnectionFactoryProperties overrideProperties = new ConnectionFactoryProperties();
ArrayList<String> value = new ArrayList<>();
value.add(INVM_CONNECTOR_FACTORY);
value.add(NETTY_CONNECTOR_FACTORY);
value.add(INVM_CONNECTOR_FACTORY);
overrideProperties.setParsedConnectorClassNames(value);
ActiveMQConnectionFactory factory = ra.getConnectionFactory(overrideProperties);
TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations();
assertNotNull(configurations);
assertEquals(3, configurations.length);
assertEquals(INVM_CONNECTOR_FACTORY, configurations[0].getFactoryClassName());
assertEquals(1, configurations[0].getParams().size());
assertEquals(NETTY_CONNECTOR_FACTORY, configurations[1].getFactoryClassName());
assertEquals(2, configurations[1].getParams().size());
assertEquals(INVM_CONNECTOR_FACTORY, configurations[2].getFactoryClassName());
assertEquals(1, configurations[2].getParams().size());
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testCreateConnectionFactoryMultipleConnectors() {
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY);
ActiveMQConnectionFactory factory = ra.getConnectionFactory(new ConnectionFactoryProperties());
TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations();
assertNotNull(configurations);
assertEquals(3, configurations.length);
assertEquals(NETTY_CONNECTOR_FACTORY, configurations[0].getFactoryClassName());
assertEquals(2, configurations[0].getParams().size());
assertEquals(INVM_CONNECTOR_FACTORY, configurations[1].getFactoryClassName());
assertEquals(1, configurations[1].getParams().size());
assertEquals(NETTY_CONNECTOR_FACTORY, configurations[2].getFactoryClassName());
assertEquals(2, configurations[2].getParams().size());
}
代码示例来源:origin: apache/activemq-artemis
@Test
public void testCreateConnectionFactoryOverrideDiscovery() throws Exception {
ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
ra.setConnectorClassName(InVMConnectorFactory.class.getName());
ConnectionFactoryProperties connectionFactoryProperties = new ConnectionFactoryProperties();
connectionFactoryProperties.setDiscoveryAddress("myhost");
connectionFactoryProperties.setDiscoveryPort(5678);
connectionFactoryProperties.setDiscoveryLocalBindAddress("newAddress");
ActiveMQConnectionFactory factory = ra.getConnectionFactory(connectionFactoryProperties);
ActiveMQConnectionFactory defaultFactory = ra.getDefaultActiveMQConnectionFactory();
Assert.assertNotSame(factory, defaultFactory);
DiscoveryGroupConfiguration dc = factory.getServerLocator().getDiscoveryGroupConfiguration();
UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory();
Assert.assertEquals(udpDg.getLocalBindAddress(), "newAddress");
Assert.assertEquals(udpDg.getGroupAddress(), "myhost");
Assert.assertEquals(udpDg.getGroupPort(), 5678);
}
内容来源于网络,如有侵权,请联系作者删除!