On Fri, Jul 24, 2009 at 2:31 PM, indika kumara <[email protected]>wrote:
> What about Extension Interface design Patten [1].It is a proven > pattern that used to address different challenges and issues in > interface design such as adaptability, Stability, Versioning, > Extensibility, Special purpose usage, etc... Thanks for the pointer Indika. I'll definitely look into this. May be for the moment we can have a simple abstract implementation of the interface and then later further improve the code by implementing the extension interface pattern. Thanks, Hiranya > > > If you need to added new component - some main abstraction related > with synapse, same as proxy, sequence, even sources, etc. You can make > event notification related into that abstraction into a new interface > and then only any client that needs those events have to implement > that interface. > > Anyway, I am not against for currently suggested approach. > > [1] http://www.laputan.org/pub/sag/extension-interface.pdf > > Indika > > On Fri, Jul 24, 2009 at 12:37 PM, Andreas > Veithen<[email protected]> wrote: > > Sounds like a very useful feature. Can you also add an > > AbstractSynapseObserver that implements SynapseObserver with default > > (empty) implementations for all the methods? By recommending to extend > > this class instead of implementing SynapseObserver directly, we can > > easily add new methods later without breaking existing observer > > implementations. > > > > Thanks, > > > > Andreas > > > > On Fri, Jul 24, 2009 at 08:24, <[email protected]> wrote: > >> Author: hiranya > >> Date: Fri Jul 24 06:24:06 2009 > >> New Revision: 797333 > >> > >> URL: http://svn.apache.org/viewvc?rev=797333&view=rev > >> Log: > >> Adding the SynapseObserver interface. Implementations of this interface > can be used to monitor a SynapseConfiguration instance at runtime. A > SynapseObserver instance registered with a SynapseConfiguration receives > events regarding configuration updates (add/remove items). Useful when > writing custom configuration monitors, dependency trackers etc. > >> > >> Added: > >> > > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseObserver.java > >> Modified: > >> > > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java > >> > >> Modified: > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java > >> URL: > http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=797333&r1=797332&r2=797333&view=diff > >> > ============================================================================== > >> --- > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java > (original) > >> +++ > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java > Fri Jul 24 06:24:06 2009 > >> @@ -118,6 +118,10 @@ > >> */ > >> private Map<String, SynapseEventSource> eventSources = new > HashMap<String, SynapseEventSource>(); > >> > >> + /** > >> + * The list of registered configuration observers > >> + */ > >> + private List<SynapseObserver> observers = new > ArrayList<SynapseObserver>(); > >> > >> /** > >> * Add a named sequence into the local registry. If a sequence > already exists by the specified > >> @@ -131,6 +135,10 @@ > >> public void addSequence(String key, Mediator mediator) { > >> assertAlreadyExists(key,SEQUENCE); > >> localRegistry.put(key, mediator); > >> + > >> + for (SynapseObserver o : observers) { > >> + o.sequenceAdded(mediator); > >> + } > >> } > >> > >> /** > >> @@ -254,6 +262,9 @@ > >> Object sequence = localRegistry.get(key); > >> if (sequence instanceof Mediator) { > >> localRegistry.remove(key); > >> + for (SynapseObserver o : observers) { > >> + o.sequenceRemoved((Mediator) sequence); > >> + } > >> } else { > >> handleException("No sequence exists by the key/name : " + > key); > >> } > >> @@ -302,12 +313,18 @@ > >> > entry.setValue(SynapseConfigUtils.getOMElementFromURL(entry.getSrc() > >> .toString())); > >> localRegistry.put(key, entry); > >> + for (SynapseObserver o : observers) { > >> + o.entryAdded(entry); > >> + } > >> } catch (IOException e) { > >> handleException("Can not read from source URL : " > >> + entry.getSrc()); > >> } > >> } else { > >> localRegistry.put(key, entry); > >> + for (SynapseObserver o : observers) { > >> + o.entryAdded(entry); > >> + } > >> } > >> } > >> > >> @@ -421,6 +438,9 @@ > >> Object entry = localRegistry.get(key); > >> if (entry instanceof Entry) { > >> localRegistry.remove(key); > >> + for (SynapseObserver o : observers) { > >> + o.entryRemoved((Entry) entry); > >> + } > >> } else { > >> handleException("No entry exists by the key : " + key); > >> } > >> @@ -467,6 +487,9 @@ > >> public void addEndpoint(String key, Endpoint endpoint) { > >> assertAlreadyExists(key, ENDPOINT); > >> localRegistry.put(key, endpoint); > >> + for (SynapseObserver o : observers) { > >> + o.endpointAdded(endpoint); > >> + } > >> } > >> > >> /** > >> @@ -568,6 +591,9 @@ > >> Object endpoint = localRegistry.get(key); > >> if (endpoint instanceof Endpoint) { > >> localRegistry.remove(key); > >> + for (SynapseObserver o : observers) { > >> + o.endpointRemoved((Endpoint) endpoint); > >> + } > >> } else { > >> handleException("No endpoint exists by the key/name : " + > key); > >> } > >> @@ -585,6 +611,9 @@ > >> public void addProxyService(String name, ProxyService proxy) { > >> if (!proxyServices.containsKey(name)) { > >> proxyServices.put(name, proxy); > >> + for (SynapseObserver o : observers) { > >> + o.proxyServiceAdded(proxy); > >> + } > >> } else { > >> handleException("Duplicate proxy service by the name : " + > name); > >> } > >> @@ -609,8 +638,8 @@ > >> * of the Proxy Service to be deleted > >> */ > >> public void removeProxyService(String name) { > >> - Object o = proxyServices.get(name); > >> - if (o == null) { > >> + ProxyService proxy = proxyServices.get(name); > >> + if (proxy == null) { > >> handleException("Unknown proxy service for name : " + name); > >> } else { > >> try { > >> @@ -623,6 +652,9 @@ > >> getAxisConfiguration().removeService(name); > >> } > >> proxyServices.remove(name); > >> + for (SynapseObserver o : observers) { > >> + o.proxyServiceRemoved(proxy); > >> + } > >> } catch (AxisFault axisFault) { > >> handleException(axisFault.getMessage()); > >> } > >> @@ -759,6 +791,9 @@ > >> public void addStartup(Startup startup) { > >> if (!startups.containsKey(startup.getName())) { > >> startups.put(startup.getName(), startup); > >> + for (SynapseObserver o : observers) { > >> + o.startupAdded(startup); > >> + } > >> } else { > >> handleException("Duplicate startup by the name : " + > startup.getName()); > >> } > >> @@ -771,8 +806,12 @@ > >> * @param name - name of the startup that needs to be removed > >> */ > >> public void removeStartup(String name) { > >> - if (startups.containsKey(name)) { > >> + Startup startup = startups.get(name); > >> + if (startup != null) { > >> startups.remove(name); > >> + for (SynapseObserver o : observers) { > >> + o.startupRemoved(startup); > >> + } > >> } else { > >> handleException("No startup exists by the name : " + name); > >> } > >> @@ -1000,6 +1039,9 @@ > >> public void addEventSource(String name, SynapseEventSource > eventSource) { > >> if (!eventSources.containsKey(name)) { > >> eventSources.put(name, eventSource); > >> + for (SynapseObserver o : observers) { > >> + o.eventSourceAdded(eventSource); > >> + } > >> } else { > >> handleException("Duplicate event source by the name : " + > name); > >> } > >> @@ -1016,8 +1058,12 @@ > >> * @param name name of the event source to be removed > >> */ > >> public void removeEventSource(String name) { > >> - if (eventSources.containsKey(name)) { > >> + SynapseEventSource eventSource = eventSources.get(name); > >> + if (eventSource != null) { > >> eventSources.remove(name); > >> + for (SynapseObserver o : observers) { > >> + o.eventSourceRemoved(eventSource); > >> + } > >> } else { > >> handleException("No event source exists by the name : " + > name); > >> } > >> @@ -1031,6 +1077,12 @@ > >> this.eventSources = eventSources; > >> } > >> > >> + public void registerObserver(SynapseObserver o) { > >> + if (!observers.contains(o)) { > >> + observers.add(o); > >> + } > >> + } > >> + > >> private void assertAlreadyExists(String key, String type) { > >> > >> if (key == null || "".equals(key)) { > >> > >> Added: > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseObserver.java > >> URL: > http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseObserver.java?rev=797333&view=auto > >> > ============================================================================== > >> --- > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseObserver.java > (added) > >> +++ > synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseObserver.java > Fri Jul 24 06:24:06 2009 > >> @@ -0,0 +1,107 @@ > >> +/* > >> + * Licensed to the Apache Software Foundation (ASF) under one > >> + * or more contributor license agreements. See the NOTICE file > >> + * distributed with this work for additional information > >> + * regarding copyright ownership. The ASF licenses this file > >> + * to you under the Apache License, Version 2.0 (the > >> + * "License"); you may not use this file except in compliance > >> + * with the License. You may obtain a copy of the License at > >> + * > >> + * http://www.apache.org/licenses/LICENSE-2.0 > >> + * > >> + * Unless required by applicable law or agreed to in writing, > >> + * software distributed under the License is distributed on an > >> + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > >> + * KIND, either express or implied. See the License for the > >> + * specific language governing permissions and limitations > >> + * under the License. > >> + */ > >> + > >> +package org.apache.synapse.config; > >> + > >> +import org.apache.synapse.Mediator; > >> +import org.apache.synapse.Startup; > >> +import org.apache.synapse.eventing.SynapseEventSource; > >> +import org.apache.synapse.core.axis2.ProxyService; > >> +import org.apache.synapse.endpoints.Endpoint; > >> + > >> +/** > >> + * An implementation of this interface can be registered with the > SynapseConfiguration to receive > >> + * configuration update events. Whenever a new item is added to the > configuration or an existing > >> + * item is removed the events defined in this interface will be fired. > >> + */ > >> +public interface SynapseObserver { > >> + > >> + /** Event fired when a new sequence is added to the configuration > >> + * > >> + * @param sequence the Sequence mediator added to the configuration > >> + */ > >> + public void sequenceAdded(Mediator sequence); > >> + > >> + /** Event fired when an existing sequence is removed from the > configuration > >> + * > >> + * @param sequence the Sequence removed from the configuration > >> + */ > >> + public void sequenceRemoved(Mediator sequence); > >> + > >> + /** Event fired when an entry is added to the configuration > >> + * > >> + * @param entry the Entry added to the configuration > >> + */ > >> + public void entryAdded(Entry entry); > >> + > >> + /** Event fired when an entry is removed from the configuration > >> + * > >> + * @param entry the Entry removed from the configuration > >> + */ > >> + public void entryRemoved(Entry entry); > >> + > >> + /** Event fired when an endpoint is added to the configuration > >> + * > >> + * @param endpoint the Endpoint added to the configuration > >> + */ > >> + public void endpointAdded(Endpoint endpoint); > >> + > >> + /** Event fired when an endpoint is removed from the configuration > >> + * > >> + * @param endpoint the Endpoint removed from the configuration > >> + */ > >> + public void endpointRemoved(Endpoint endpoint); > >> + > >> + /** Event fired when a proxy service is added to the configuration > >> + * > >> + * @param proxy the ProxyService added to the configuration > >> + */ > >> + public void proxyServiceAdded(ProxyService proxy); > >> + > >> + /** Event fired when a proxy service is removed from the > configuration > >> + * > >> + * @param proxy the ProxyService removed from the configuration > >> + */ > >> + public void proxyServiceRemoved(ProxyService proxy); > >> + > >> + /** Event fired when a startup is added to the configuration > >> + * > >> + * @param startup the Startup added to the configuration > >> + */ > >> + public void startupAdded(Startup startup); > >> + > >> + /** Event fired when a startup is removed from the configuration > >> + * > >> + * @param startup the Startup removed from the configuration > >> + */ > >> + public void startupRemoved(Startup startup); > >> + > >> + /** Event fired when an event source is added to the configuration > >> + * > >> + * @param eventSource the SynapseEventSource added to the > configuration > >> + */ > >> + public void eventSourceAdded(SynapseEventSource eventSource); > >> + > >> + /** Event fired when an event source is removed from the > configuration > >> + * > >> + * @param eventSource the SynapseEventSource removed from the > configuration > >> + */ > >> + public void eventSourceRemoved(SynapseEventSource eventSource); > >> + > >> +} > >> > >> > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- Hiranya Jayathilaka Software Engineer; WSO2 Inc.; http://wso2.org E-mail: [email protected]; Mobile: +94 77 633 3491 Blog: http://techfeast-hiranya.blogspot.com
