当前位置: 首页>>代码示例>>Java>>正文


Java ServerLocator.createSessionFactory方法代码示例

本文整理汇总了Java中org.apache.activemq.artemis.api.core.client.ServerLocator.createSessionFactory方法的典型用法代码示例。如果您正苦于以下问题:Java ServerLocator.createSessionFactory方法的具体用法?Java ServerLocator.createSessionFactory怎么用?Java ServerLocator.createSessionFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.artemis.api.core.client.ServerLocator的用法示例。


在下文中一共展示了ServerLocator.createSessionFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testProducerWithSmallWindowSizeAndLargeMessage

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testProducerWithSmallWindowSizeAndLargeMessage() throws Exception {
   final CountDownLatch latch = new CountDownLatch(1);
   server.getRemotingService().addIncomingInterceptor(new Interceptor() {
      @Override
      public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
         if (packet.getType() == PacketImpl.SESS_SEND) {
            latch.countDown();
         }
         return true;
      }
   });
   ServerLocator locator = createInVMNonHALocator().setConfirmationWindowSize(100);
   ClientSessionFactory cf = locator.createSessionFactory();
   ClientSession session = cf.createSession(false, true, true);
   ClientProducer producer = session.createProducer(QUEUE);
   ClientMessage message = session.createMessage(true);
   byte[] body = new byte[1000];
   message.getBodyBuffer().writeBytes(body);
   producer.send(message);
   Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
   session.close();
   locator.close();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:ProducerTest.java

示例2: setup

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
   server = createServer(true);
   server.start();

   server.waitForActivation(10, TimeUnit.SECONDS);

   ServerLocator sl = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
   sessionFactory = sl.createSessionFactory();

   addSessionFactory(sessionFactory);

   addressInfo = new AddressInfo(baseAddress);
   addressInfo.addRoutingType(RoutingType.ANYCAST);
   server.addOrUpdateAddressInfo(addressInfo);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:17,代码来源:AnycastTest.java

示例3: main

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
   try {
      CrashClient.log.debug("args = " + Arrays.asList(args));

      ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
      locator.setClientFailureCheckPeriod(ClientCrashTest.PING_PERIOD);
      locator.setConnectionTTL(ClientCrashTest.CONNECTION_TTL);
      ClientSessionFactory sf = locator.createSessionFactory();

      ClientSession session = sf.createSession(false, true, true);
      ClientProducer producer = session.createProducer(ClientCrashTest.QUEUE);

      // it has to be durable otherwise it may race dying before the client is killed
      ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 1);
      message.getBodyBuffer().writeString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);

      producer.send(message);

      // exit without closing the session properly
      System.exit(9);
   } catch (Throwable t) {
      CrashClient.log.error(t.getMessage(), t);
      System.exit(1);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:CrashClient.java

示例4: ServerConnector

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
/**
 * Connects to the Artemis server and starts a client session.
 * @param locator locates the Artemis server.
 * @param createSession factory method to create a new session.
 * @throws Exception if the connection could not be established or the
 * session could not be started.
 * @throws NullPointerException if any argument is {@code null}.
 */
public ServerConnector(
        ServerLocator locator,
        FunctionE<ClientSessionFactory, ClientSession> createSession)
            throws Exception {
    requireNonNull(locator, "locator");
    requireNonNull(createSession, "createSession");
    
    this.factory = locator.createSessionFactory();
    this.session = startSession(factory, createSession);
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:19,代码来源:ServerConnector.java

示例5: ServerConnector

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
/**
 * Connects to the Artemis server and starts a client session.
 * @param locator locates the Artemis server.
 * @throws Exception if the connection could not be established or the
 * session could not be started.
 */
public ServerConnector(ServerLocator locator) throws Exception {
    requireNonNull(locator, "locator");
    
    this.factory = locator.createSessionFactory();
    this.session = startSession(factory);
}
 
开发者ID:c0c0n3,项目名称:ome-smuggler,代码行数:13,代码来源:ServerConnector.java

示例6: testInVMConnectionLimit

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testInVMConnectionLimit() throws Exception {
   ServerLocator locator = addServerLocator(createNonHALocator(false));
   ClientSessionFactory clientSessionFactory = locator.createSessionFactory();

   try {
      ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory();
      fail("creating a session factory here should fail");
   } catch (Exception e) {
      assertTrue(e instanceof ActiveMQNotConnectedException);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:ConnectionLimitTest.java

示例7: createQueue

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
protected void createQueue(final String address, final String queue) throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory sf = locator.createSessionFactory();
   ClientSession session = sf.createSession();
   try {
      session.createQueue(address, queue);
   } finally {
      session.close();
      closeSessionFactory(sf);
      closeServerLocator(locator);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:ActiveMQTestBase.java

示例8: testNettyConnectionLimit

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testNettyConnectionLimit() throws Exception {
   ServerLocator locator = createNonHALocator(true).setCallTimeout(3000);
   ClientSessionFactory clientSessionFactory = locator.createSessionFactory();
   ClientSession clientSession = addClientSession(clientSessionFactory.createSession());

   try {
      ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory();
      ClientSession extraClientSession = addClientSession(extraClientSessionFactory.createSession());
      fail("creating a session here should fail");
   } catch (Exception e) {
      assertTrue(e instanceof ActiveMQConnectionTimedOutException);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:15,代码来源:ConnectionLimitTest.java

示例9: createSessionFactoryAndWaitForTopology

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
protected ClientSessionFactoryInternal createSessionFactoryAndWaitForTopology(ServerLocator locator,
                                                                              int topologyMembers) throws Exception {
   CountDownLatch countDownLatch = new CountDownLatch(topologyMembers);

   locator.addClusterTopologyListener(new LatchClusterTopologyListener(countDownLatch));

   ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) locator.createSessionFactory();
   addSessionFactory(sf);

   Assert.assertTrue("topology members expected " + topologyMembers, countDownLatch.await(5, TimeUnit.SECONDS));
   return sf;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:FailoverTestBase.java

示例10: testNoCursors

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testNoCursors() throws Exception {
   Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);

   server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);

   server.start();

   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory sf = locator.createSessionFactory();
   ClientSession session = sf.createSession();

   session.createQueue(ADDRESS, ADDRESS, true);
   ClientProducer prod = session.createProducer(ADDRESS);

   for (int i = 0; i < 100; i++) {
      Message msg = session.createMessage(true);
      msg.toCore().getBodyBuffer().writeBytes(new byte[1024]);
      prod.send(msg);
   }

   session.commit();

   session.deleteQueue(ADDRESS);
   session.close();
   sf.close();
   locator.close();
   server.stop();
   server.start();
   waitForNotPaging(server.getPagingManager().getPageStore(ADDRESS));
   server.stop();

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:34,代码来源:PagingTest.java

示例11: main

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
   if (args.length != 2) {
      throw new Exception("require 2 arguments: queue name + message text");
   }
   String queueName = args[0];
   String messageText = args[1];

   try {
      ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
      ClientSessionFactory sf = locator.createSessionFactory();
      ClientSession session = sf.createSession(false, true, true);
      ClientProducer producer = session.createProducer(queueName);
      ClientConsumer consumer = session.createConsumer(queueName);

      ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
      message.getBodyBuffer().writeString(messageText);
      producer.send(message);

      session.start();

      // block in receiving for 5 secs, we won't receive anything
      consumer.receive(5000);

      // this should silence any non-daemon thread and allow for graceful exit
      session.close();
      System.exit(0);
   } catch (Throwable t) {
      GracefulClient.log.error(t.getMessage(), t);
      System.exit(1);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:32,代码来源:GracefulClient.java

示例12: perform

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public void perform() throws Exception {
   ServerLocator locator = null;
   ClientSessionFactory sf = null;
   try {
      locator = createNettyNonHALocator();
      sf = locator.createSessionFactory();
      ClientSession session = sf.createSession(false, true, true);
      log.info("### client: connected. server incrementingVersion = " + session.getVersion());
      session.close();
   } finally {
      closeSessionFactory(sf);
      closeServerLocator(locator);
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:15,代码来源:IncompatibleVersionTest.java

示例13: testStressConnection

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testStressConnection() throws Exception {

   for (int i = 0; i < 10; i++) {
      ServerLocator locatorSendx = createFactory(isNetty()).setReconnectAttempts(15);
      ClientSessionFactory factoryx = locatorSendx.createSessionFactory();
      factoryx.close();
      locatorSendx.close();
   }

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:12,代码来源:ConsumerTest.java

示例14: start

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
public void start() throws Exception {
   if (configuration == null || !configSet) {
      if (configResourcePath == null) {
         configuration = new MessageServiceConfiguration();
      } else {
         URL url = getClass().getClassLoader().getResource(configResourcePath);

         if (isOutsideOfClassloader(url)) {
            url = new URL(configResourcePath);
         }
         JAXBContext jaxb = JAXBContext.newInstance(MessageServiceConfiguration.class);
         Reader reader = new InputStreamReader(url.openStream());
         String xml = XMLUtil.readerToString(reader);
         xml = XMLUtil.replaceSystemProps(xml);
         configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
      }
   }
   if (threadPool == null)
      threadPool = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
   timeoutTaskInterval = configuration.getTimeoutTaskInterval();
   timeoutTask = new TimeoutTask(timeoutTaskInterval);
   threadPool.execute(timeoutTask);

   DestinationSettings defaultSettings = new DestinationSettings();
   defaultSettings.setConsumerSessionTimeoutSeconds(configuration.getConsumerSessionTimeoutSeconds());
   defaultSettings.setDuplicatesAllowed(configuration.isDupsOk());
   defaultSettings.setDurableSend(configuration.isDefaultDurableSend());

   ServerLocator consumerLocator = ActiveMQClient.createServerLocator(configuration.getUrl());

   if (configuration.getConsumerWindowSize() != -1) {
      consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
   }

   ActiveMQRestLogger.LOGGER.debug("Created ServerLocator: " + consumerLocator);

   consumerSessionFactory = consumerLocator.createSessionFactory();
   ActiveMQRestLogger.LOGGER.debug("Created ClientSessionFactory: " + consumerSessionFactory);

   ServerLocator defaultLocator = ActiveMQClient.createServerLocator(configuration.getUrl());

   ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();

   LinkStrategy linkStrategy;
   if (configuration.isUseLinkHeaders()) {
      linkStrategy = new LinkHeaderLinkStrategy();
   } else {
      linkStrategy = new CustomHeaderLinkStrategy();
   }

   queueManager.setServerLocator(defaultLocator);
   queueManager.setSessionFactory(sessionFactory);
   queueManager.setTimeoutTask(timeoutTask);
   queueManager.setConsumerServerLocator(consumerLocator);
   queueManager.setConsumerSessionFactory(consumerSessionFactory);
   queueManager.setDefaultSettings(defaultSettings);
   queueManager.setPushStoreFile(configuration.getQueuePushStoreDirectory());
   queueManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
   queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
   queueManager.setLinkStrategy(linkStrategy);
   queueManager.setRegistry(registry);

   topicManager.setServerLocator(defaultLocator);
   topicManager.setSessionFactory(sessionFactory);
   topicManager.setTimeoutTask(timeoutTask);
   topicManager.setConsumerServerLocator(consumerLocator);
   topicManager.setConsumerSessionFactory(consumerSessionFactory);
   topicManager.setDefaultSettings(defaultSettings);
   topicManager.setPushStoreFile(configuration.getTopicPushStoreDirectory());
   topicManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
   queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
   topicManager.setLinkStrategy(linkStrategy);
   topicManager.setRegistry(registry);

   queueManager.start();
   topicManager.start();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:78,代码来源:MessageServiceManager.java

示例15: testMultipleClientSessionFactories

import org.apache.activemq.artemis.api.core.client.ServerLocator; //导入方法依赖的package包/类
@Test
public void testMultipleClientSessionFactories() throws Throwable {
   startServers(0, 1, 2, 3, 4);
   String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);

   ServerLocator locator = createHAServerLocator();

   waitForClusterConnections(0, 4);
   waitForClusterConnections(1, 4);
   waitForClusterConnections(2, 4);
   waitForClusterConnections(3, 4);
   waitForClusterConnections(4, 4);

   final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
   final CountDownLatch upLatch = new CountDownLatch(5);
   final CountDownLatch downLatch = new CountDownLatch(4);

   locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, downLatch));

   ClientSessionFactory[] sfs = new ClientSessionFactory[]{locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory(), locator.createSessionFactory()};
   Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
   checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes);

   // we can't close all of the servers, we need to leave one up to notify us
   stopServers(4, 2, 3, 1);

   boolean ok = downLatch.await(10, SECONDS);
   if (!ok) {
      log.warn("TopologyClusterTestBase.testMultipleClientSessionFactories will fail");
   }
   Assert.assertTrue("Was not notified that all servers are Down", ok);
   checkContains(new int[]{0}, nodeIDs, nodes);

   for (ClientSessionFactory sf : sfs) {
      sf.close();
   }

   locator.close();

   stopServers(0);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:42,代码来源:TopologyClusterTestBase.java


注:本文中的org.apache.activemq.artemis.api.core.client.ServerLocator.createSessionFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。