/** * Casts the <code>Destination</code> into <code>MessageDestination</code> * and calls super.addDestination. * * @param destination The <code>Destination</code> instance to be added. */ @Override public void addDestination(Destination destination) { MessageDestination messageDestination = (MessageDestination)destination; super.addDestination(messageDestination); }
/** * The default implementation of this method stops all of the destinations * of the service. * If subclasses override, they must call <code>super.stop()</code>. */ public void stop() { if (!isStarted()) { return; } stopDestinations(); super.stop(); // Remove management if (isManaged() && getMessageBroker().isManaged()) { if (getControl() != null) { getControl().unregister(); setControl(null); } setManaged(false); } }
/** * Sets the <code>MessageBroker</code> of the <code>AbstractService</code>. * Removes the <code>AbstractService</code> from the old broker * (if there was one) and adds to the list of services in the new broker. * * @param broker <code>MessageBroker</code> of the <code>AbstractService</code>. */ public void setMessageBroker(MessageBroker broker) { MessageBroker oldBroker = getMessageBroker(); setParent(broker); if (oldBroker != null) { oldBroker.removeService(getId()); } // Add service to the new broker if needed if (broker.getService(getId()) != this) broker.addService(this); }
public void start() if (isStarted()) startDestinations(); return; MessageBroker broker = getMessageBroker(); if (!broker.isStarted()) Log.getLogger(getLogCategory()).warn("Service with id '{0}' cannot be started" + " when the MessageBroker is not started.", new Object[]{getId()}); if (isManaged() && broker.isManaged()) setupServiceControl(broker); MessageBrokerControl controller = (MessageBrokerControl)broker.getControl(); if (getControl() != null) controller.addService(getControl().getObjectName()); startDestinations();
/** * Sets the channel list of the <code>AbstractService</code>. * <code>MessageBroker</code> has to know the channels, otherwise they * are not added to the list. * * @param ids List of channel ids. */ public void setDefaultChannels(List ids) { if (ids != null && isStarted()) { List channelIds = getMessageBroker().getChannelIds(); for (Iterator iter = ids.iterator(); iter.hasNext();) { String id = (String) iter.next(); if (channelIds == null || !channelIds.contains(id)) { iter.remove(); if (Log.isWarn()) { Log.getLogger(getLogCategory()).warn("No channel with id '{0}' is known by the MessageBroker." + " Not adding the channel.", new Object[]{id}); } } } } // Otherwise, channels will be checked before startup defaultChannels = ids; }
/** * Verifies that the <code>AbstractService</code> is in valid state before * it is started. If subclasses override, they must call <code>super.validate()</code>. */ protected void validate() { if (isValid()) return; super.validate(); if (defaultChannels != null) { for (Iterator iter = defaultChannels.iterator(); iter.hasNext();) { String id = (String) iter.next(); if (!getMessageBroker().getChannelIds().contains(id)) { iter.remove(); if (Log.isWarn()) { Log.getLogger(getLogCategory()).warn("Removing the Channel "+id+" from Destination "+getId()+ "as MessageBroker does not know the channel"); } } } } else { defaultChannels = getMessageBroker().getDefaultChannels(); } }
if (getDestination(id) == destination) getMessageBroker().registerDestination(id, getId());
/** * Creates a <code>Destination</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. Note that it cannot have a null id and cannot have an id of * a <code>Destination</code> already registered with the <code>AbstractService</code>. * * @param id The id of the <code>Destination</code>. * @return The <code>Destination</code> instanced created. */ 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); Destination destination = new Destination(); destination.setId(id); destination.setManaged(isManaged()); destination.setService(this); return destination; }
/** * Sets the id of the <code>AbstractService</code>. If the <code>AbstractService</code> * has a <code>MessageBroker</code> assigned, it also updates the id in the * <code>MessageBroker</code>. */ public void setId(String id) { String oldId = getId(); super.setId(id); // Update the service id in the broker MessageBroker broker = getMessageBroker(); if (broker != null) { // broker must have the service then broker.removeService(oldId); broker.addService(this); } }
/** * Removes the <code>Destination</code> from the list of destinations known * by the <code>AbstractService</code>. * * @param id The id of the <code>Destination</code>. * @return Previous <code>Destination</code> associated with the id. */ public Destination removeDestination(String id) { Destination destination = destinations.get(id); if (destination != null) { destination.stop(); destinations.remove(id); getMessageBroker().unregisterDestination(id); } return destination; }
/** * Sets the default adapter of the <code>AbstractService</code>. * * @param id The id of the default adapter. */ public void setDefaultAdapter(String id) { if (adapterClasses.get(id) == null) { // No adapter with id '{0}' is registered with the service '{1}'. ConfigurationException ex = new ConfigurationException(); ex.setMessage(ConfigurationConstants.UNREGISTERED_ADAPTER, new Object[]{id, getId()}); throw ex; } defaultAdapterId = id; }
/** * Returns the <code>MessageBroker</code> of the <code>AbstractService</code>. * * @return MessageBroker of the <code>AbstractService</code>. */ public MessageBroker getMessageBroker() { return (MessageBroker)getParent(); }
/** * Returns the <code>Destination</code> that the <code>Message</code> targets. * * @return The <code>Destination</code> that the <code>Message</code> targets. * @throws <code>MessageException</code> if no such <code>Destination</code> exists. */ public Destination getDestination(Message message) { String id = message.getDestination(); Destination result = getDestination(id); if (result == null) { throw new MessageException ("No destination '" + id + "' exists in service " + getClass().getName()); } return result; }
/** * Creates a <code>Destination</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>Destination</code>. * @return The <code>Destination</code> instanced created. */ public Destination createDestination(String id) { Destination destination = new Destination(); destination.setId(id); destination.setManaged(isManaged()); destination.setService(this); return destination; }
if (isStarted()) startDestinations(); return; MessageBroker broker = getMessageBroker(); if (!broker.isStarted()) Log.getLogger(getLogCategory()).warn("Service with id '{0}' cannot be started" + " when the MessageBroker is not started.", new Object[]{getId()}); if (isManaged() && broker.isManaged()) setupServiceControl(broker); MessageBrokerControl controller = (MessageBrokerControl)broker.getControl(); if (getControl() != null) controller.addService(getControl().getObjectName()); startDestinations();
/** * Sets the channel list of the <code>AbstractService</code>. * <code>MessageBroker</code> has to know the channels, otherwise they * are not added to the list. * * @param ids List of channel ids. */ public void setDefaultChannels(List<String> ids) { if (ids != null && isStarted()) { List<String> channelIds = getMessageBroker().getChannelIds(); for (Iterator<String> iter = ids.iterator(); iter.hasNext();) { String id = iter.next(); if (channelIds == null || !channelIds.contains(id)) { iter.remove(); if (Log.isWarn()) { Log.getLogger(getLogCategory()).warn("No channel with id '{0}' is known by the MessageBroker." + " Not adding the channel.", new Object[]{id}); } } } } // Otherwise, channels will be checked before startup defaultChannels = ids; }
protected void validate() if (isValid()) return; if (!getMessageBroker().getChannelIds().contains(id)) Log.getLogger(getLogCategory()).warn("Removing the Channel "+id+" from Destination "+getId()+ "as MessageBroker does not know the channel"); defaultChannels = getMessageBroker().getDefaultChannels();
if (getDestination(id) == destination) getMessageBroker().registerDestination(id, getId());
/** * Creates a <code>Destination</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. Note that it cannot have a null id and cannot have an id of * a <code>Destination</code> already registered with the <code>AbstractService</code>. * * @param id The id of the <code>Destination</code>. * @return The <code>Destination</code> instanced created. */ 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); Destination destination = new Destination(); destination.setId(id); destination.setManaged(isManaged()); destination.setService(this); return destination; }
/** * Sets the id of the <code>AbstractService</code>. If the <code>AbstractService</code> * has a <code>MessageBroker</code> assigned, it also updates the id in the * <code>MessageBroker</code>. * * @param id the id */ @Override public void setId(String id) { String oldId = getId(); super.setId(id); // Update the service id in the broker MessageBroker broker = getMessageBroker(); if (broker != null) { // broker must have the service then broker.removeService(oldId); broker.addService(this); } }