Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
3,261 additions
and
3,268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
target | ||
*.iml | ||
*.ipr | ||
target | ||
*.iml | ||
*.ipr | ||
*.iws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jadecife-client</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<parent> | ||
<artifactId>jadecife-parent</artifactId> | ||
<groupId>ru.frostman.jadecife</groupId> | ||
<version>0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>jadecife-client</name> | ||
<url>http://jadecife.frostman.ru</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ru.frostman.jadecife</groupId> | ||
<artifactId>jadecife-common</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javassist</groupId> | ||
<artifactId>javassist</artifactId> | ||
<version>3.12.1.GA</version> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jadecife-client</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<parent> | ||
<artifactId>jadecife-parent</artifactId> | ||
<groupId>ru.frostman.jadecife</groupId> | ||
<version>0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>jadecife-client</name> | ||
<url>http://jadecife.frostman.ru</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ru.frostman.jadecife</groupId> | ||
<artifactId>jadecife-common</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javassist</groupId> | ||
<artifactId>javassist</artifactId> | ||
<version>3.12.1.GA</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
116 changes: 58 additions & 58 deletions
116
jadecife-client/src/main/java/ru/frostman/jadecife/client/ClientHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
package ru.frostman.jadecife.client; | ||
|
||
import org.jboss.netty.channel.*; | ||
import org.jboss.netty.channel.group.ChannelGroup; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import ru.frostman.jadecife.message.MessageHandler; | ||
import ru.frostman.jadecife.model.Message; | ||
|
||
/** | ||
* @author slukjanov aka Frostman | ||
*/ | ||
class ClientHandler extends SimpleChannelUpstreamHandler { | ||
private static final Logger log = LoggerFactory.getLogger(ClientHandler.class); | ||
|
||
private final ChannelGroup channelGroup; | ||
private final MessageHandler messageHandler; | ||
private Channel channel; | ||
|
||
public ClientHandler(ChannelGroup channelGroup, MessageHandler messageHandler) { | ||
this.channelGroup = channelGroup; | ||
this.messageHandler = messageHandler; | ||
} | ||
|
||
@Override | ||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { | ||
if (e.getMessage() instanceof Message) { | ||
messageHandler.messageReceived((Message) e.getMessage()); | ||
} else { | ||
messageReceived(ctx, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { | ||
this.channel = e.getChannel(); | ||
this.channelGroup.add(e.getChannel()); | ||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { | ||
log.warn("Exception in handling messages", e.getCause()); | ||
|
||
e.getChannel().close(); | ||
} | ||
|
||
public ChannelFuture sendMessage(Message message) { | ||
if (channel != null) { | ||
return channel.write(message); | ||
}else { | ||
throw new IllegalStateException("Channel == null"); | ||
} | ||
} | ||
|
||
public void stop() { | ||
channel.close(); | ||
} | ||
} | ||
package ru.frostman.jadecife.client; | ||
|
||
import org.jboss.netty.channel.*; | ||
import org.jboss.netty.channel.group.ChannelGroup; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import ru.frostman.jadecife.message.MessageHandler; | ||
import ru.frostman.jadecife.model.Message; | ||
|
||
/** | ||
* @author slukjanov aka Frostman | ||
*/ | ||
class ClientHandler extends SimpleChannelUpstreamHandler { | ||
private static final Logger log = LoggerFactory.getLogger(ClientHandler.class); | ||
|
||
private final ChannelGroup channelGroup; | ||
private final MessageHandler messageHandler; | ||
private Channel channel; | ||
|
||
public ClientHandler(ChannelGroup channelGroup, MessageHandler messageHandler) { | ||
this.channelGroup = channelGroup; | ||
this.messageHandler = messageHandler; | ||
} | ||
|
||
@Override | ||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { | ||
if (e.getMessage() instanceof Message) { | ||
messageHandler.messageReceived((Message) e.getMessage()); | ||
} else { | ||
messageReceived(ctx, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { | ||
this.channel = e.getChannel(); | ||
this.channelGroup.add(e.getChannel()); | ||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { | ||
log.warn("Exception in handling messages", e.getCause()); | ||
|
||
e.getChannel().close(); | ||
} | ||
|
||
public ChannelFuture sendMessage(Message message) { | ||
if (channel != null) { | ||
return channel.write(message); | ||
}else { | ||
throw new IllegalStateException("Channel == null"); | ||
} | ||
} | ||
|
||
public void stop() { | ||
channel.close(); | ||
} | ||
} |
Oops, something went wrong.