[soashable commit] r800 - in trunk/openfire-cometd: . src src/main src/main/java src/main/java/com src/main/java/com...

2 views
Skip to first unread message

codesite...@google.com

unread,
Aug 1, 2008, 3:51:05 PM8/1/08
to soashabl...@googlegroups.com
Author: h.iverson
Date: Fri Aug 1 12:50:13 2008
New Revision: 800

Added:
trunk/openfire-cometd/
trunk/openfire-cometd/pom.xml
trunk/openfire-cometd/src/
trunk/openfire-cometd/src/main/
trunk/openfire-cometd/src/main/java/
trunk/openfire-cometd/src/main/java/com/
trunk/openfire-cometd/src/main/java/com/soashable/
trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/
trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/BayeuxStartupListener.java
trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/CometdPlugin.java
trunk/openfire-cometd/src/main/openfire/
trunk/openfire-cometd/src/main/openfire/plugin.xml
trunk/openfire-cometd/src/main/webapp/
trunk/openfire-cometd/src/test/
trunk/openfire-cometd/src/test/java/

Log:
added base to test cometd connections on

Added: trunk/openfire-cometd/pom.xml
==============================================================================
--- (empty file)
+++ trunk/openfire-cometd/pom.xml Fri Aug 1 12:50:13 2008
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <parent>
+ <artifactId>soashable-web-master</artifactId>
+ <groupId>com.soashable</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.soashable</groupId>
+ <artifactId>openfire-cometd</artifactId>
+ <name>Openfire Cometd Connection Plugin</name>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>openfire-plugin</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.igniterealtime.openfire</groupId>
+ <artifactId>openfire</artifactId>
+ <version>[3.5.0,)</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>cometd-bayeux</artifactId>
+ <version>6.1.11</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.reucon.maven.plugins</groupId>
+ <artifactId>maven-openfire-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <jspPackageName>com.soashable.openfirecometd.jsp</jspPackageName>
+ </configuration>
+ </plugin>
+ </plugins>
+ <finalName>robot-olympics</finalName>
+ </build>
+</project>
\ No newline at end of file

Added: trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/BayeuxStartupListener.java
==============================================================================
--- (empty file)
+++
trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/BayeuxStartupListener.java
Fri Aug 1 12:50:13 2008
@@ -0,0 +1,143 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.soashable.openfirecometd;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
+
+import org.mortbay.cometd.BayeuxService;
+import org.jivesoftware.util.Log;
+
+import dojox.cometd.Bayeux;
+import dojox.cometd.Client;
+import dojox.cometd.Listener;
+import dojox.cometd.Message;
+import dojox.cometd.MessageListener;
+import dojox.cometd.RemoveListener;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+public class BayeuxStartupListener implements ServletContextAttributeListener
+{
+ public void initialize(Bayeux bayeux)
+ {
+ synchronized(bayeux)
+ {
+ if (!bayeux.hasChannel("/service/echo"))
+ {
+ new EchoRPC(bayeux);
+ new Monitor(bayeux);
+ new ChatService(bayeux);
+ }
+ }
+ }
+
+ public void attributeAdded(ServletContextAttributeEvent scab)
+ {
+ if (scab.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX))
+ {
+ Bayeux bayeux=(Bayeux)scab.getValue();
+ initialize(bayeux);
+ }
+ }
+
+ public void attributeRemoved(ServletContextAttributeEvent scab)
+ {
+
+ }
+
+ public void attributeReplaced(ServletContextAttributeEvent scab)
+ {
+
+ }
+
+
+ public static class EchoRPC extends BayeuxService
+ {
+ public EchoRPC(Bayeux bayeux)
+ {
+ super(bayeux,"echo");
+ subscribe("/service/echo","doEcho");
+ }
+
+ public Object doEcho(Client client, Object data)
+ {
+ Log.info("ECHO from "+client+" "+data);
+ return data;
+ }
+ }
+
+ public static class Monitor extends BayeuxService
+ {
+ public Monitor(Bayeux bayeux)
+ {
+ super(bayeux,"monitor");
+ subscribe("/meta/subscribe","monitorSubscribe");
+ subscribe("/meta/unsubscribe","monitorUnsubscribe");
+ subscribe("/meta/*","monitorMeta");
+ }
+
+ public void monitorSubscribe(Client client, Message message)
+ {
+ Log.info("Subscribe from "+client+" for "+message.get(Bayeux.SUBSCRIPTION_FIELD));
+ }
+
+ public void monitorUnsubscribe(Client client, Message message)
+ {
+ Log.info("Unsubscribe from "+client+" for "+message.get(Bayeux.SUBSCRIPTION_FIELD));
+ }
+
+ public void monitorMeta(Client client, Message message)
+ {
+ Log.debug(message.getChannel()+" from "+client);
+ }
+ }
+
+ public static class ChatService extends BayeuxService
+ {
+ ConcurrentMap<String,Set<String>> _members = new ConcurrentHashMap<String,Set<String>>();
+
+ public ChatService(Bayeux bayeux)
+ {
+ super(bayeux,"chat");
+ subscribe("/chat/**","trackMembers");
+ }
+
+ public void trackMembers(Client joiner,String
channel,Map<String,Object> data,String id)
+ {
+ if (Boolean.TRUE.equals(data.get("join")))
+ {
+ Set<String> m = _members.get(channel);
+ if (m==null)
+ {
+ Set<String> new_list=new CopyOnWriteArraySet<String>();
+ m=_members.putIfAbsent(channel,new_list);
+ if (m==null)
+ m=new_list;
+ }
+
+ final Set<String> members=m;
+ final String username=(String)data.get("user");
+
+ members.add(username);
+ joiner.addListener(new RemoveListener(){
+ public void removed(String clientId, boolean timeout)
+ {
+ members.remove(username);
+ Log.info("members: "+members);
+ }
+ });
+ Log.info("Members: "+members);
+ send(joiner,channel,members,id);
+ }
+ }
+ }
+}

Added: trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/CometdPlugin.java
==============================================================================
--- (empty file)
+++
trunk/openfire-cometd/src/main/java/com/soashable/openfirecometd/CometdPlugin.java
Fri Aug 1 12:50:13 2008
@@ -0,0 +1,26 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.soashable.openfirecometd;
+
+import java.io.File;
+import org.jivesoftware.openfire.container.Plugin;
+import org.jivesoftware.openfire.container.PluginManager;
+
+/**
+ *
+ * @author Harlan
+ */
+public class CometdPlugin implements Plugin {
+
+ public void initializePlugin(PluginManager arg0, File arg1) {
+
+ }
+
+ public void destroyPlugin() {
+
+ }
+
+}

Added: trunk/openfire-cometd/src/main/openfire/plugin.xml
==============================================================================
--- (empty file)
+++ trunk/openfire-cometd/src/main/openfire/plugin.xml Fri Aug 1
12:50:13 2008
@@ -0,0 +1,19 @@
+<plugin>
+ <!-- Main plugin class -->
+ <class>com.soashable.openfirecometd.CometdPlugin</class>
+
+ <!-- Plugin meta-data -->
+ <name>Cometd Connection Support</name>
+ <description>Allows Bayeux / Cometd Connections</description>
+ <author>Harlan Iverson</author>
+ <version>1.0</version>
+ <date>2008-08-11</date>
+ <minServerVersion>3.4.0</minServerVersion>
+ <licenseType>lgpl</licenseType>
+
+ <!-- Admin console meta-data -->
+ <adminconsole>
+
+
+ </adminconsole>
+</plugin>
\ No newline at end of file

Reply all
Reply to author
Forward
0 new messages