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); } }
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; }
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; }
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; }
public void close(final boolean failed) throws Exception { callback.removeReadyListener(this); setStarted(false); LargeMessageDeliverer del = largeMessageDeliverer; if (del != null) { del.finish(); } if (browseOnly) { browserDeliverer.close(); } else { messageQueue.removeConsumer(this); } session.removeConsumer(id); LinkedList<MessageReference> refs = cancelRefs(failed, false, null); Iterator<MessageReference> iter = refs.iterator(); Transaction tx = new TransactionImpl(storageManager); while (iter.hasNext()) { MessageReference ref = iter.next(); ref.getQueue().cancel(tx, ref); } tx.rollback(); 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.putSimpleStringProperty( ManagementHelper.HDR_FILTERSTRING, filter == null ? null : filter.getFilterString()); props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance()); props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, messageQueue.getConsumerCount()); // HORNETQ-946 props.putSimpleStringProperty( ManagementHelper.HDR_USER, SimpleString.toSimpleString(session.getUsername())); props.putSimpleStringProperty( ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString( ((ServerSessionImpl) session).getRemotingConnection().getRemoteAddress())); props.putSimpleStringProperty( ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(session.getName())); Notification notification = new Notification(null, NotificationType.CONSUMER_CLOSED, props); managementService.sendNotification(notification); } }
private synchronized void activate() throws Exception { if (!started) { return; } if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug( "Activating cluster connection nodeID=" + nodeManager.getNodeId() + " for server=" + this.server); } liveNotifier = new LiveNotifier(); liveNotifier.updateAsLive(); liveNotifier.schedule(); serverLocator = clusterConnector.createServerLocator(); if (serverLocator != null) { if (!useDuplicateDetection) { HornetQServerLogger.LOGGER.debug( "DuplicateDetection is disabled, sending clustered messages blocked"); } final TopologyMember currentMember = topology.getMember(manager.getNodeId()); if (currentMember == null) { // sanity check only throw new IllegalStateException( "InternalError! The ClusterConnection doesn't know about its own node = " + this); } serverLocator.setNodeID(nodeManager.getNodeId().toString()); serverLocator.setIdentity("(main-ClusterConnection::" + server.toString() + ")"); serverLocator.setReconnectAttempts(0); serverLocator.setClusterConnection(true); serverLocator.setClusterTransportConfiguration(connector); serverLocator.setInitialConnectAttempts(-1); serverLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod); serverLocator.setConnectionTTL(connectionTTL); serverLocator.setConfirmationWindowSize(confirmationWindowSize); // if not using duplicate detection, we will send blocked serverLocator.setBlockOnDurableSend(!useDuplicateDetection); serverLocator.setBlockOnNonDurableSend(!useDuplicateDetection); serverLocator.setCallTimeout(callTimeout); serverLocator.setCallFailoverTimeout(callFailoverTimeout); // No producer flow control on the bridges, as we don't want to lock the queues serverLocator.setProducerWindowSize(-1); if (retryInterval > 0) { this.serverLocator.setRetryInterval(retryInterval); } addClusterTopologyListener(this); serverLocator.setAfterConnectionInternalListener(this); serverLocator.start(server.getExecutorFactory().getExecutor()); } if (managementService != null) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(new SimpleString("name"), name); Notification notification = new Notification( nodeManager.getNodeId().toString(), NotificationType.CLUSTER_CONNECTION_STARTED, props); HornetQServerLogger.LOGGER.debug("sending notification: " + notification); managementService.sendNotification(notification); } }
public void createConsumer( final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) 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, supportLargeMessage, credits); 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()); // HORNETQ-946 props.putSimpleStringProperty( ManagementHelper.HDR_USER, SimpleString.toSimpleString(username)); props.putSimpleStringProperty( ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress())); props.putSimpleStringProperty( ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name)); if (filterString != null) { props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString); } Notification notification = new Notification(null, CONSUMER_CREATED, props); if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug( "Session with user="******", connection=" + this.remotingConnection + " created a consumer on queue " + queueName + ", filter = " + filterString); } managementService.sendNotification(notification); } }