/** * Issue messages to request the remote subscription table from each server in the cluster (except this one). */ public void initRemoteSubscriptions(String destinationId) { ClusterManager clm = getMessageBroker().getClusterManager(); String serviceType = getClass().getName(); MessageDestination dest = (MessageDestination) getDestination(destinationId); Cluster cluster = clm.getCluster(serviceType, destinationId); if (cluster != null) cluster.addRemoveNodeListener(dest.getRemoteSubscriptionManager()); List members = clm.getClusterMemberAddresses(serviceType, destinationId); for (int i = 0; i < members.size(); i++) { Object addr = members.get(i); if (!clm.getLocalAddress(serviceType, destinationId).equals(addr)) requestSubscriptions(destinationId, addr); } }
if (isManaged()) MessageDestination destination = (MessageDestination)getDestination(message.getDestination()); if (destination != null && destination.isManaged()) pushMessageToClients(message, false); sendPushMessageFromPeer(message, false); pushMessageToClients(subscriberIds, message, false);
/** * */ @Override public Object serviceCommand(CommandMessage message) { if (managed) incrementMessageCount(true, message); Object commandResult = super.serviceCommonCommands(message); if (commandResult == null) commandResult = manageSubscriptions(message); return commandResult; }
/** * Send the passed message to clients connected to other server peer nodes in the cluster. * If you are using broadcast cluster-messaging-routing mode, the message is broadcast * through the cluster. If you are using the server-to-server mode, the message is sent only * to servers from which we have received a matching subscription request. * * @param message The <code>Message</code> to push to peer server nodes in the cluster. * @param evalSelector <code>true</code> to evaluate each remote subscriber's selector * before pushing the message to them; <code>false</code> to skip selector evaluation. */ public void sendPushMessageFromPeer(Message message, boolean evalSelector) { sendPushMessageFromPeer(message, (MessageDestination)getDestination(message), evalSelector); }
/** * This method is not invoked across a cluster, it is always locally invoked. * The passed message will be pushed to the subscribers in the passed set, conditionally depending * upon the execution of their selector expressions. * * @param subscriberIds The set of subscribers to push the message to. * * @param message The <code>Message</code> to push. * * @param evalSelector <code>true</code> to evaluate each subscriber's selector before pushing * the message to them; <code>false</code> to skip selector evaluation. */ public void pushMessageToClients(Set subscriberIds, Message message, boolean evalSelector) { MessageDestination destination = (MessageDestination)getDestination(message); pushMessageToClients(destination, subscriberIds, message, evalSelector); }
MessageDestination destination = (MessageDestination)getDestination(command); SubscriptionManager subscriptionManager = destination.getSubscriptionManager(); getMessageBroker().inspectChannel(command, destination); testSelector(selectorExpr, command); int maxFrequency = processMaxFrequencyHeader(command); subscriptionManager.addSubscriber(clientId, selectorExpr, subtopicString, endpointId, maxFrequency); getMessageBroker().inspectChannel(command, destination); Object[] adds = getObjectArrayFromHeader(command.getHeader(CommandMessage.ADD_SUBSCRIPTIONS)); Object[] rems = getObjectArrayFromHeader(command.getHeader(CommandMessage.REMOVE_SUBSCRIPTIONS)); int maxFrequency = processMaxFrequencyHeader(command); for (int i = 0; i < adds.length; i++) if (missedMessages != null && !missedMessages.isEmpty()) MessageBroker broker = getMessageBroker(); for (Iterator iter = missedMessages.iterator(); iter.hasNext();) broker.routeMessageToMessageClient((Message)iter.next(), client);
incrementMessageCount(false, message); dest = (MessageDestination)getDestination(message); ThrottleManager throttleManager = dest.getThrottleManager(); if (throttleManager != null && throttleManager.throttleIncomingMessage(message)) dest = (MessageDestination)getDestination(message); Subtopic subtopic = testProducerSubtopic(dest.getServerSettings().getSubtopicSeparator(), subtopicString); if (subtopics == null) subtopics = new ArrayList<Subtopic>(); dest = (MessageDestination)getDestination(message); subtopicSeperator = dest.getServerSettings().getSubtopicSeparator(); Subtopic subtopic = testProducerSubtopic(subtopicSeperator, subtopicString); if (subtopics == null) subtopics = new ArrayList<Subtopic>(); dest = (MessageDestination)getDestination(message); ServerSettings destServerSettings = dest.getServerSettings(); if (destServerSettings.getMessageTTL() >= 0) Log.getLogger(TIMING_LOG_CATEGORY).debug("After invoke service: " + getId() + "; execution time = " + (end - start) + "ms");
public void start() ClusterManager clm = getMessageBroker().getClusterManager(); MessageDestination dest = (MessageDestination) getDestination(destName); if (!dest.getServerSettings().isBroadcastRoutingMode() && dest.isClustered()) initRemoteSubscriptions(destName); MessageDestination dest = (MessageDestination) getDestination(destName); if (!dest.getServerSettings().isBroadcastRoutingMode() && dest.isClustered())
/** * Handle a data message intended for this adapter. */ public Object invoke(Message message) { MessageService msgService = (MessageService)getDestination().getService(); msgService.pushMessageToClients(message, true); msgService.sendPushMessageFromPeer(message, true); return null; }
MessageDestination destination = (MessageDestination)getDestination(message.getDestination()); if (destination != null && destination.isManaged()) pushMessageToClients(message, false); sendPushMessageFromPeer(message, false); pushMessageToClients(subscriberIds, message, false);
if (filterSender && headers.containsKey(FlexHeaders.FLEX_CLIENT_ID)) { Set<Object> subscribers = new HashSet<Object>(this.subscriberIds); FlexClient flexClient = messageService.getMessageBroker().getFlexClientManager().getFlexClient(headers.get(FlexHeaders.FLEX_CLIENT_ID).toString()); for (Object subscriberId : this.subscriberIds) { if (flexClient.getMessageClient(subscriberId.toString()) != null) { messageService.pushMessageToClients(subscribers, flexMessage, true); } else { messageService.pushMessageToClients(flexMessage, true); messageService.sendPushMessageFromPeer(flexMessage, true);
MessageDestination destination = (MessageDestination) getDestination(message); ClusterManager clm = getMessageBroker().getClusterManager(); if (destination.getServerSettings().isBroadcastRoutingMode())
/** * This method is provided for a clustered messaging with the routing-mode set to point-to-point. * On startup, a server invokes this method for each server to request its local subscription state. * * */ public void requestSubscriptions(String destinationId, Object remoteAddress) { ClusterManager clm = getMessageBroker().getClusterManager(); clm.invokePeerToPeerOperation(getClass().getName(), destinationId, ClusterManager.OPERATION_SEND_SUBSCRIPTIONS, new Object[] { destinationId }, remoteAddress); }
/** * Creates a <code>MessageDestination</code> instance, sets its id, sets it manageable * if the <code>AbstractService</code> that created it is manageable, * and sets its <code>Service</code> to the <code>AbstractService</code> that * created it. * * @param id The id of the <code>MessageDestination</code>. * @return The <code>Destination</code> instanced created. */ @Override public Destination createDestination(String id) { if (id == null) { // Cannot add ''{0}'' with null id to the ''{1}'' ConfigurationException ex = new ConfigurationException(); ex.setMessage(ConfigurationConstants.NULL_COMPONENT_ID, new Object[]{"Destination", "Service"}); throw ex; } // check with the message broker to make sure that no destination with the id already exists getMessageBroker().isDestinationRegistered(id, getId(), true); MessageDestination destination = new MessageDestination(); destination.setId(id); destination.setManaged(isManaged()); destination.setService(this); return destination; }
/** * @exclude * This method is provided for a cluster peer broadcast, it is not intended to be * invoked locally. */ public void pushMessageFromPeer(AsyncMessage message, Boolean evalSelector) { if (!isStarted()) { Log.getLogger(LOG_CATEGORY).debug("Received message from peer server before server is started - ignoring: " + message + " evalSelector: " + evalSelector); return; } if (Log.isDebug()) Log.getLogger(LOG_CATEGORY).debug("Received message from peer server: " + message + " evalSelector: " + evalSelector); // Update the FlexContext for this thread to indicate we're processing a message from // a server peer. FlexContext.setMessageFromPeer(true); // we are not confirming that replication is enabled again here, so if the remote // peer has replication enabled and therefore broadcast to this peer, then this peer // will complete the operation even if it locally does not have replication enabled pushMessageToClients(message, evalSelector.booleanValue()); // And unset. FlexContext.setMessageFromPeer(false); }
/** * Returns the set of subscribers for the specified destination, subtopic/subtopic pattern * and message headers. The message headers can be null. If specified, they are used * to match against any selector patterns that were used for subscribers. */ public Set getSubscriberIds(String destinationId, String subtopicPattern, Map messageHeaders) { MessageDestination destination = (MessageDestination) getDestination(destinationId); SubscriptionManager subscriptionManager = destination.getSubscriptionManager(); return subscriptionManager.getSubscriberIds(subtopicPattern, messageHeaders); }
/** * Pushes the supplied message and then invalidates the MessageClient. * * @param message The message to push to the client before invalidating. * When message is null, MessageClient is invalidated silently. */ public void invalidate(Message message) { if (message != null) { message.setDestination(destination.getId()); message.setClientId(clientId); Set subscriberIds = new TreeSet(); subscriberIds.add(clientId); try { ((MessageService)destination.getService()).pushMessageToClients(destination, subscriberIds, message, false /* don't eval selector */); } catch (MessageException ignore) {} invalidate(true /* attempt to notify remote client */); } else { invalidate(); } }
/** * Used to increment the message count metric for the <code>MessageService</code>. This value is * stored in the corresponding MBean. The <code>MessageService</code> already invokes this method * in its <code>serviceMessage()</code> and <code>serviceCommand()</code> implementations, but if * a subclass overrides these methods completely it should invoke this method appropriately as * it processes messages. * * @param commandMessage Pass <code>true</code> if the message being processed is a <code>CommandMessage</code>; * otherwise <code>false</code>. */ protected void incrementMessageCount(boolean commandMessage, Message message) { // Update management metrics. if (isManaged()) { MessageDestination destination = (MessageDestination)getDestination(message.getDestination()); if (destination != null && destination.isManaged()) { MessageDestinationControl destinationControl = (MessageDestinationControl)destination.getControl(); if (destinationControl != null) // Should not happen but just in case. { if (commandMessage) destinationControl.incrementServiceCommandCount(); else destinationControl.incrementServiceMessageCount(); } } } }
/** * Creates a <code>MessageDestination</code> instance, sets its id, sets it manageable * if the <code>AbstractService</code> that created it is manageable, * and sets its <code>Service</code> to the <code>AbstractService</code> that * created it. * * @param id The id of the <code>MessageDestination</code>. * @return The <code>Destination</code> instanced created. */ public Destination createDestination(String id) { MessageDestination destination = new MessageDestination(); destination.setId(id); destination.setManaged(isManaged()); destination.setService(this); return destination; }
MessageDestination destination = (MessageDestination)getDestination(command); SubscriptionManager subscriptionManager = destination.getSubscriptionManager(); getMessageBroker().inspectChannel(command, destination); testSelector(selectorExpr, command); int maxFrequency = processMaxFrequencyHeader(command); subscriptionManager.addSubscriber(clientId, selectorExpr, subtopicString, endpointId, maxFrequency); getMessageBroker().inspectChannel(command, destination); Object[] adds = getObjectArrayFromHeader(command.getHeader(CommandMessage.ADD_SUBSCRIPTIONS)); Object[] rems = getObjectArrayFromHeader(command.getHeader(CommandMessage.REMOVE_SUBSCRIPTIONS)); int maxFrequency = processMaxFrequencyHeader(command); for (int i = 0; i < adds.length; i++) if (missedMessages != null && !missedMessages.isEmpty()) MessageBroker broker = getMessageBroker(); for (Iterator iter = missedMessages.iterator(); iter.hasNext();) broker.routeMessageToMessageClient((Message)iter.next(), client);