From: <st...@us...> - 2007-08-15 09:51:18
|
Revision: 4987 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=4987&view=rev Author: steve_l Date: 2007-08-15 02:51:14 -0700 (Wed, 15 Aug 2007) Log Message: ----------- SFOS-391 XMPP enhancements Modified Paths: -------------- trunk/core/components/xmpp/build.xml trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/HistoryPacketHandlerImpl.java trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppListenerImpl.java trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppPacketHandlerImpl.java trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/components.sf trunk/core/components/xmpp/test/files/gmail_smartfrog_to_smartfrog.sf trunk/core/components/xmpp/test/files/xmpp.sf trunk/core/components/xmpp/test/org/smartfrog/services/xmpp/test/components.sf Added Paths: ----------- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/RelayHandlerImpl.java trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/WireMessage.java trunk/core/components/xmpp/test/files/relay.sf Modified: trunk/core/components/xmpp/build.xml =================================================================== --- trunk/core/components/xmpp/build.xml 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/build.xml 2007-08-15 09:51:14 UTC (rev 4987) @@ -40,16 +40,12 @@ <property name="root.dir" location="../.."/> - + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> <!-- Import common stuff --> <import file="${root.dir}/common.xml"/> - <target name="init" depends="common.init"> - <echo message="==================================================================="/> - <echo message="= ${ant.project.name}"/> - </target> - <!-- ========================================================== --> <!-- parse the file --> <!-- ========================================================== --> @@ -60,59 +56,18 @@ <classpath refid="tests.run.classpath"/> <sysproperty key="org.smartfrog.codebase" value="${codebase}"/> - <sysproperty key="xmpp.password" value=""/> + <sysproperty key="test.xmpp.password" value=""/> <!-- test files --> <source dir="${test.src.dir}"> <include name="files/*.sf"/> - <exclude name="files/components.sf"/> + <exclude name="**/components.sf"/> + <include name="org/smartfrog/services/xmpp/test/test*.sf"/> </source> </sf-parse> </target> <!-- ========================================================== --> - <!-- set up any properties for deployment --> - <!-- ========================================================== --> - <target name="init-deploy-properties" depends="init"> - <property name="deploy.host" value="localhost"/> - <property name="application.name" value="${project.name}"/> - </target> - - - - <!-- ========================================================== --> - <!-- deploy; requires a host --> - <!-- ========================================================== --> - <target name="deploy" depends="parse,init-codebase,init-deploy-properties" - description="deploy"> - - <sf-deploy classpathref="run.classpath" - logStackTraces="true" - host="${deploy.host}" - timeout="30000" - > - <codebase url="${codebase}"/> - - <application name="${application.name}"> - #include "/${deploy.sf}" - sfCodeBase PROPERTY org.smartfrog.codebase; - </application> - </sf-deploy> - </target> - - <target name="undeploy" depends="init-deploy-properties" - description="deploy"> - - <sf-undeploy classpathref="run.classpath" - logStackTraces="true" - host="${deploy.host}" - timeout="30000" - application="${application.name}"/> - </target> - - - - <!-- ========================================================== --> <!-- system tests --> <!-- ========================================================== --> Modified: trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/HistoryPacketHandlerImpl.java =================================================================== --- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/HistoryPacketHandlerImpl.java 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/HistoryPacketHandlerImpl.java 2007-08-15 09:51:14 UTC (rev 4987) @@ -37,7 +37,6 @@ public class HistoryPacketHandlerImpl extends XmppPacketHandlerImpl implements Remote { private List<Packet> messages; - private int limit; public static final String ATTR_LIMIT = "limit"; Added: trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/RelayHandlerImpl.java =================================================================== --- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/RelayHandlerImpl.java (rev 0) +++ trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/RelayHandlerImpl.java 2007-08-15 09:51:14 UTC (rev 4987) @@ -0,0 +1,78 @@ +/** (C) Copyright 2007 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.xmpp; + +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.packet.Message; +import org.smartfrog.sfcore.common.SmartFrogException; + +import java.rmi.RemoteException; +import java.util.Vector; + +/** + * + * Created 14-Aug-2007 16:35:25 + * + */ + +public class RelayHandlerImpl extends XmppMessageHandlerImpl { + + private Vector<String> recipients; + public static final String ATTR_TO = "to"; + + public RelayHandlerImpl() throws RemoteException { + } + + + /** + * Can be called to start components. Subclasses should override to provide functionality Do not block in this call, + * but spawn off any main loops! + * + * @throws SmartFrogException failure while starting + * @throws RemoteException In case of network/rmi error + */ + public synchronized void sfStart() throws SmartFrogException, RemoteException { + super.sfStart(); + Object to = sfResolve(ATTR_TO,true); + if(to instanceof Vector) { + recipients=(Vector<String>) to; + } else { + recipients=new Vector<String>(1); + recipients.add(to.toString()); + } + } + + /** + * Process the next packet sent to this packet listener.<p> + * + * A single thread is responsible for invoking all listeners, so it's very important that implementations of this + * method not block for any extended period of time. + * + * @param packet the packet to process. + */ + public void processPacket(Packet packet) { + super.processPacket(packet); + Message m=(Message) packet; + for(String to:recipients) { + getListener().sendMessage(to, m.getSubject(), m.getBody()); + } + + } +} Added: trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/WireMessage.java =================================================================== --- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/WireMessage.java (rev 0) +++ trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/WireMessage.java 2007-08-15 09:51:14 UTC (rev 4987) @@ -0,0 +1,48 @@ +/** (C) Copyright 2007 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.xmpp; + +import org.jivesoftware.smack.packet.Message; + +import java.io.Serializable; + +/** + * + * Created 14-Aug-2007 17:36:40 + * + */ + +public class WireMessage implements Serializable { + + private String subject; + private String thread; + private String body; + + + public WireMessage() { + } + + + public WireMessage(Message m) { + subject=m.getSubject(); + + body=m.getBody(); + } +} Modified: trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppListenerImpl.java =================================================================== --- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppListenerImpl.java 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppListenerImpl.java 2007-08-15 09:51:14 UTC (rev 4987) @@ -72,7 +72,6 @@ throws SmartFrogException, RemoteException { super.sfStart(); handlers.add(this); - String filter = sfResolve(ATTR_FILTER, "", true); reconnect = sfResolve(ATTR_RECONNECT, reconnect, true); timeout = sfResolve(ATTR_TIMEOUT, 0, true) * 60000L; connectAndRegister(); @@ -85,7 +84,6 @@ */ protected void connectAndRegister() throws SmartFrogException { connection = login(); - connection.addConnectionListener(this); registerAllHandlers(); } @@ -162,6 +160,8 @@ connection.close(); } catch (Exception e) { //ignore this + } finally { + connection = null; } } } @@ -283,10 +283,37 @@ /** + * Get the active connection + * @return the connection; this will be null when disconnected + */ + public XMPPConnection getConnection() { + return connection; + } + + /** * Is this connection made? * @return true if we are connected */ public boolean isConnected() { return connection!=null; } + + /** + * Send a text message if connected + * @param recipient who gets the message + * @param subject subject of the message + * @param text the text + * @return true if the message was sent + */ + public boolean sendMessage(String recipient,String subject,String text) { + if(isConnected()) { + Message m = new Message(recipient); + m.setSubject(subject); + m.setBody(text); + m.setType(Message.Type.NORMAL); + connection.sendPacket(m); + return true; + } + return false; + } } Modified: trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppPacketHandlerImpl.java =================================================================== --- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppPacketHandlerImpl.java 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/XmppPacketHandlerImpl.java 2007-08-15 09:51:14 UTC (rev 4987) @@ -21,6 +21,7 @@ import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.XMPPConnection; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogDeploymentException; import org.smartfrog.sfcore.prim.PrimImpl; @@ -36,6 +37,7 @@ XmppMessageHandler, LocalXmppPacketHandler, PacketFilter,Remote { private XmppListenerImpl listener; + public static final String ERROR_WRONG_TYPE_OR_PROCESS = "The listener must be an instance of XmppListenerImpl in the same process"; public XmppPacketHandlerImpl() throws RemoteException { @@ -51,12 +53,28 @@ /** - * Can be called to start components. Subclasses should override to provide functionality Do not block in this - * call, but spawn off any main loops! - * - * @throws SmartFrogException failure while starting - * @throws RemoteException In case of network/rmi error + * Get the current listener + * @return the listener */ + protected XmppListenerImpl getListener() { + return listener; + } + + /** + * Get the active connection (may be null) + * @return the active connection (may be null) + */ + protected XMPPConnection getConnection() { + return listener.getConnection(); + } + + /** + * Can be called to start components. Subclasses should override to provide functionality Do not block in this + * call, but spawn off any main loops! + * + * @throws SmartFrogException failure while starting + * @throws RemoteException In case of network/rmi error + */ public synchronized void sfStart() throws SmartFrogException, RemoteException { super.sfStart(); Prim owner=null; @@ -68,22 +86,7 @@ listener.registerPacketHandler(this); } - /** - * Called after instantiation for deployment purposes. Heart monitor is started and if there is a parent the - * deployed component is added to the heartbeat. Subclasses can override to provide additional deployment behavior. - * Attributees that require injection are handled during sfDeploy(). - * - * @throws SmartFrogException error while deploying - * @throws RemoteException In case of network/rmi error - */ - public synchronized void sfDeploy() throws SmartFrogException, RemoteException { - super.sfDeploy(); - - } - - - /** * Provides hook for subclasses to implement useful termination behavior. Deregisters component from local process * compound (if ever registered) * @@ -93,6 +96,7 @@ super.sfTerminateWith(status); if(listener!=null) { listener.unregisterPacketHandler(this); + listener=null; } } Modified: trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/components.sf =================================================================== --- trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/components.sf 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/src/org/smartfrog/services/xmpp/components.sf 2007-08-15 09:51:14 UTC (rev 4987) @@ -83,8 +83,8 @@ XmppListener extends XmppComponent { xmppListenerSchema extends Schema { - filter extends String { - description "classname for a filter to process incoming packets"; + presence extends Boolean { + description "should the component register itself as present"; } reconnect extends Boolean; offlineMinutesTimeout extends Integer { @@ -97,8 +97,6 @@ reconnect true; //a lot of servers go down. To be robust you have to retry a lot. offlineMinutesTimeout 60; - //default filter strips out all but messages - filter "org.smartfrog.services.xmpp.MessageFilter"; } /** @@ -214,7 +212,6 @@ */ XmppMessageHandler extends XmppPacketHandler { sfClass "org.smartfrog.services.xmpp.XmppMessageHandlerImpl"; - } /** @@ -233,4 +230,14 @@ sfClass "org.smartfrog.services.xmpp.HistoryPacketHandlerImpl"; //a limit of -1 means "no limit"; anything else limits the size limit 100; -} \ No newline at end of file +} + + +/** + * this component relays the message to someone else + */ +RelayHandler extends XmppMessageHandler { + sfClass "org.smartfrog.services.xmpp.RelayHandlerImpl"; + //give the name of the recipient, or a list of recipients + to TBD; +} \ No newline at end of file Modified: trunk/core/components/xmpp/test/files/gmail_smartfrog_to_smartfrog.sf =================================================================== --- trunk/core/components/xmpp/test/files/gmail_smartfrog_to_smartfrog.sf 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/test/files/gmail_smartfrog_to_smartfrog.sf 2007-08-15 09:51:14 UTC (rev 4987) @@ -35,8 +35,8 @@ post extends GoogleChatClientWorkflow { to "sma...@gm..."; - login "smartfrog.one"; - password PROPERTY xmpp.password; + login "smartfrog.two"; + password xmpp.password; message "hello, world"; } Added: trunk/core/components/xmpp/test/files/relay.sf =================================================================== --- trunk/core/components/xmpp/test/files/relay.sf (rev 0) +++ trunk/core/components/xmpp/test/files/relay.sf 2007-08-15 09:51:14 UTC (rev 4987) @@ -0,0 +1,48 @@ +/** (C) Copyright 2006 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ + +#include "/org/smartfrog/services/xmpp/components.sf" + +xmpp.password OPTIONAL("") PROPERTY test.xmpp.password; + +/** + * Not intended to do anything useful, merely + * parse correctly + */ + +sfConfig extends Compound { + + + Listener extends GoogleChatListener { + login "smartfrog.two"; + password xmpp.password; + } + + relay extends RelayHandler { + to ["ste...@gm..."]; + listener LAZY PARENT:Listener; + } + + log extends XmppMessageHandler { + listener LAZY PARENT:Listener; + } + + +} \ No newline at end of file Modified: trunk/core/components/xmpp/test/files/xmpp.sf =================================================================== --- trunk/core/components/xmpp/test/files/xmpp.sf 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/test/files/xmpp.sf 2007-08-15 09:51:14 UTC (rev 4987) @@ -30,17 +30,16 @@ sfConfig extends Parallel { - post extends GoogleChatClientWorkflow { - to "sma...@gm..."; - login "smartfrog.one"; - password xmpp.password; - message "hello, world"; - } listener extends GoogleChatListener { login "smartfrog.two"; password xmpp.password; } - + post extends GoogleChatClientWorkflow { + to "sma...@gm..."; + login "smartfrog.two"; + password xmpp.password; + message "hello, world"; + } } \ No newline at end of file Modified: trunk/core/components/xmpp/test/org/smartfrog/services/xmpp/test/components.sf =================================================================== --- trunk/core/components/xmpp/test/org/smartfrog/services/xmpp/test/components.sf 2007-08-14 16:01:46 UTC (rev 4986) +++ trunk/core/components/xmpp/test/org/smartfrog/services/xmpp/test/components.sf 2007-08-15 09:51:14 UTC (rev 4987) @@ -27,18 +27,16 @@ * members know */ -xmpp.password OPTIONAL("") PROPERTY test.xmpp.password; -//xmpp.password.present IF (xmpp.password != "") THEN true ELSE false FI; -xmpp.password.present (xmpp.password != ""); +xmpp.password OPTIONAL("parmaHam") PROPERTY test.xmpp.password; IsXmppPresent extends BooleanValue { - value xmpp.password.present; + value (xmpp.password != ""); } - postMessageFrom1 extends GoogleChatClientWorkflow { + PostMessage extends GoogleChatClientWorkflow { to "sma...@gm..."; - login "smartfrog.one"; + login "smartfrog.two"; password xmpp.password; message "hello, world"; } @@ -54,17 +52,17 @@ description "test xmpp deployment -requires test.xmpp.password to be set to the appropriate password"; action extends Compound { - listener extends listener2; + Listener extends listener2; historyPacketHandler extends HistoryPacketHandler { - listener LAZY listener; + listener LAZY Listener; } } undeployAfter 60000; tests extends Sequence { - post1 extends postMessageFrom1; - post2 extends postMessageFrom1 { + post1 extends PostMessage; + post2 extends PostMessage { message "second message"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |