Author: bpoussin Date: 2010-10-13 16:08:43 +0200 (Wed, 13 Oct 2010) New Revision: 403 Url: http://nuiton.org/repositories/revision/wikitty/403 Log: refactoring de event remote pour permettre l'implantation simple de nouveaux protocoles Added: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java Removed: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java Modified: trunk/wikitty-api/pom.xml trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java Modified: trunk/wikitty-api/pom.xml =================================================================== --- trunk/wikitty-api/pom.xml 2010-10-13 14:05:31 UTC (rev 402) +++ trunk/wikitty-api/pom.xml 2010-10-13 14:08:43 UTC (rev 403) @@ -98,6 +98,11 @@ <artifactId>jgroups</artifactId> </dependency> + <dependency> + <groupId>jivesoftware</groupId> + <artifactId>smackx</artifactId> + </dependency> + </dependencies> <!-- ************************************************************* --> @@ -181,7 +186,15 @@ </execution> </executions> </plugin> - + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> </plugins> </build> Deleted: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java 2010-10-13 14:05:31 UTC (rev 402) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java 2010-10-13 14:08:43 UTC (rev 403) @@ -1,277 +0,0 @@ -/* *##% - * Copyright (C) 2010 Code Lutin, Chatellier Eric - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package org.nuiton.wikitty; - -import java.io.Serializable; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jgroups.Channel; -import org.jgroups.ChannelClosedException; -import org.jgroups.ChannelException; -import org.jgroups.ChannelNotConnectedException; -import org.jgroups.JChannel; -import org.jgroups.Message; -import org.jgroups.ReceiverAdapter; - -/** - * JGroups notifier. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class JGroupsNotifier extends ReceiverAdapter implements WikittyServiceListener { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(JGroupsNotifier.class); - - /** Notifier service reference reference. */ - protected WikittyServiceNotifier ws; - - /** Message type (put, remove, clear...). */ - static enum WikittyJGroupType { - PUT_WIKITTY, - REMOVE_WIKITTY, - CLEAR_WIKITTY, - PUT_EXTENSION, - REMOVE_EXTENSION, - CLEAR_EXTENSION - } - - static class WikittyJGroupMessage implements Serializable { - /** serialVersionUID. */ - private static final long serialVersionUID = 1914969328584238081L; - - public WikittyJGroupType type; - public WikittyServiceEvent event; - - private WikittyJGroupMessage(WikittyJGroupType type, WikittyServiceEvent event) { - this.type = type; - this.event = event; - } - - public String toString() { - String toString = type + " " + event; - return toString; - } - } - - /** - * Indique si les objects sont propages (true) vers les autres caches ou - * simplement supprimes des autres caches (false). - * - * @see WikittyServiceCached#WIKITTY_PROPAGATE_CACHE_OPTION - */ - protected boolean propagateCache = false; - - /** JGroup channel. */ - protected JChannel channel; - - public JGroupsNotifier(WikittyServiceNotifier ws, String channelName, boolean propagateCache) { - this.ws = ws; - this.propagateCache = propagateCache; - initChannel(channelName); - } - - /** - * Init jgroup channel. - * - * @param channelName channel name - */ - protected void initChannel(String channelName) { - if (log.isDebugEnabled()) { - log.debug("Init jgroup communication channel..."); - } - - try { - // use default udp.xml in classpath - channel = new JChannel(); - channel.setReceiver(this); - - // don't receive messages sent by myself - channel.setOpt(Channel.LOCAL, false); - - channel.connect(channelName); - - if (log.isInfoEnabled()) { - log.info("JGroup communication channel initialized to " - + channel.getAddressAsString() + " (" - + channel.getClusterName() + ")"); - log.info("Channel view: " + channel.getView()); - } - } catch (ChannelException eee) { - if (log.isErrorEnabled()) { - log.error("Can't init jgroup channel", eee); - } - } - } - - /** - * Send a jgroup message to all other channel member. - * - * @param wikittyMessage message to send - */ - protected void sendJGroupMessage(WikittyJGroupMessage wikittyMessage) { - if (log.isInfoEnabled()) { - log.info("Send message : " + wikittyMessage); - } - - Message msg = new Message(null, null, wikittyMessage); - try { - channel.send(msg); - } catch (ChannelNotConnectedException eee) { - if (log.isErrorEnabled()) { - log.error("Can't send jgroup message", eee); - } - } catch (ChannelClosedException eee) { - if (log.isErrorEnabled()) { - log.error("Can't send jgroup message", eee); - } - } - } - - /* - * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message) - */ - @Override - public void receive(Message msg) { - - Object message = msg.getObject(); - - if (log.isInfoEnabled()) { - log.info("Receive message : " + msg.getObject()); - } - - if (message instanceof WikittyJGroupMessage) { - WikittyJGroupMessage wikittyMessage = (WikittyJGroupMessage)message; - WikittyJGroupType type = wikittyMessage.type; - WikittyServiceEvent event = wikittyMessage.event; - - //source is transient, add it here : - event.setSource(ws); - event.setRemote(true); // received event became remote - - switch(type) { - case PUT_WIKITTY: - ws.firePutWikitty(event); break; - case REMOVE_WIKITTY: - ws.fireRemoveWikitty(event); break; - case CLEAR_WIKITTY: - ws.fireClearWikitty(event); break; - case PUT_EXTENSION: - ws.firePutExtension(event); break; - case REMOVE_EXTENSION: - ws.fireRemoveExtension(event); break; - case CLEAR_EXTENSION: - ws.fireClearExtension(event); break; - default: - if (log.isDebugEnabled()) { - log.debug("Not managed jgroup message " + wikittyMessage.type); - } - } - } - } - - /* - * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[]) - */ - @Override - public void putWikitty(WikittyServiceEvent event) { - if (propagateCache) { - sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.PUT_WIKITTY, event)); - } else { - if (log.isDebugEnabled()) { - log.debug("Not master cache, do not propagate putWikitty event"); - } - } - } - - /* - * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[]) - */ - @Override - public void removeWikitty(WikittyServiceEvent event) { - if (propagateCache) { - sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.REMOVE_WIKITTY, event)); - } else { - if (log.isDebugEnabled()) { - log.debug("Not master cache, do not propagate removeWikitty event"); - } - } - } - - /* - * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty() - */ - @Override - public void clearWikitty(WikittyServiceEvent event) { - if (propagateCache) { - sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.CLEAR_WIKITTY, event)); - } else { - if (log.isDebugEnabled()) { - log.debug("Not master cache, do not propagate clearWikitty event"); - } - } - } - - /* - * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[]) - */ - @Override - public void putExtension(WikittyServiceEvent event) { - if (propagateCache) { - sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.PUT_EXTENSION, event)); - } else { - if (log.isDebugEnabled()) { - log.debug("Not master cache, do not propagate putExtension event"); - } - } - } - - /* - * @see org.nuiton.wikitty.WikittyServiceListener#removeExtension(java.lang.String[]) - */ - @Override - public void removeExtension(WikittyServiceEvent event) { - if (propagateCache) { - sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.REMOVE_EXTENSION, event)); - } else { - if (log.isDebugEnabled()) { - log.debug("Not master cache, do not propagate removeExtension event"); - } - } - } - - /* - * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension() - */ - @Override - public void clearExtension(WikittyServiceEvent event) { - if (propagateCache) { - sendJGroupMessage(new WikittyJGroupMessage(WikittyJGroupType.CLEAR_EXTENSION, event)); - } else { - if (log.isDebugEnabled()) { - log.debug("Not master cache, do not propagate clearExtension event"); - } - } - } -} Copied: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java (from rev 398, trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifier.java) =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java (rev 0) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/JGroupsNotifierTransporter.java 2010-10-13 14:08:43 UTC (rev 403) @@ -0,0 +1,161 @@ +/* *##% + * Copyright (C) 2010 Code Lutin, Chatellier Eric + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.nuiton.wikitty; + +import java.util.Properties; +import org.apache.commons.lang.StringUtils; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jgroups.Channel; +import org.jgroups.ChannelException; +import org.jgroups.JChannel; +import org.jgroups.Message; +import org.jgroups.ReceiverAdapter; + +/** + * JGroups notifier. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class JGroupsNotifierTransporter extends ReceiverAdapter + implements WikittyServiceNotifier.RemoteNotifierTransporter { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class); + + /** + * Utilisation du canal de communication basé sur jgroups avec + * comme identifiant d'application le nom de canal en option. + * + * Si ce nom est vide, jgroups n'est pas utilisé. + * Si {@link #WIKITTY_EVENT_PROPAGATE_OPTION} est a true et que cette + * options est vide, une exception est levée. + */ + static public final String WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION = "wikitty.service.event.jgroupschannelname"; + + /** Notifier service reference reference. */ + protected WikittyServiceNotifier ws; + + + /** JGroup channel. */ + protected JChannel channel; + + public JGroupsNotifierTransporter(WikittyServiceNotifier ws, Properties props) { + this.ws = ws; + + // can be null according to default constructor + if (props != null) { + // add notifier as listener + String jgroupChannel = props.getProperty(WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION); + if (!StringUtils.isBlank(jgroupChannel)) { + initChannel(jgroupChannel); + } else { + throw new IllegalArgumentException("Can't use propagate cache without a valid jgroups channel name !!!"); + } + } + } + + /** + * Init jgroup channel. + * + * @param channelName channel name + */ + protected void initChannel(String channelName) { + if (log.isDebugEnabled()) { + log.debug("Init jgroup communication channel..."); + } + + try { + // use default udp.xml in classpath + channel = new JChannel(); + channel.setReceiver(this); + + // don't receive messages sent by myself + channel.setOpt(Channel.LOCAL, false); + + channel.connect(channelName); + + if (log.isInfoEnabled()) { + log.info("JGroup communication channel initialized to " + + channel.getAddressAsString() + " (" + + channel.getClusterName() + ")"); + log.info("Channel view: " + channel.getView()); + } + } catch (ChannelException eee) { + throw new WikittyException("Can't initialize jgroup channel", eee); + } + } + + /** + * Send a jgroup message to all other channel member. + * + * @param event message to send + */ + @Override + public void sendMessage(WikittyServiceEvent event) throws Exception { + Message msg = new Message(null, null, event); + channel.send(msg); + } + + /* + * @see org.jgroups.ReceiverAdapter#receive(org.jgroups.Message) + */ + @Override + public void receive(Message msg) { + + Object message = msg.getObject(); + + if (log.isInfoEnabled()) { + log.info("Receive message : " + message); + } + + if (message instanceof WikittyServiceEvent) { + WikittyServiceEvent event = (WikittyServiceEvent)message; + + //source is transient, add it here : + event.setSource(ws); + event.setRemote(true); // received event became remote + + switch(event.type) { + case PUT_WIKITTY: + ws.firePutWikitty(event); break; + case REMOVE_WIKITTY: + ws.fireRemoveWikitty(event); break; + case CLEAR_WIKITTY: + ws.fireClearWikitty(event); break; + case PUT_EXTENSION: + ws.firePutExtension(event); break; + case REMOVE_EXTENSION: + ws.fireRemoveExtension(event); break; + case CLEAR_EXTENSION: + ws.fireClearExtension(event); break; + default: + if (log.isDebugEnabled()) { + log.debug("Not managed jgroup message " + event.type); + } + } + } + } + +} Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-13 14:05:31 UTC (rev 402) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceEvent.java 2010-10-13 14:08:43 UTC (rev 403) @@ -44,9 +44,23 @@ /** serialVersionUID. */ private static final long serialVersionUID = 9017732163643700599L; + /** Message type (put, remove, clear...). */ + static public enum WikittyEventType { + PUT_WIKITTY, + REMOVE_WIKITTY, + CLEAR_WIKITTY, + PUT_EXTENSION, + REMOVE_EXTENSION, + CLEAR_EXTENSION + } + + /** Remote event (received from jgroup). */ protected boolean remote; + /** event type */ + protected WikittyEventType type; + /** * Id managed by event. * @@ -73,8 +87,9 @@ * * @param source wikitty service */ - public WikittyServiceEvent(Object source) { + public WikittyServiceEvent(Object source, WikittyEventType type) { super(source); + this.type = type; } /** Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-13 14:05:31 UTC (rev 402) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-13 14:08:43 UTC (rev 403) @@ -26,10 +26,11 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; +import org.apache.commons.beanutils.ConstructorUtils; -import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ListenerSet; /** @@ -48,31 +49,6 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(WikittyServiceNotifier.class); - /** - * Utilisation du canal de communication basé sur jgroups avec - * comme identifiant d'application le nom de canal en option. - * - * Si ce nom est vide, jgroups n'est pas utilisé. - * Si {@link #WIKITTY_EVENT_PROPAGATE_OPTION} est a true et que cette - * options est vide, une exception est levée. - */ - static public final String WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION = "wikitty.service.event.jgroupschannelname"; - - /** - * Indique si les objects sont propages (true) vers les autres caches ou - * simplement supprimes des autres caches (false). Default to {@code false}. - */ - static public final String WIKITTY_EVENT_PROPAGATE_OPTION = "wikitty.service.event.propagateEvent"; - - /** - * Indique si les evenement sont propagés aux autres listener. Sinon on est - * juste listener des evenements recus. C'est pourquoi le listener - * {@link #notifier} doit toujours être ajouté. - * - * @see WikittyServiceNotifier#WIKITTY_EVENT_PROPAGATE_OPTION - */ - protected boolean propagateCache = false; - /** Service to delegate. */ protected WikittyService ws; @@ -111,41 +87,11 @@ allWikittyServiceListeners = new ListenerSet<WikittyServiceListener>(); localWikittyServiceListeners = new ListenerSet<WikittyServiceListener>(); remoteWikittyServiceListeners = new ListenerSet<WikittyServiceListener>(); - - addJGroupNotifier(props); - } - /** - * Add jgroup listener if enabled by configuration. - * - * @param props properties (can be null) - */ - protected void addJGroupNotifier(Properties props) { - // can be null according to default constructor if (props != null) { - - // get propagate cache property - String propagateCacheOption = props.getProperty(WIKITTY_EVENT_PROPAGATE_OPTION, "false"); - propagateCache = "true".equalsIgnoreCase(propagateCacheOption); - if (log.isDebugEnabled()) { - log.debug("Set propagateCache option to " + propagateCache); - } - - // add notifier as listener - String jgroupChannel = props.getProperty(WIKITTY_EVENT_JGROUPCHANNELNAME_OPTION); - if (!StringUtils.isBlank(jgroupChannel)) { - notifier = new JGroupsNotifier(this, jgroupChannel, propagateCache); - addWikittyServiceListener(notifier, ServiceListenerType.ALL); // weak reference - } - else if (propagateCache) { - throw new IllegalArgumentException("Can't use propagate cache without a valid jgroups channel name !!!"); - } - else if (log.isDebugEnabled()) { - log.debug("JGroup synchronisation channel not used "); - } + notifier = new RemoteNotifier(this, props); } - } @Override @@ -443,7 +389,8 @@ * @param ws data */ protected void firePutWikitty(Wikitty... ws) { - WikittyServiceEvent event = new WikittyServiceEvent(ws); + WikittyServiceEvent event = new WikittyServiceEvent(ws, + WikittyServiceEvent.WikittyEventType.PUT_WIKITTY); Set<String> ids = new HashSet<String>(); Map<String, Set<String>> idsExtension = new HashMap<String, Set<String>>(); Map<String, String> idsVersion = new HashMap<String, String>(); @@ -471,7 +418,8 @@ * @param wikittyIds wikitty ids */ protected void fireRemoveWikitty(String... wikittyIds) { - WikittyServiceEvent event = new WikittyServiceEvent(ws); + WikittyServiceEvent event = new WikittyServiceEvent(ws, + WikittyServiceEvent.WikittyEventType.REMOVE_WIKITTY); Set<String> ids = new HashSet<String>(); for (String wikittyId : wikittyIds) { @@ -487,7 +435,8 @@ * Build event to fire and call {@link #fireClearWikitty(WikittyServiceEvent)}. */ protected void fireClearWikitty() { - WikittyServiceEvent event = new WikittyServiceEvent(ws); + WikittyServiceEvent event = new WikittyServiceEvent(ws, + WikittyServiceEvent.WikittyEventType.CLEAR_WIKITTY); fireClearWikitty(event); } @@ -497,7 +446,8 @@ * @param ws data */ protected void firePutExtension(WikittyExtension... exts) { - WikittyServiceEvent event = new WikittyServiceEvent(ws); + WikittyServiceEvent event = new WikittyServiceEvent(ws, + WikittyServiceEvent.WikittyEventType.PUT_EXTENSION); Set<String> ids = new HashSet<String>(); Map<String, Set<String>> idsExtension = new HashMap<String, Set<String>>(); @@ -525,7 +475,8 @@ * @param ws data */ protected void fireRemoveExtension(WikittyExtension... exts) { - WikittyServiceEvent event = new WikittyServiceEvent(ws); + WikittyServiceEvent event = new WikittyServiceEvent(ws, + WikittyServiceEvent.WikittyEventType.REMOVE_EXTENSION); Set<String> ids = new HashSet<String>(); for (WikittyExtension ext : exts) { @@ -543,7 +494,8 @@ * @param ws data */ protected void fireClearExtension() { - WikittyServiceEvent event = new WikittyServiceEvent(ws); + WikittyServiceEvent event = new WikittyServiceEvent(ws, + WikittyServiceEvent.WikittyEventType.CLEAR_EXTENSION); fireClearExtension(event); } @@ -744,4 +696,189 @@ }; eventThread.start(); } + + /** + * This interface must be implemented to send and received remote message. + * Only sendMessage method is in interface but you must write receive + * method too, but this method is protocol specific and can't appear in + * interface + */ + static public interface RemoteNotifierTransporter { + + /** + * Send a jgroup message to all other channel member. + * + * @param event message to send + */ + public void sendMessage(WikittyServiceEvent event) throws Exception; + } + + /** + * Class used to notify remote listener. This class is realy activate + * only if wikitty.notifier.transporter.class configuration is found and + * wikitty.service.event.propagateEvent is true + */ + static public class RemoteNotifier implements WikittyServiceListener { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(JGroupsNotifierTransporter.class); + /** + * Indique si les objects sont propages (true) vers les autres caches ou + * simplement supprimes des autres caches (false). Default to {@code false}. + */ + static public final String WIKITTY_EVENT_PROPAGATE_OPTION = "wikitty.service.event.propagateEvent"; + /** notifier class name in configuration that this service must used */ + static final public String WIKITTY_NOTIFIER_TRANSPORTER_CLASS = "wikitty.notifier.transporter.class"; + + /** Notifier service reference reference. */ + protected WikittyServiceNotifier ws; + /** + * Indique si les objects sont propages (true) vers les autres caches ou + * simplement supprimes des autres caches (false). + * + * @see WikittyServiceCached#WIKITTY_PROPAGATE_CACHE_OPTION + */ + protected boolean propagateEvent = false; + protected RemoteNotifierTransporter transporter; + + public RemoteNotifier(WikittyServiceNotifier ws, Properties props) { + // can be null according to default constructor + if (props != null) { + this.ws = ws; + + if (!props.containsKey(WIKITTY_NOTIFIER_TRANSPORTER_CLASS)) { + props.setProperty(WIKITTY_NOTIFIER_TRANSPORTER_CLASS, JGroupsNotifierTransporter.class.getName()); + } + ApplicationConfig config = new ApplicationConfig(props); + propagateEvent = config.getOptionAsBoolean(WIKITTY_EVENT_PROPAGATE_OPTION); + if (log.isDebugEnabled()) { + log.debug("Set propagateEvent option to " + propagateEvent); + } + + if (propagateEvent) { + try { + Class transporterClass = config.getOptionAsClass( + WIKITTY_NOTIFIER_TRANSPORTER_CLASS); + transporter = (RemoteNotifierTransporter) ConstructorUtils.invokeConstructor(transporterClass, new Object[]{this, props}); + } catch (Exception eee) { + throw new WikittyException("Can't create notifier: " + + config.getOption(WIKITTY_NOTIFIER_TRANSPORTER_CLASS), eee); + } + + // add this as listener when transporter is created without error + ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference + } + } + if (transporter == null && log.isDebugEnabled()) { + log.debug("RemoteNotifier synchronisation not used "); + } + } + + /** + * Send a jgroup message to all other channel member. + * + * @param event message to send + */ + protected void sendMessage(WikittyServiceEvent event) { + try { + if (log.isInfoEnabled()) { + log.info("Try to send message : " + event); + } + + transporter.sendMessage(event); + + if (log.isInfoEnabled()) { + log.info("message send" + event); + } + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't send message", eee); + } + } + } + + /* + * @see org.nuiton.wikitty.WikittyServiceListener#putWikitty(org.nuiton.wikitty.Wikitty[]) + */ + @Override + public void putWikitty(WikittyServiceEvent event) { + if (propagateEvent) { + sendMessage(event); + } else { + if (log.isDebugEnabled()) { + log.debug("Not master cache, do not propagate putWikitty event"); + } + } + } + + /* + * @see org.nuiton.wikitty.WikittyServiceListener#removeWikitty(java.lang.String[]) + */ + @Override + public void removeWikitty(WikittyServiceEvent event) { + if (propagateEvent) { + sendMessage(event); + } else { + if (log.isDebugEnabled()) { + log.debug("Not master cache, do not propagate removeWikitty event"); + } + } + } + + /* + * @see org.nuiton.wikitty.WikittyServiceListener#clearWikitty() + */ + @Override + public void clearWikitty(WikittyServiceEvent event) { + if (propagateEvent) { + sendMessage(event); + } else { + if (log.isDebugEnabled()) { + log.debug("Not master cache, do not propagate clearWikitty event"); + } + } + } + + /* + * @see org.nuiton.wikitty.WikittyServiceListener#putExtension(org.nuiton.wikitty.WikittyExtension[]) + */ + @Override + public void putExtension(WikittyServiceEvent event) { + if (propagateEvent) { + sendMessage(event); + } else { + if (log.isDebugEnabled()) { + log.debug("Not master cache, do not propagate putExtension event"); + } + } + } + + /* + * @see org.nuiton.wikitty.WikittyServiceListener#removeExtension(java.lang.String[]) + */ + @Override + public void removeExtension(WikittyServiceEvent event) { + if (propagateEvent) { + sendMessage(event); + } else { + if (log.isDebugEnabled()) { + log.debug("Not master cache, do not propagate removeExtension event"); + } + } + } + + /* + * @see org.nuiton.wikitty.WikittyServiceListener#clearExtension() + */ + @Override + public void clearExtension(WikittyServiceEvent event) { + if (propagateEvent) { + sendMessage(event); + } else { + if (log.isDebugEnabled()) { + log.debug("Not master cache, do not propagate clearExtension event"); + } + } + } + } }
participants (1)
-
bpoussin@users.nuiton.org