Skip to content

Commit

Permalink
修改ps
Browse files Browse the repository at this point in the history
  • Loading branch information
黄志磊 committed Jan 29, 2016
1 parent 2080baf commit 8925b43
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 71 deletions.
Expand Up @@ -109,17 +109,23 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
NettyClientFactory.INSTANCE.remove(ctx.channel());
Client client = NettyClientFactory.INSTANCE.getCientByChannel(ctx.channel());
if(client instanceof SecurityNettyClient){
NettyClientFactory.INSTANCE.remove(ctx.channel());
}else{
client.close("exception");
}

LOGGER.error("caught an ex, channel={}", ctx.channel(), cause);
}

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
LOGGER.info("client connect channel={}", ctx.channel());
Connection connection = new NettyConnection();
NettyClientFactory.INSTANCE.put(ctx.channel(), client);

if(client instanceof SecurityNettyClient){
NettyClientFactory.INSTANCE.put(ctx.channel(), client);
connection.init(ctx.channel(), true);
client.initConnection(connection);
client.init(ctx.channel());
Expand All @@ -133,8 +139,13 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
Client client = NettyClientFactory.INSTANCE.getCientByChannel(ctx.channel());
if(client instanceof SecurityNettyClient){
NettyClientFactory.INSTANCE.remove(ctx.channel());
}else{
client.close("inactive");
}
LOGGER.info("client disconnect channel={}", ctx.channel());
NettyClientFactory.INSTANCE.remove(ctx.channel());;
}

private void tryFastConnect(SecurityNettyClient securityNettyClient) {
Expand Down
4 changes: 4 additions & 0 deletions mpush-ps/pom.xml
Expand Up @@ -29,5 +29,9 @@
<groupId>com.shinemo.mpush</groupId>
<artifactId>mpush-tools</artifactId>
</dependency>
<dependency>
<groupId>com.shinemo.mpush</groupId>
<artifactId>mpush-core</artifactId>
</dependency>
</dependencies>
</project>

This file was deleted.

Expand Up @@ -8,7 +8,7 @@
/**
* Created by ohun on 2016/1/7.
*/
public class PushTest {
public class Main {

public static void main(String[] args) throws Exception {
GatewayClientMain client = new GatewayClientMain();
Expand Down
Expand Up @@ -21,7 +21,7 @@
*/
public class PushRequest implements PushSender.Callback, Runnable {

private static GatewayServerManage gatewayClientManage = (GatewayServerManage)ServiceContainer.getInstance(ServerManage.class, "gatewayClientManage");
private static GatewayServerManage gatewayClientManage = (GatewayServerManage)ServiceContainer.getInstance(ServerManage.class, "gatewayServerManage");

private static final Logger LOGGER = LoggerFactory.getLogger(PushRequest.class);
private PushSender.Callback callback;
Expand Down
Expand Up @@ -14,8 +14,9 @@
import com.shinemo.mpush.api.connection.Connection;
import com.shinemo.mpush.common.app.impl.GatewayServerApplication;
import com.shinemo.mpush.common.manage.ServerManage;
import com.shinemo.mpush.core.client.ClientChannelHandler;
import com.shinemo.mpush.netty.client.NettyClient;
import com.shinemo.mpush.netty.client.NettyClientFactory;
import com.shinemo.mpush.ps.GatewayClientChannelHandler;

public class GatewayServerManage implements ServerManage<GatewayServerApplication>{

Expand All @@ -31,9 +32,11 @@ public class GatewayServerManage implements ServerManage<GatewayServerApplicatio
public void addOrUpdate(String fullPath,GatewayServerApplication application){
holder.put(fullPath, application);
try{
Client client = NettyClientFactory.INSTANCE.create(application.getIp(), application.getPort(), new GatewayClientChannelHandler());
Client client = new NettyClient(application.getIp(), application.getPort());
ClientChannelHandler handler = new ClientChannelHandler(client);
NettyClientFactory.INSTANCE.create(handler);
application2Client.put(application, client);
ip2Client.put(application.getIp()+":"+application.getPort(), client);
ip2Client.put(application.getIp(), client);
}catch(Exception e){

}
Expand Down

0 comments on commit 8925b43

Please sign in to comment.