Example #1
0
  @Test
  public void testGetQueueNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString anotherQueue = RandomUtil.randomSimpleString();

    session.createQueue(address, queue, true);

    AddressControl addressControl = createManagementControl(address);
    String[] queueNames = addressControl.getQueueNames();
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(queue.toString(), queueNames[0]);

    session.createQueue(address, anotherQueue, false);
    queueNames = addressControl.getQueueNames();
    Assert.assertEquals(2, queueNames.length);

    session.deleteQueue(queue);

    queueNames = addressControl.getQueueNames();
    Assert.assertEquals(1, queueNames.length);
    Assert.assertEquals(anotherQueue.toString(), queueNames[0]);

    session.deleteQueue(anotherQueue);
  }
Example #2
0
  @Test
  public void testGetBindingNames() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    String divertName = RandomUtil.randomString();

    session.createQueue(address, queue, false);

    AddressControl addressControl = createManagementControl(address);
    String[] bindingNames = addressControl.getBindingNames();
    assertEquals(1, bindingNames.length);
    assertEquals(queue.toString(), bindingNames[0]);

    server
        .getHornetQServerControl()
        .createDivert(
            divertName,
            randomString(),
            address.toString(),
            RandomUtil.randomString(),
            false,
            null,
            null);

    bindingNames = addressControl.getBindingNames();
    Assert.assertEquals(2, bindingNames.length);

    session.deleteQueue(queue);

    bindingNames = addressControl.getBindingNames();
    assertEquals(1, bindingNames.length);
    assertEquals(divertName.toString(), bindingNames[0]);
  }
Example #3
0
  @Test
  public void testGetNumberOfBytesPerPage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createQueue(address, address, true);

    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(
        HornetQDefaultConfiguration.getDefaultJournalFileSize(),
        addressControl.getNumberOfBytesPerPage());

    session.close();
    server.stop();

    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setPageSizeBytes(1024);

    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    addServerLocator(locator2);
    ClientSessionFactory sf2 = createSessionFactory(locator2);

    session = sf2.createSession(false, true, false);
    session.createQueue(address, address, true);
    Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
  }
  public Destination getJMSDestination() throws JMSException {
    if (dest == null) {
      SimpleString sdest = message.getAddress();

      dest = sdest == null ? null : HornetQDestination.fromAddress(sdest.toString());
    }

    return dest;
  }
Example #5
0
  public String getStringProperty(final SimpleString key)
      throws HornetQPropertyConversionException {
    SimpleString str = getSimpleStringProperty(key);

    if (str == null) {
      return null;
    } else {
      return str.toString();
    }
  }
  public Destination getJMSReplyTo() throws JMSException {
    if (replyTo == null) {
      SimpleString repl = message.getSimpleStringProperty(HornetQMessage.REPLYTO_HEADER_NAME);

      if (repl != null) {
        replyTo = HornetQDestination.fromAddress(repl.toString());
      }
    }
    return replyTo;
  }
  public String getJMSType() throws JMSException {
    if (jmsType == null) {
      SimpleString ss = message.getSimpleStringProperty(HornetQMessage.TYPE_HEADER_NAME);

      if (ss != null) {
        jmsType = ss.toString();
      }
    }
    return jmsType;
  }
  public void setStringProperty(final String name, final String value) throws JMSException {
    checkProperty(name, value);

    if (HornetQMessage.JMSXGROUPID.equals(name)) {
      message.putStringProperty(
          org.hornetq.api.core.Message.HDR_GROUP_ID, SimpleString.toSimpleString(value));
    } else {
      message.putStringProperty(new SimpleString(name), SimpleString.toSimpleString(value));
    }
  }
  /**
   * deploy an element
   *
   * @param node the element to deploy
   * @throws Exception .
   */
  @Override
  public void deploy(final Node node) throws Exception {
    CoreQueueConfiguration queueConfig = parser.parseQueueConfiguration(node);

    server.deployQueue(
        SimpleString.toSimpleString(queueConfig.getAddress()),
        SimpleString.toSimpleString(queueConfig.getName()),
        SimpleString.toSimpleString(queueConfig.getFilterString()),
        queueConfig.isDurable(),
        false);
  }
Example #10
0
 /**
  * Returns the ObjectName used by QueueControl.
  *
  * @see QueueControl
  */
 public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name)
     throws Exception {
   return ObjectName.getInstance(
       String.format(
           "%s:module=%s,type=%s,address=%s,name=%s",
           domain,
           ObjectNameBuilder.CORE_MODULE,
           "Queue",
           ObjectName.quote(address.toString()),
           ObjectName.quote(name.toString())));
 }
Example #11
0
 @Override
 public String getStringProperty(String name) {
   try {
     SimpleString prop = properties.getSimpleStringProperty(new SimpleString(name));
     if (prop == null) return null;
     return prop.toString();
   } catch (HornetQPropertyConversionException ce) {
     throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
 }
 /** {@inheritDoc} */
 @Override
 public void mapFrom(ClientMessage source, Context context) throws Exception {
   for (SimpleString key : source.getPropertyNames()) {
     String name = key.toString();
     if (matches(name)) {
       Object value = source.getObjectProperty(key);
       if (value != null) {
         // HornetQ ClientMessage properties -> Context EXCHANGE properties
         context.setProperty(name, value, EXCHANGE).addLabels(HORNETQ_MESSAGE_PROPERTY);
       }
     }
   }
 }
Example #13
0
  @Test
  public void testGetAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();

    session.createQueue(address, queue, false);

    AddressControl addressControl = createManagementControl(address);

    Assert.assertEquals(address.toString(), addressControl.getAddress());

    session.deleteQueue(queue);
  }
Example #14
0
  @Override
  public Set<String> getPropertyNames() {
    try {
      Set<String> propNames = new HashSet<String>();

      for (SimpleString str : properties.getPropertyNames()) {
        propNames.add(str.toString());
      }
      return propNames;
    } catch (HornetQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
    } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
    }
  }
Example #15
0
  public Enumeration getPropertyNames() throws JMSException {
    HashSet<String> set = new HashSet<String>();

    for (SimpleString propName : message.getPropertyNames()) {
      if (!propName.startsWith(HornetQMessage.JMS)
          || propName.startsWith(HornetQMessage.JMSX)
          || propName.startsWith(HornetQMessage.JMS_)) {
        set.add(propName.toString());
      }
    }

    set.add(HornetQMessage.JMSXDELIVERYCOUNT);

    return Collections.enumeration(set);
  }
Example #16
0
 /**
  * returns the size of a SimpleString which could be null
  *
  * @param str the SimpleString to check
  * @return the size
  */
 public static int sizeofNullableString(final SimpleString str) {
   if (str == null) {
     return 1;
   } else {
     return 1 + str.sizeof();
   }
 }
Example #17
0
  private void receiveMessages() throws Exception {
    ClientSession session = sf.createSession(true, true);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int i = 0; i < numMessages; i++) {
      ClientMessage message = consumer.receive(100);
      assertNotNull("Expecting a message " + i, message);
      assertMessageBody(i, message);
      assertEquals(i, message.getIntProperty("int").intValue());
      assertEquals((short) i, message.getShortProperty("short").shortValue());
      assertEquals((byte) i, message.getByteProperty("byte").byteValue());
      assertEquals(floatValue(i), message.getFloatProperty("float").floatValue(), 0.001);
      assertEquals(
          new SimpleString(Integer.toString(i)),
          message.getSimpleStringProperty(SIMPLE_STRING_KEY.toString()));
      assertEqualsByteArrays(byteArray(i), message.getBytesProperty("byte[]"));

      assertTrue(message.containsProperty("null-value"));
      assertEquals(message.getObjectProperty("null-value"), null);

      message.acknowledge();
    }
    assertNull("no more messages", consumer.receive(50));
    consumer.close();
    session.commit();
  }
Example #18
0
  public Object[] getRoles() throws Exception {
    clearIO();
    try {
      Set<Role> roles = securityRepository.getMatch(address.toString());

      Object[] objRoles = new Object[roles.size()];

      int i = 0;
      for (Role role : roles) {
        objRoles[i++] =
            new Object[] {
              role.getName(),
              CheckType.SEND.hasRole(role),
              CheckType.CONSUME.hasRole(role),
              CheckType.CREATE_DURABLE_QUEUE.hasRole(role),
              CheckType.DELETE_DURABLE_QUEUE.hasRole(role),
              CheckType.CREATE_NON_DURABLE_QUEUE.hasRole(role),
              CheckType.DELETE_NON_DURABLE_QUEUE.hasRole(role),
              CheckType.MANAGE.hasRole(role)
            };
      }
      return objRoles;
    } finally {
      blockOnIO();
    }
  }
Example #19
0
  public Message putStringProperty(final String key, final String value) {
    properties.putSimpleStringProperty(new SimpleString(key), SimpleString.toSimpleString(value));

    bufferValid = false;

    return this;
  }
Example #20
0
  public QueueQueryResult executeQueueQuery(final SimpleString name) throws Exception {
    if (name == null) {
      throw HornetQMessageBundle.BUNDLE.queueNameIsNull();
    }

    QueueQueryResult response;

    Binding binding = postOffice.getBinding(name);

    if (binding != null && binding.getType() == BindingType.LOCAL_QUEUE) {
      Queue queue = (Queue) binding.getBindable();

      Filter filter = queue.getFilter();

      SimpleString filterString = filter == null ? null : filter.getFilterString();

      response =
          new QueueQueryResult(
              name,
              binding.getAddress(),
              queue.isDurable(),
              queue.isTemporary(),
              filterString,
              queue.getConsumerCount(),
              queue.getMessageCount());
    }
    // make an exception for the management address (see HORNETQ-29)
    else if (name.equals(managementAddress)) {
      response = new QueueQueryResult(name, managementAddress, true, false, null, -1, -1);
    } else {
      response = new QueueQueryResult();
    }

    return response;
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = super.hashCode();
   result = prime * result + ((queueName == null) ? 0 : queueName.hashCode());
   return result;
 }
Example #22
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    configuration = createDefaultConfig();
    configuration.setSecurityEnabled(false);
    server = createServer(true, configuration);
    // start the server
    server.start();

    qs = new AddressSettings();
    qs.setLastValueQueue(true);
    server.getAddressSettingsRepository().addMatch(address.toString(), qs);
    // then we create a client as normal
    locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));

    locator.setBlockOnAcknowledge(true);
    locator.setAckBatchSize(0);
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    clientSession = sessionFactory.createSession(false, true, true);
    clientSessionXa = sessionFactory.createSession(true, false, false);
    clientSession.createQueue(address, qName1, null, true);
  }
Example #23
0
 public String getLastSentMessageID(String address) {
   Pair<UUID, AtomicLong> value = targetAddressInfos.get(SimpleString.toSimpleString(address));
   if (value != null) {
     return value.getA().toString();
   } else {
     return null;
   }
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = super.hashCode();
   result = prime * result + ((address == null) ? 0 : address.hashCode());
   result = prime * result + credits;
   return result;
 }
Example #25
0
  public void clearProperties() throws JMSException {
    List<SimpleString> toRemove = new ArrayList<SimpleString>();

    for (SimpleString propName : message.getPropertyNames()) {
      if (!propName.startsWith(HornetQMessage.JMS)
          || propName.startsWith(HornetQMessage.JMSX)
          || propName.startsWith(HornetQMessage.JMS_)) {
        toRemove.add(propName);
      }
    }

    for (SimpleString propName : toRemove) {
      message.removeProperty(propName);
    }

    propertiesReadOnly = false;
  }
  public void testCreateAndDestroyQueueWithEmptyStringForFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    String filter = "";
    boolean durable = true;

    HornetQServerControl serverControl = createManagementControl();

    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));

    serverControl.createQueue(address.toString(), name.toString(), filter, durable);

    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));
    QueueControl queueControl =
        ManagementControlHelper.createQueueControl(address, name, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());

    serverControl.destroyQueue(name.toString());

    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name));
  }
Example #27
0
  public Map<String, Object> toMap() {
    Map<String, Object> map = new HashMap<String, Object>();

    map.put("messageID", messageID);
    if (userID != null) {
      map.put("userID", "ID:" + userID.toString());
    }
    map.put("address", address.toString());
    map.put("type", type);
    map.put("durable", durable);
    map.put("expiration", expiration);
    map.put("timestamp", timestamp);
    map.put("priority", priority);
    for (SimpleString propName : properties.getPropertyNames()) {
      map.put(propName.toString(), properties.getProperty(propName));
    }
    return map;
  }
Example #28
0
  public void addSubscription(
      long consumerID,
      String subscriptionID,
      String clientID,
      String durableSubscriptionName,
      String destination,
      String selector,
      String ack)
      throws Exception {
    SimpleString queue = SimpleString.toSimpleString(destination);
    int receiveCredits = consumerCredits;
    if (ack.equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) {
      receiveCredits = -1;
    }

    if (destination.startsWith("jms.topic")) {
      // subscribes to a topic
      if (durableSubscriptionName != null) {
        if (clientID == null) {
          throw BUNDLE.missingClientID();
        }
        queue = SimpleString.toSimpleString(clientID + "." + durableSubscriptionName);
        QueueQueryResult query = session.executeQueueQuery(queue);
        if (!query.isExists()) {
          session.createQueue(
              SimpleString.toSimpleString(destination),
              queue,
              SimpleString.toSimpleString(selector),
              false,
              true);
        }
      } else {
        queue = UUIDGenerator.getInstance().generateSimpleStringUUID();
        session.createQueue(
            SimpleString.toSimpleString(destination),
            queue,
            SimpleString.toSimpleString(selector),
            true,
            false);
      }
      ((ServerSessionImpl) session)
          .createConsumer(consumerID, queue, null, false, false, receiveCredits);
    } else {
      ((ServerSessionImpl) session)
          .createConsumer(
              consumerID,
              queue,
              SimpleString.toSimpleString(selector),
              false,
              false,
              receiveCredits);
    }

    StompSubscription subscription = new StompSubscription(subscriptionID, ack);
    subscriptions.put(consumerID, subscription);

    session.start();
  }
Example #29
0
  @Override
  public boolean equals(final Object other) {
    if (other instanceof DisconnectMessage == false) {
      return false;
    }

    DisconnectMessage r = (DisconnectMessage) other;

    return super.equals(other) && nodeID.equals(r.nodeID);
  }
Example #30
0
  @Test
  public void testGetRolesAsJSON() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    Role role =
        new Role(
            RandomUtil.randomString(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomBoolean());

    session.createQueue(address, queue, true);

    AddressControl addressControl = createManagementControl(address);
    String jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    RoleInfo[] roles = RoleInfo.from(jsonString);
    Assert.assertEquals(0, roles.length);

    Set<Role> newRoles = new HashSet<Role>();
    newRoles.add(role);
    server.getSecurityRepository().addMatch(address.toString(), newRoles);

    jsonString = addressControl.getRolesAsJSON();
    Assert.assertNotNull(jsonString);
    roles = RoleInfo.from(jsonString);
    Assert.assertEquals(1, roles.length);
    RoleInfo r = roles[0];
    Assert.assertEquals(role.getName(), roles[0].getName());
    Assert.assertEquals(role.isSend(), r.isSend());
    Assert.assertEquals(role.isConsume(), r.isConsume());
    Assert.assertEquals(role.isCreateDurableQueue(), r.isCreateDurableQueue());
    Assert.assertEquals(role.isDeleteDurableQueue(), r.isDeleteDurableQueue());
    Assert.assertEquals(role.isCreateNonDurableQueue(), r.isCreateNonDurableQueue());
    Assert.assertEquals(role.isDeleteNonDurableQueue(), r.isDeleteNonDurableQueue());
    Assert.assertEquals(role.isManage(), r.isManage());

    session.deleteQueue(queue);
  }