Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.IO pull request : included merge with Atmosphere 0.9 #174

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.MessageListener;

import org.atmosphere.config.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.util.AbstractBroadcasterProxy;
import org.slf4j.Logger;
Expand All @@ -37,11 +38,11 @@ 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) {
public HazelcastBroadcaster(String id, AtmosphereConfig config) {
this(id, URI.create("http://localhost:6379"), config);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
package org.atmosphere.plugin.jgroups;

import org.atmosphere.config.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.util.AbstractBroadcasterProxy;
import org.jgroups.JChannel;
Expand All @@ -60,7 +61,7 @@ public class JGroupsBroadcaster extends AbstractBroadcasterProxy {
private JChannel jchannel;
private final CountDownLatch ready = new CountDownLatch(1);

public JGroupsBroadcaster(String id, AtmosphereServlet.AtmosphereConfig config) {
public JGroupsBroadcaster(String id, AtmosphereConfig config) {
super(id, null, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
package org.atmosphere.plugin.jms;

import org.atmosphere.config.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.util.AbstractBroadcasterProxy;
import org.slf4j.Logger;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class JMSBroadcaster extends AbstractBroadcasterProxy {
private String factoryName = "atmosphereFactory";
private String namespace = "jms/";

public JMSBroadcaster(String id, AtmosphereServlet.AtmosphereConfig config) {
public JMSBroadcaster(String id, AtmosphereConfig config) {
super(id, null, config);
setUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
package org.atmosphere.plugin.jms;

import org.atmosphere.config.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.cpr.Broadcaster;
import org.atmosphere.cpr.ClusterBroadcastFilter;
Expand Down Expand Up @@ -118,7 +119,7 @@ public void setUri(String clusterName) {
*/
public void init() {
try {
AtmosphereServlet.AtmosphereConfig config = bc.getBroadcasterConfig().getAtmosphereConfig();
AtmosphereConfig config = bc.getBroadcasterConfig().getAtmosphereConfig();
if (config != null) {

// For backward compatibility.
Expand Down
1 change: 1 addition & 0 deletions extras/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<module>redis</module>
<module>xmpp</module>
<module>hazelcast</module>
<module>socketio</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


import org.apache.commons.pool.impl.GenericObjectPool;
import org.atmosphere.config.AtmosphereConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.util.AbstractBroadcasterProxy;
import org.slf4j.Logger;
Expand Down Expand Up @@ -48,11 +49,11 @@ public class RedisBroadcaster extends AbstractBroadcasterProxy {
private boolean sharedPool = false;
private JedisPool jedisPool;

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

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

Expand Down
69 changes: 69 additions & 0 deletions extras/socketio/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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-socketio</artifactId>
<packaging>bundle</packaging>
<version>0.9-SNAPSHOT</version>
<name>atmosphere-socketio</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.*
</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-runtime</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-websockets</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2012 Sebastien Dionne
*
* 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.protocol.socketio;

/**
*
* @author Sebastien Dionne : [email protected]
*
*/
public enum ConnectionState {
UNKNOWN(-1),
CONNECTING(0),
CONNECTED(1),
CLOSING(2),
CLOSED(3);

private int value;
private ConnectionState(int v) { this.value = v; }
public int value() { return value; }

public static ConnectionState fromInt(int val) {
switch (val) {
case 0:
return CONNECTING;
case 1:
return CONNECTED;
case 2:
return CLOSING;
case 3:
return CLOSED;
default:
return UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2012 Sebastien Dionne
*
* 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.protocol.socketio;

import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;

/**
*
* @author Sebastien Dionne : [email protected]
*
*/
public class HeartBeatSessionMonitor extends SocketIOSessionActivityMonitor {

private SocketIOSession session = null;

public HeartBeatSessionMonitor(SocketIOSession session, ScheduledExecutorService executor) {
super(executor);
this.session = session;
}

@Override
public Callable<Boolean> getCommand() {
return new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
session.sendHeartBeat();
return true;
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2012 Sebastien Dionne
*
* 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.protocol.socketio;

import java.io.IOException;

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

import org.atmosphere.cpr.AtmosphereHandler;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.protocol.socketio.transport.DisconnectReason;

/**
*
* @author Sebastien Dionne : [email protected]
*
*/
public interface SocketIOAtmosphereHandler<F, G> extends AtmosphereHandler<F, G> {


public static final String SocketIOSessionOutbound = "SocketIOSessionOutbound";

public static final String SOCKETIO_SESSION_ID = SocketIOAtmosphereHandler.class.getPackage().getName() + ".sessionid";


/**
* Called when the connection is established. This will only ever be called once.
*
* @param outbound The SocketOutbound associated with the connection
*/
void onConnect(AtmosphereResource<HttpServletRequest, HttpServletResponse> event, SocketIOSessionOutbound handler) throws IOException;
void onDisconnect() throws IOException;

/**
* Called when the socket connection is closed. This will only ever be called once.
* This method may be called instead of onConnect() if the connection handshake isn't
* completed successfully.
*
* @param reason The reason for the disconnect.
* @param errorMessage Possibly non null error message associated with the reason for disconnect.
*/
void onDisconnect(DisconnectReason reason, String errorMessage);

/**
* Called when the socket connection is closed. This will only ever be called once.
* This method may be called instead of onConnect() if the connection handshake isn't
* completed successfully.
*
* @param reason The reason for the disconnect.
* @param errorMessage Possibly non null error message associated with the reason for disconnect.
*/
void onDisconnect(AtmosphereResource<HttpServletRequest, HttpServletResponse> event, SocketIOSessionOutbound handler, DisconnectReason reason);

/**
* Called one per arriving message.
*
* @param messageType
* @param message
*/
void onMessage(AtmosphereResource<HttpServletRequest, HttpServletResponse> event, SocketIOSessionOutbound handler, String message);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2012 Sebastien Dionne
*
* 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.protocol.socketio;

/**
*
* @author Sebastien Dionne : [email protected]
*
*/
public class SocketIOClosedException extends SocketIOException {
private static final long serialVersionUID = 1L;

public SocketIOClosedException() {
super();
}

public SocketIOClosedException(String message) {
super(message);
}

public SocketIOClosedException(String message, Throwable cause) {
super(message, cause);
}

public SocketIOClosedException(Throwable cause) {
super(cause);
}
}
Loading