Package org.hornetq.api.core.client

Examples of org.hornetq.api.core.client.ClientSession


         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         session.createQueue(ADDRESS.toString(), "q1", true);

         session.createQueue(ADDRESS.toString(), "q2", true);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         ClientMessage message = null;

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            message = session.createMessage(true);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % messagesPerTX == 0)
            {
               session.commit();
            }
         }
         session.commit();
         session.close();
      }
      finally
      {
         try
         {
            server.stop();
         }
         catch (Throwable ignored)
         {
         }
      }

      ArrayList<RecordInfo> records = new ArrayList<RecordInfo>();

      List<PreparedTransactionInfo> list = new ArrayList<PreparedTransactionInfo>();

      JournalImpl jrn = new JournalImpl(config.getJournalFileSize(),
                                        2,
                                        0,
                                        0,
                                        new NIOSequentialFileFactory(getJournalDir()),
                                        "hornetq-data",
                                        "hq",
                                        1);
      jrn.start();
      jrn.load(records, list, null);

      // Delete everything from the journal
      for (RecordInfo info : records)
      {
         if (!info.isUpdate)
         {
            jrn.appendDeleteRecord(info.id, false);
         }
      }

      jrn.stop();

      server = createServer(true,
                            config,
                            PagingTest.PAGE_SIZE,
                            PagingTest.PAGE_MAX,
                            new HashMap<String, AddressSettings>());

      server.start();

      Page pg = server.getPagingManager().getPageStore(ADDRESS).getCurrentPage();

      pg.open();

      List<PagedMessage> msgs = pg.read(server.getStorageManager());

      pg.close();

      long queues[] = new long[] { server.locateQueue(new SimpleString("q1")).getID() };

      for (long q : queues)
      {
         for (int i = 0; i < msgs.size(); i++)
         {
            server.getStorageManager().storeCursorAcknowledge(q, new PagePositionImpl(pg.getPageId(), i));
         }
      }

      server.stop();

      ServerLocator locator = createInVMNonHALocator();

      locator.setBlockOnNonDurableSend(true);
      locator.setBlockOnDurableSend(true);
      locator.setBlockOnAcknowledge(true);

      server = createServer(true,
                            config,
                            PagingTest.PAGE_SIZE,
                            PagingTest.PAGE_MAX,
                            new HashMap<String, AddressSettings>());

      server.start();

      ClientSessionFactory csf = locator.createSessionFactory();

      ClientSession sess = csf.createSession();

      sess.start();

      ClientConsumer cons = sess.createConsumer("q1");

      assertNull(cons.receive(500));

      Thread.sleep(5000);

      ClientConsumer cons2 = sess.createConsumer("q2");
      assertNull(cons2.receive(500));

      long timeout = System.currentTimeMillis() + 5000;

      while (System.currentTimeMillis() < timeout && server.getPagingManager().getPageStore(ADDRESS).isPaging())
      {
         Thread.sleep(100);
      }

      assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging());

      sess.close();

      locator.close();

      server.stop();
   }
View Full Code Here


   protected void createQueue(String address, String queue) throws Exception
   {
      ServerLocator locator = createInVMNonHALocator();
      ClientSessionFactory sf = locator.createSessionFactory();
      ClientSession session = sf.createSession();
      session.createQueue(address, queue);
      session.close();
      sf.close();
      locator.close();
   }
View Full Code Here

      {

         server.start();
         ServerLocator locator = createInVMNonHALocator();
         ClientSessionFactory factory = locator.createSessionFactory();
         ClientSession session = factory.createSession(false, false, false);
         HornetQDestination queue = (HornetQDestination)HornetQJMSClient.createQueue("test");
         session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
         session.close();

         HornetQResourceAdapter ra = new HornetQResourceAdapter();

         ra.setConnectorClassName("org.hornetq.core.remoting.impl.invm.InVMConnectorFactory");
         ra.setUserName("userGlobal");
View Full Code Here

                                      final boolean deliveryTransacted,
                                      final boolean useLocalTx,
                                      final Integer txTimeout) throws Exception
   {

      ClientSession result;

      // if we are CMP or BMP using local tx we ignore the ack mode as we are transactional
      if (deliveryTransacted || useLocalTx)
      {
         int actTxBatchSize = transactionBatchSize != null ? transactionBatchSize
View Full Code Here

      setupCF();

      setupDestination();
      for (int i = 0; i < spec.getMaxSession(); i++)
      {
         ClientSession session = null;

         try
         {
            session = setupSession();
            HornetQMessageHandler handler = new HornetQMessageHandler(this, ra.getTM(), (ClientSessionInternal) session, i);
            handler.setup();
            session.start();
            handlers.add(handler);
         }
         catch (Exception e)
         {
            if (session != null)
            {
               session.close();
            }
           
            throw e;
         }
      }
View Full Code Here

    * @return The connection
    * @throws Exception Thrown if an error occurs
    */
   protected ClientSession setupSession() throws Exception
   {
      ClientSession result = null;

      try
      {
         result = ra.createSession(factory.getServerLocator().createSessionFactory(),
                                   spec.getAcknowledgeModeInt(),
                                   spec.getUser(),
                                   spec.getPassword(),
                                   ra.getPreAcknowledge(),
                                   ra.getDupsOKBatchSize(),
                                   ra.getTransactionBatchSize(),
                                   isDeliveryTransacted,
                                   spec.isUseLocalTx(),
                                   spec.getTransactionTimeout());

         result.addMetaData("resource-adapter", "inbound");
         result.addMetaData("jms-session", "");
         if (spec.getClientID() != null)
         {
            result.addMetaData("jms-client-id", spec.getClientID());
         }

         HornetQActivation.log.debug("Using queue connection " + result);

         return result;
      }
      catch (Throwable t)
      {
         try
         {
            if (result != null)
            {
               result.close();
            }
         }
         catch (Exception e)
         {
            HornetQActivation.log.trace("Ignored error closing connection", e);
View Full Code Here

      {
         JMSServerConfigParserImpl parser = new JMSServerConfigParserImpl();
         TopicConfiguration topic = parser.parseTopicConfiguration(document.getDocumentElement());
         HornetQTopic hqTopic = HornetQDestination.createTopic(topic.getName());
         String topicName = hqTopic.getAddress();
         ClientSession session = manager.getSessionFactory().createSession(false, false, false);
         try
         {

            ClientSession.QueueQuery query = session.queueQuery(new SimpleString(topicName));
            if (!query.isExists())
            {
               session.createQueue(topicName, topicName, "__HQX=-1", true);

            }
            else
            {
               throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build());
            }
         }
         finally
         {
            try { session.close(); } catch (Exception ignored) {}
         }
         if (topic.getBindings() != null && topic.getBindings().length > 0 && manager.getRegistry() != null)
         {
            for (String binding : topic.getBindings())
            {
View Full Code Here

         {

         }
      }

      ClientSession session = manager.getSessionFactory().createSession(false, false, false);
      try
      {

         SimpleString topicName = new SimpleString(name);
         ClientSession.QueueQuery query = session.queueQuery(topicName);
         if (query.isExists())
         {
            session.deleteQueue(topicName);
         }
         else
         {
            throw new WebApplicationException(Response.status(405).type("text/plain").entity("Topic '" + name + "' does not exist").build());
         }
      }
      finally
      {
         try { session.close(); } catch (Exception ignored) {}
      }

   }
View Full Code Here

   public TopicResource findTopic(@PathParam("topic-name") String name) throws Exception
   {
      TopicResource topic = topics.get(name);
      if (topic == null)
      {
         ClientSession session = manager.getSessionFactory().createSession(false, false, false);
         try
         {
            ClientSession.QueueQuery query = session.queueQuery(new SimpleString(name));
            if (!query.isExists())
            {
               System.err.println("Topic '" + name + "' does not exist");
               throw new WebApplicationException(Response.status(404).type("text/plain").entity("Topic '" + name + "' does not exist").build());
            }
            DestinationSettings queueSettings = manager.getDefaultSettings();
            boolean defaultDurable = queueSettings.isDurableSend() || query.isDurable();

            topic = createTopicResource(name, defaultDurable, queueSettings.getConsumerSessionTimeoutSeconds(), queueSettings.isDuplicatesAllowed());
         }
         finally
         {
            try
            {
               session.close();
            }
            catch (HornetQException e)
            {
            }
         }
View Full Code Here

      if (!started)
      {
         throw new Exception("You must start() this class instance before deploying");
      }
      String queueName = topicDeployment.getName();
      ClientSession session = sessionFactory.createSession(false, false, false);
      ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
      boolean defaultDurable = topicDeployment.isDurableSend();
      if (query.isExists())
      {
         defaultDurable = query.isDurable();
      }
      else
      {
         session.createQueue(queueName, queueName, topicDeployment.isDurableSend());
      }
      session.close();

      destination.createTopicResource(queueName, defaultDurable, topicDeployment.getConsumerSessionTimeoutSeconds(), topicDeployment.isDuplicatesAllowed());
   }
View Full Code Here

TOP

Related Classes of org.hornetq.api.core.client.ClientSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.