r413 - trunk/wikitty-api/src/main/java/org/nuiton/wikitty
Author: sletellier Date: 2010-10-15 14:02:05 +0200 (Fri, 15 Oct 2010) New Revision: 413 Url: http://nuiton.org/repositories/revision/wikitty/413 Log: - Fix XMPP implementation - Verify that server don't listen own messages Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 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-15 10:27:38 UTC (rev 412) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyServiceNotifier.java 2010-10-15 12:02:05 UTC (rev 413) @@ -721,7 +721,7 @@ 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); + static private Log log = LogFactory.getLog(RemoteNotifier.class); /** * Indique si les objects sont propages (true) vers les autres caches ou * simplement supprimes des autres caches (false). Default to {@code false}. @@ -732,6 +732,7 @@ /** 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). @@ -750,24 +751,25 @@ 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); - } + Class transporterClass = config.getOptionAsClass( + WIKITTY_NOTIFIER_TRANSPORTER_CLASS); + try { + transporter = (RemoteNotifierTransporter) ConstructorUtils.invokeConstructor(transporterClass, + new Object[]{ws, props}, + new Class[]{WikittyServiceNotifier.class, Properties.class}); + } catch (Exception eee) { + throw new WikittyException("Can't create notifier: " + + transporterClass.getName(), eee); + } - // add this as listener when transporter is created without error - ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference - } + // add this as listener when transporter is created without error + ws.addWikittyServiceListener(this, WikittyService.ServiceListenerType.ALL); // weak reference } if (log.isInfoEnabled()) { if (transporter == null) { @@ -785,14 +787,14 @@ */ protected void sendMessage(WikittyServiceEvent event) { try { - if (log.isInfoEnabled()) { - log.info("Try to send message : " + event); + if (log.isDebugEnabled()) { + log.debug("Try to send message : " + event); } transporter.sendMessage(event); - if (log.isInfoEnabled()) { - log.info("message send" + event); + if (log.isDebugEnabled()) { + log.debug("Message is sent : " + event); } } catch (Exception eee) { if (log.isErrorEnabled()) { Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-15 10:27:38 UTC (rev 412) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/XMPPNotifierTransporter.java 2010-10-15 12:02:05 UTC (rev 413) @@ -72,12 +72,17 @@ received event missed after deconnection */ protected boolean persistent = false; + // Keep room addresse and pseudo to verify that messages event are not send by us + protected String room; + protected String pseudo; + protected XMPPConnection connection; protected MultiUserChat muc; /** * * @param ws + * @param props */ public XMPPNotifierTransporter(WikittyServiceNotifier ws, Properties props) { this.ws = ws; @@ -94,9 +99,10 @@ persistent = config.getOptionAsBoolean(WIKITTY_NOTIFICATION_PERSISTENT); String server = config.getOption(WIKITTY_XMPP_SERVER); - String room = config.getOption(WIKITTY_XMPP_ROOM); - - String pseudo = getUniqueLoginName(); + + // Keep them to verify that is not us notifications + room = config.getOption(WIKITTY_XMPP_ROOM); + pseudo = getUniqueLoginName(); try { if (log.isInfoEnabled()) { log.info("Try to connect to xmpp serveur " + server + @@ -141,21 +147,27 @@ */ @Override public void processPacket(Packet packet) { - Object event = packet.getProperty(PROPERTY_EVENT_NAME); - if (log.isInfoEnabled()) { - log.info("Receive message : " + event); - } + // Dont listen own events + String name = room + "/" + pseudo; + if (!name.equals(packet.getFrom())) { - if (event instanceof WikittyServiceEvent) { - processEvent((WikittyServiceEvent)event); + Object event = packet.getProperty(PROPERTY_EVENT_NAME); + + if (log.isDebugEnabled()) { + log.debug("Receive message : " + event); + } + + if (event instanceof WikittyServiceEvent) { + processEvent((WikittyServiceEvent)event); + } } } /** * Process event */ - protected void processEvent(WikittyServiceEvent event) { + protected void processEvent(WikittyServiceEvent event) { //source is transient, add it here : event.setSource(ws); event.setRemote(true); // received event became remote
participants (1)
-
sletellier@users.nuiton.org