Skip to content

Commit

Permalink
Fix for #159 Add support for Hazelcast
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Jan 19, 2012
1 parent 44290c0 commit 27b930b
Show file tree
Hide file tree
Showing 25 changed files with 1,350 additions and 0 deletions.
64 changes: 64 additions & 0 deletions extras/hazelcast/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-project</artifactId>
<version>0.9-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-hazelcast</artifactId>
<packaging>bundle</packaging>
<version>0.9-SNAPSHOT</version>
<name>atmosphere-hazelcast</name>
<url>https://github.com/Atmosphere/atmosphere</url>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${felix-version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>*</Import-Package>
<Export-Package>
org.atmosphere.plugin.hazelcast.*
</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>osgi-bundle</id>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-jersey</artifactId>
<version>${pom.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>1.9.4.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2012 Jeanfrancois Arcand
*
* Licensed 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.atmosphere.plugin.hazelcast;


import com.hazelcast.core.ITopic;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MessageListener;

import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.util.AbstractBroadcasterProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;

/**
* Simple {@link org.atmosphere.cpr.Broadcaster} implementation based on Hazelcast
*
* @author Jeanfrancois Arcand
*/
public class HazelcastBroadcaster extends AbstractBroadcasterProxy {

private static final Logger logger = LoggerFactory.getLogger(org.atmosphere.plugin.hazelcast.HazelcastBroadcaster.class);
private ITopic topic;

public HazelcastBroadcaster(String id, AtmosphereServlet.AtmosphereConfig config) {
this(id, URI.create("http://localhost:6379"), config);
}

public HazelcastBroadcaster(String id, URI uri, AtmosphereServlet.AtmosphereConfig config) {
super(id, uri, config);
}

public void setUp() {
topic = Hazelcast.<String>getTopic(getID());
}

@Override
public synchronized void setID(String id) {
super.setID(id);
setUp();
}

/**
* {@inheritDoc}
*/
@Override
public void destroy() {
topic.destroy();
}

/**
* {@inheritDoc}
*/
@Override
public void incomingBroadcast() {
logger.info("Subscribing to: {}", getID());
topic.addMessageListener(new MessageListener<String>() {
@Override
public void onMessage(String message) {
broadcastReceivedMessage(message);
}
});
}

/**
* {@inheritDoc}
*/
@Override
public void outgoingBroadcast(Object message) {
topic.publish(message.toString());
}

}
1 change: 1 addition & 0 deletions extras/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
<module>jms</module>
<module>redis</module>
<module>xmpp</module>
<module>hazelcast</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
import static org.atmosphere.cpr.ApplicationConfig.SUPPORT_TRACKABLE;
import static org.atmosphere.cpr.ApplicationConfig.WEBSOCKET_PROTOCOL;
import static org.atmosphere.cpr.ApplicationConfig.WEBSOCKET_SUPPORT;
import static org.atmosphere.cpr.FrameworkConfig.HAZELCAST_BROADCASTER;
import static org.atmosphere.cpr.FrameworkConfig.JERSEY_BROADCASTER;
import static org.atmosphere.cpr.FrameworkConfig.JERSEY_CONTAINER;
import static org.atmosphere.cpr.FrameworkConfig.JGROUPS_BROADCASTER;
Expand Down Expand Up @@ -401,6 +402,7 @@ public AtmosphereServlet(boolean isFilter) {
* The order of addition is quite important here.
*/
private void populateBroadcasterType() {
broadcasterTypes.add(HAZELCAST_BROADCASTER);
broadcasterTypes.add(XMPP_BROADCASTER);
broadcasterTypes.add(REDIS_BROADCASTER);
broadcasterTypes.add(JGROUPS_BROADCASTER);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1320257818000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1322056397000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1322237374000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1324429089000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1324492840000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1324480420000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1326923560000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1326733811000
(?:[^/]+/)*?[^/]*?
META-INF(?:$|/.+)
50 changes: 50 additions & 0 deletions samples/jquery-pubsub-hazelcast/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.atmosphere.samples</groupId>
<artifactId>atmosphere-samples</artifactId>
<version>0.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.atmosphere.samples</groupId>
<artifactId>atmosphere-pubsub-hazelcast</artifactId>
<packaging>war</packaging>
<version>0.9-SNAPSHOT</version>
<name>atmosphere-pubsub-hazelcast</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-jquery</artifactId>
<version>${pom.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-jersey</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-hazelcast</artifactId>
<version>${pom.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback-version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2012 Jeanfrancois Arcand
*
* Licensed 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.atmosphere.samples.pubsub;

import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.atmosphere.cpr.AtmosphereResourceEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EventsLogger implements AtmosphereResourceEventListener {

private static final Logger logger = LoggerFactory.getLogger(EventsLogger.class);

public EventsLogger() {
}

public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
logger.info("onSuspend(): {}:{}", event.getResource().getRequest().getRemoteAddr(),
event.getResource().getRequest().getRemotePort());
}

public void onResume(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
logger.info("onResume(): {}:{}", event.getResource().getRequest().getRemoteAddr(),
event.getResource().getRequest().getRemotePort());
}

public void onDisconnect(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
logger.info("onDisconnect(): {}:{}", event.getResource().getRequest().getRemoteAddr(),
event.getResource().getRequest().getRemotePort());
}

public void onBroadcast(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
logger.info("onBroadcast(): {}", event.getMessage());
}

public void onThrowable(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) {
logger.warn("onThrowable(): {}", event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2012 Jeanfrancois Arcand
*
* Licensed 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.atmosphere.samples.pubsub;

import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.PathSegment;
import java.io.InputStream;

@Path("/")
@Produces("text/html")
public class FileResource {

private
@Context
ServletContext sc;

@Path("/jquery/{id}")
@GET
public InputStream getJQuery(@PathParam("id") PathSegment ps) {
return sc.getResourceAsStream("/jquery/" + ps.getPath());
}

@GET
public InputStream getIndex() {
return sc.getResourceAsStream("/index.html");
}
}
Loading

0 comments on commit 27b930b

Please sign in to comment.