Skip to content

Commit

Permalink
Fixed a little bug that wouldn't allow one to create a client or serv…
Browse files Browse the repository at this point in the history
…er without creating a session listener. Fixed a problem with the packet class. The byte buffer was being passed incorrectly, which would cause encoding and decoding problems. Also added an option for the server to distribute packets via a selection of algorithms. Algorithms are going to come by time. In the next commit the examples are going to be adjusted to the changes. Bumped to version 1.6.0.
  • Loading branch information
marcluque committed Apr 15, 2018
1 parent d64c2d9 commit ed3f127
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 113 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ like a [simple chat application](https://github.com/DataSecs/Hydra/wiki/Building
<dependency>
<groupId>de.datasecs</groupId>
<artifactId>hydra-all</artifactId>
<version>1.5.5</version>
<version>1.6.0</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hydra</artifactId>
<groupId>de.datasecs</groupId>
<version>1.5.5</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,14 +16,14 @@
<dependency>
<groupId>de.datasecs</groupId>
<artifactId>hydra-client</artifactId>
<version>1.5.5</version>
<version>1.6.0</version>
</dependency>

<!-- Hydra server -->
<dependency>
<groupId>de.datasecs</groupId>
<artifactId>hydra-server</artifactId>
<version>1.5.5</version>
<version>1.6.0</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hydra</artifactId>
<groupId>de.datasecs</groupId>
<version>1.5.5</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>de.datasecs</groupId>
<artifactId>hydra-shared</artifactId>
<version>1.5.5</version>
<version>1.6.0</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hydra</artifactId>
<groupId>de.datasecs</groupId>
<version>1.5.5</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -15,7 +15,7 @@
<dependency>
<groupId>de.datasecs</groupId>
<artifactId>hydra-all</artifactId>
<version>1.5.5</version>
<version>1.6.0</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>de.datasecs</groupId>
<artifactId>hydra</artifactId>
<packaging>pom</packaging>
<version>1.5.5</version>
<version>1.6.0</version>

<modules>
<module>all</module>
Expand Down
4 changes: 2 additions & 2 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hydra</artifactId>
<groupId>de.datasecs</groupId>
<version>1.5.5</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>de.datasecs</groupId>
<artifactId>hydra-shared</artifactId>
<version>1.5.5</version>
<version>1.6.0</version>
</dependency>
</dependencies>

Expand Down
19 changes: 19 additions & 0 deletions server/src/main/java/de/datasecs/hydra/server/HydraServer.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.datasecs.hydra.server;

import de.datasecs.hydra.shared.distribution.Distribution;
import de.datasecs.hydra.shared.handler.HydraSession;
import de.datasecs.hydra.shared.handler.Session;
import de.datasecs.hydra.shared.protocol.HydraProtocol;
import de.datasecs.hydra.shared.protocol.packets.Packet;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.internal.ConcurrentSet;

import java.net.SocketAddress;
import java.util.Arrays;
Expand Down Expand Up @@ -105,4 +108,20 @@ public SocketAddress getLocalAdress() {
public Set<Session> getSessions() {
return protocol.getSessions();
}

/**
* Sends a packet to all clients that are connected to the server with the specified distribution type.
*
* @param packet the packet that is supposed to be send to all connected clients.
* @param distributionType the type of distribution that is supposed to be used.
*/
public void send(Packet packet, Distribution distributionType) {
switch (distributionType) {
case SIMPLE_BROADCAST:
ConcurrentSet<Session> sessions = new ConcurrentSet<>();
sessions.addAll(protocol.getSessions());
sessions.forEach(session -> session.send(packet));
break;
}
}
}
2 changes: 1 addition & 1 deletion shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hydra</artifactId>
<groupId>de.datasecs</groupId>
<version>1.5.5</version>
<version>1.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.datasecs.hydra.shared.distribution;

//TODO: Add explanation
public enum Distribution {
SIMPLE_BROADCAST
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ public HydraSession(Channel channel, HydraProtocol protocol) {

@Override
protected void channelRead0(ChannelHandlerContext context, Packet packet) {
protocol.callPacketListener(packet, this);
if (protocol.getPacketListener() != null) {
protocol.callPacketListener(packet, this);
}
}

@Override
public void handlerRemoved(ChannelHandlerContext context) {
protocol.callSessionListener(false, this);
if (protocol.getSessionListener() != null) {
protocol.callSessionListener(false, this);
}

protocol.removeSession(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ protected void initChannel(SocketChannel channel) {
protocol.setClientSession(session);
}

// Inform SessionListener about new session
protocol.callSessionListener(true, session);
if (protocol.getSessionListener() != null) {
// Inform SessionListener about new session
protocol.callSessionListener(true, session);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,12 @@ public void removeSession(Session session) {
public Set<Session> getSessions() {
return sessions;
}

public HydraSessionListener getSessionListener() {
return sessionListener;
}

public HydraPacketListener getPacketListener() {
return packetListener;
}
}
Loading

0 comments on commit ed3f127

Please sign in to comment.