예제 #1
0
  public synchronized void stop() {
    if (!started) {
      return;
    }

    if (!paused) {
      InVMRegistry.instance.unregisterAcceptor(id);
    }

    for (Connection connection : connections.values()) {
      listener.connectionDestroyed(connection.getID());
    }

    connections.clear();

    if (notificationService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(
          new SimpleString("factory"), new SimpleString(InVMAcceptorFactory.class.getName()));
      props.putIntProperty(new SimpleString("id"), id);
      Notification notification = new Notification(null, NotificationType.ACCEPTOR_STOPPED, props);
      try {
        notificationService.sendNotification(notification);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    started = false;

    paused = false;
  }
예제 #2
0
  public void stop() throws Exception {
    if (!started) {
      return;
    }
    stopping = true;
    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug(this + "::stopping ClusterConnection");
    }

    if (serverLocator != null) {
      serverLocator.removeClusterTopologyListener(this);
    }

    HornetQServerLogger.LOGGER.debug(
        "Cluster connection being stopped for node"
            + nodeManager.getNodeId()
            + ", server = "
            + this.server
            + " serverLocator = "
            + serverLocator);

    synchronized (this) {
      for (MessageFlowRecord record : records.values()) {
        try {
          record.close();
        } catch (Exception ignore) {
        }
      }
    }

    if (managementService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(new SimpleString("name"), name);
      Notification notification =
          new Notification(
              nodeManager.getNodeId().toString(),
              NotificationType.CLUSTER_CONNECTION_STOPPED,
              props);
      managementService.sendNotification(notification);
    }
    executor.execute(
        new Runnable() {
          public void run() {
            synchronized (ClusterConnectionImpl.this) {
              closeLocator(serverLocator);
              serverLocator = null;
            }
          }
        });

    started = false;
  }
예제 #3
0
  public Message putTypedProperties(final TypedProperties otherProps) {
    properties.putTypedProperties(otherProps);

    bufferValid = false;

    return this;
  }
예제 #4
0
  public Message putStringProperty(final SimpleString key, final SimpleString value) {
    properties.putSimpleStringProperty(key, value);

    bufferValid = false;

    return this;
  }
예제 #5
0
  @Override
  public Message putCharProperty(String key, char value) {
    properties.putCharProperty(new SimpleString(key), value);
    bufferValid = false;

    return this;
  }
예제 #6
0
  public Message putBytesProperty(final String key, final byte[] value) {
    properties.putBytesProperty(new SimpleString(key), value);

    bufferValid = false;

    return this;
  }
예제 #7
0
  public Message putObjectProperty(final SimpleString key, final Object value)
      throws HornetQPropertyConversionException {
    TypedProperties.setObjectProperty(key, value, properties);
    bufferValid = false;

    return this;
  }
예제 #8
0
  public Message putDoubleProperty(final String key, final double value) {
    properties.putDoubleProperty(new SimpleString(key), value);

    bufferValid = false;

    return this;
  }
예제 #9
0
  public Message putStringProperty(final String key, final String value) {
    properties.putSimpleStringProperty(new SimpleString(key), SimpleString.toSimpleString(value));

    bufferValid = false;

    return this;
  }
예제 #10
0
 @Override
 public double getDoubleProperty(String name) {
   try {
     return properties.getDoubleProperty(new SimpleString(name));
   } catch (HornetQPropertyConversionException ce) {
     throw new MessageFormatRuntimeException(ce.getMessage());
   }
 }
예제 #11
0
 @Override
 public JMSProducer setProperty(String name, String value) {
   checkName(name);
   SimpleString key = new SimpleString(name);
   properties.putSimpleStringProperty(key, new SimpleString(value));
   stringPropertyNames.add(key);
   return this;
 }
예제 #12
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;
  }
예제 #13
0
 @Override
 public JMSProducer clearProperties() {
   try {
     stringPropertyNames.clear();
     properties.clear();
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
   return this;
 }
예제 #14
0
 @Override
 public boolean getBooleanProperty(String name) {
   try {
     return properties.getBooleanProperty(new SimpleString(name));
   } catch (HornetQPropertyConversionException ce) {
     throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
 }
예제 #15
0
  public synchronized void start() throws Exception {
    if (started) {
      return;
    }

    InVMRegistry.instance.registerAcceptor(id, this);

    if (notificationService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(
          new SimpleString("factory"), new SimpleString(InVMAcceptorFactory.class.getName()));
      props.putIntProperty(new SimpleString("id"), id);
      Notification notification = new Notification(null, NotificationType.ACCEPTOR_STARTED, props);
      notificationService.sendNotification(notification);
    }

    started = true;

    paused = false;
  }
예제 #16
0
  public void createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly)
      throws Exception {
    Binding binding = postOffice.getBinding(queueName);

    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
      throw HornetQMessageBundle.BUNDLE.noSuchQueue(queueName);
    }

    securityStore.check(binding.getAddress(), CheckType.CONSUME, this);

    Filter filter = FilterImpl.createFilter(filterString);

    ServerConsumer consumer =
        new ServerConsumerImpl(
            consumerID,
            this,
            (QueueBinding) binding,
            filter,
            started,
            browseOnly,
            storageManager,
            callback,
            preAcknowledge,
            strictUpdateDeliveryCount,
            managementService);

    consumers.put(consumer.getID(), consumer);

    if (!browseOnly) {
      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

      props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

      props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

      Queue theQueue = (Queue) binding.getBindable();

      props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

      if (filterString != null) {
        props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
      }

      Notification notification = new Notification(null, CONSUMER_CREATED, props);

      managementService.sendNotification(notification);
    }
  }
예제 #17
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());
   }
 }
예제 #18
0
 @Override
 public JMSProducer setProperty(String name, Object value) {
   checkName(name);
   try {
     TypedProperties.setObjectProperty(new SimpleString(name), value, properties);
   } catch (HornetQPropertyConversionException hqe) {
     throw new MessageFormatRuntimeException(hqe.getMessage());
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
   return this;
 }
예제 #19
0
    private synchronized void doConsumerCreated(final ClientMessage message) throws Exception {
      if (HornetQServerLogger.LOGGER.isTraceEnabled()) {
        HornetQServerLogger.LOGGER.trace(
            ClusterConnectionImpl.this + " Consumer created " + message);
      }
      if (!message.containsProperty(ManagementHelper.HDR_DISTANCE)) {
        throw new IllegalStateException("distance is null");
      }

      if (!message.containsProperty(ManagementHelper.HDR_CLUSTER_NAME)) {
        throw new IllegalStateException("clusterName is null");
      }

      Integer distance = message.getIntProperty(ManagementHelper.HDR_DISTANCE);

      SimpleString clusterName = message.getSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME);

      message.putIntProperty(ManagementHelper.HDR_DISTANCE, distance + 1);

      SimpleString filterString =
          message.getSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING);

      RemoteQueueBinding binding = bindings.get(clusterName);

      if (binding == null) {
        throw new IllegalStateException(
            "Cannot find binding for " + clusterName + " on " + ClusterConnectionImpl.this);
      }

      binding.addConsumer(filterString);

      // Need to propagate the consumer add
      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

      props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, clusterName);

      props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance + 1);

      Queue theQueue = (Queue) binding.getBindable();

      props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

      if (filterString != null) {
        props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
      }

      Notification notification = new Notification(null, CONSUMER_CREATED, props);

      managementService.sendNotification(notification);
    }
예제 #20
0
 @Override
 public Object getObjectProperty(String name) {
   try {
     SimpleString key = new SimpleString(name);
     Object property = properties.getProperty(key);
     if (stringPropertyNames.contains(key)) {
       property = property.toString();
     }
     return property;
   } catch (HornetQPropertyConversionException ce) {
     throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
     throw new JMSRuntimeException(e.getMessage());
   }
 }
예제 #21
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());
    }
  }
예제 #22
0
 public int getHeadersAndPropertiesEncodeSize() {
   return DataConstants.SIZE_LONG
       + // Message ID
       DataConstants.SIZE_BYTE
       + // user id null?
       (userID == null ? 0 : 16)
       +
       /* address */ SimpleString.sizeofNullableString(address)
       + DataConstants./* Type */ SIZE_BYTE
       + DataConstants./* Durable */ SIZE_BOOLEAN
       + DataConstants./* Expiration */ SIZE_LONG
       + DataConstants./* Timestamp */ SIZE_LONG
       + DataConstants./* Priority */ SIZE_BYTE
       +
       /* PropertySize and Properties */ properties.getEncodeSize();
 }
예제 #23
0
 public void encodeHeadersAndProperties(final HornetQBuffer buffer) {
   buffer.writeLong(messageID);
   buffer.writeNullableSimpleString(address);
   if (userID == null) {
     buffer.writeByte(DataConstants.NULL);
   } else {
     buffer.writeByte(DataConstants.NOT_NULL);
     buffer.writeBytes(userID.asBytes());
   }
   buffer.writeByte(type);
   buffer.writeBoolean(durable);
   buffer.writeLong(expiration);
   buffer.writeLong(timestamp);
   buffer.writeByte(priority);
   properties.encode(buffer);
 }
예제 #24
0
 public Response receive(final Proposal proposal, final int distance) throws Exception {
   TypedProperties props = new TypedProperties();
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());
   props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
   props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
   props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
   Notification notification = new Notification(null, NotificationType.PROPOSAL, props);
   managementService.sendNotification(notification);
   return null;
 }
예제 #25
0
 public void decodeHeadersAndProperties(final HornetQBuffer buffer) {
   messageID = buffer.readLong();
   address = buffer.readNullableSimpleString();
   if (buffer.readByte() == DataConstants.NOT_NULL) {
     byte[] bytes = new byte[16];
     buffer.readBytes(bytes);
     userID = new UUID(UUID.TYPE_TIME_BASED, bytes);
   } else {
     userID = null;
   }
   type = buffer.readByte();
   durable = buffer.readBoolean();
   expiration = buffer.readLong();
   timestamp = buffer.readLong();
   priority = buffer.readByte();
   properties.decode(buffer);
 }
예제 #26
0
  public Response propose(final Proposal proposal) throws Exception {
    // sanity check in case it is already selected
    Response response = responses.get(proposal.getGroupId());
    if (response != null) {
      return response;
    }

    try {
      lock.lock();

      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());

      props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, 0);

      Notification notification = new Notification(null, NotificationType.PROPOSAL, props);

      managementService.sendNotification(notification);

      if (!sendCondition.await(timeout, TimeUnit.MILLISECONDS))
        HornetQLogger.LOGGER.groupHandlerSendTimeout();
      response = responses.get(proposal.getGroupId());

    } finally {
      lock.unlock();
    }
    if (response == null) {
      throw new IllegalStateException(
          "no response received from group handler for " + proposal.getGroupId());
    }
    return response;
  }
예제 #27
0
 public Object getObjectProperty(final String key) {
   return properties.getProperty(new SimpleString(key));
 }
예제 #28
0
 public boolean containsProperty(final String key) {
   return properties.containsProperty(new SimpleString(key));
 }
예제 #29
0
 public Set<SimpleString> getPropertyNames() {
   return properties.getPropertyNames();
 }
예제 #30
0
  public Object removeProperty(final String key) {
    bufferValid = false;

    return properties.removeProperty(new SimpleString(key));
  }