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 implementation #393

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
1 change: 1 addition & 0 deletions extras/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<module>weblogic</module>
<module>jetty-websocketdraft8</module>
<module>jaxrs2</module>
<module>socketio</module>
</modules>
</project>
71 changes: 71 additions & 0 deletions extras/socketio/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-socketio</artifactId>
<packaging>bundle</packaging>
<version>1.0.0-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.protocol.*,
org.atmosphere.transport.socketio.*
</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>${project.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,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,62 @@
/*
* 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 org.atmosphere.cpr.AtmosphereHandler;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.protocol.socketio.transport.DisconnectReason;

/**
*
* @author Sebastien Dionne : [email protected]
*
*/
public interface SocketIOAtmosphereHandler extends AtmosphereHandler {


public static final String SOCKETIO_SESSION_OUTBOUND = "SocketIOSessionOutbound";

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


/**
* Called when the connection is established.
*
* @param outbound The SocketOutbound associated with the connection
*/
void onConnect(AtmosphereResource event, SocketIOSessionOutbound handler) throws IOException;

/**
* Called when the socket connection is disconnected.
*
* @param event AtmosphereResource
* @param handler outbound handler to broadcast response
* @param reason The reason for the disconnect.
*/
void onDisconnect(AtmosphereResource event, SocketIOSessionOutbound handler, DisconnectReason reason);

/**
* Called for each message received.
*
* @param event AtmosphereResource
* @param handler outbound handler to broadcast response
* @param message message received
*/
void onMessage(AtmosphereResource 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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;

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

public SocketIOException() {
super();
}

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

public SocketIOException(Throwable cause) {
super(cause);
}

public SocketIOException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.List;

import org.atmosphere.protocol.socketio.protocol1.transport.SocketIOPacketImpl;

/**
*
* @author Sebastien Dionne : [email protected]
*
*/
public interface SocketIOOutbound {

/**
* disconnect the current connection
*/
void disconnect();

/**
* force close connection
*/
void close();


/**
* Send a message to the client. If the session is still active, the message will be cached if the connection is closed.
*
* @param message The message to send
* @throws SocketIOException
*/
void sendMessage(String message) throws SocketIOException;

/**
* Send a message to the client formatted is SocketIO format. If the session is still active, the message will be cached if the connection is closed.
*
* @param message The message to send
* @throws SocketIOException
*/
void sendMessage(SocketIOPacket packet) throws SocketIOException;

/**
* Send messages to the client. If the session is still active, the messages will be cached if the connection is closed.
*
* @param message The message to send
* @throws SocketIOException
*/
void sendMessage(List<SocketIOPacketImpl> messages) throws SocketIOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 interface SocketIOPacket {

String toString();

}
Loading