Skip to content

Commit

Permalink
push client 代码调整
Browse files Browse the repository at this point in the history
  • Loading branch information
黄志磊 committed Feb 14, 2016
1 parent 2a72c85 commit 4929e5a
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -10,4 +10,5 @@
*.jar
*.war
*.ear
*.iml
*.iml
./target/*
7 changes: 7 additions & 0 deletions conf-daily.properties
Expand Up @@ -2,4 +2,11 @@
log.home=/tmp/logs/mpush
loglevel=warn
zk_ip = 127.0.0.1:2181
zk_digest = shinemoIpo
zk_namespace = mpush-daily
redis_group = 127.0.0.1:6379:shinemoIpo
private_key = MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=
public_key = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
force_write_redis_group_info = true
connection_server_port = 20882
gateway_server_port = 4000
7 changes: 7 additions & 0 deletions conf-online.properties
Expand Up @@ -2,4 +2,11 @@
log.home=/opt/logs/mpush
loglevel=INFO
zk_ip = 10.161.155.50:3356,10.162.19.217:3356,10.162.93.125:3356
zk_digest = shinemoIpo
zk_namespace = mpush-online
redis_group = 10.1.80.57:6379:shinemoIpo
private_key = MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=
public_key = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
force_write_redis_group_info = false
connection_server_port = 3000
gateway_server_port = 4000
7 changes: 7 additions & 0 deletions conf-pre.properties
Expand Up @@ -2,4 +2,11 @@
log.home=/opt/logs/mpush
loglevel=INFO
zk_ip = 10.161.155.50:3356,10.162.19.217:3356,10.162.93.125:3356
zk_digest = shinemoIpo
zk_namespace = mpush-pre
redis_group = 10.1.80.57:6379:shinemoIpo
private_key = MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=
public_key = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
force_write_redis_group_info = false
connection_server_port = 3000
gateway_server_port = 4000
28 changes: 28 additions & 0 deletions mpush-client/pom.xml
Expand Up @@ -22,4 +22,32 @@
<artifactId>mpush-netty</artifactId>
</dependency>
</dependencies>

<!-- 编译配置 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>com.shinemo.mpush:mpush-test</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
46 changes: 46 additions & 0 deletions mpush-client/src/main/java/com/shinemo/mpush/push/Main.java
@@ -0,0 +1,46 @@
package com.shinemo.mpush.push;

import com.shinemo.mpush.api.PushSender;
import com.shinemo.mpush.tools.Jsons;

import java.util.Arrays;
import java.util.concurrent.locks.LockSupport;

/**
* Created by ohun on 2016/1/7.
*/
public class Main {
public static void main(String[] args) throws Exception {
PushClient client = new PushClient();
client.start();
Thread.sleep(1000);
for (int i = 0; i < 100; i++) {
PushContent content = new PushContent("msgId_" + (i % 2), "MPush", "this a first push." + i);

client.send(Jsons.toJson(content), Arrays.asList("user-0", "8"), new PushSender.Callback() {
@Override
public void onSuccess(String userId) {
System.err.println("push onSuccess userId=" + userId);
}

@Override
public void onFailure(String userId) {
System.err.println("push onFailure userId=" + userId);
}

@Override
public void onOffline(String userId) {
System.err.println("push onOffline userId=" + userId);
}

@Override
public void onTimeout(String userId) {
System.err.println("push onTimeout userId=" + userId);
}
});
Thread.sleep(10000);
}
LockSupport.park();
}

}
@@ -1,17 +1,17 @@
package com.shinemo.mpush.test.push;
package com.shinemo.mpush.push;

import java.util.Collection;

import com.google.common.base.Strings;
import com.shinemo.mpush.api.PushSender.Callback;
import com.shinemo.mpush.api.PushSender;
import com.shinemo.mpush.common.AbstractClient;
import com.shinemo.mpush.test.push.zk.listener.impl.GatewayServerPathListener;
import com.shinemo.mpush.push.zk.listener.impl.GatewayServerPathListener;

public class GatewayClientMain extends AbstractClient {
public class PushClient extends AbstractClient implements PushSender{

private static final int defaultTimeout = 3000;

public GatewayClientMain() {
public PushClient() {
registerListener(new GatewayServerPathListener());
}

Expand Down
@@ -1,4 +1,4 @@
package com.shinemo.mpush.test.push;
package com.shinemo.mpush.push;

public class PushContent {
public String msgId;
Expand Down
@@ -1,4 +1,4 @@
package com.shinemo.mpush.test.push;
package com.shinemo.mpush.push;

import com.shinemo.mpush.api.PushSender;
import com.shinemo.mpush.api.connection.Connection;
Expand All @@ -7,7 +7,7 @@
import com.shinemo.mpush.common.message.gateway.GatewayPushMessage;
import com.shinemo.mpush.common.router.ConnectionRouterManager;
import com.shinemo.mpush.common.router.RemoteRouter;
import com.shinemo.mpush.test.push.manage.impl.GatewayServerManage;
import com.shinemo.mpush.push.manage.impl.GatewayServerManage;
import com.shinemo.mpush.tools.spi.ServiceContainer;

import io.netty.channel.ChannelFuture;
Expand Down
@@ -1,4 +1,4 @@
package com.shinemo.mpush.test.push;
package com.shinemo.mpush.push;

import java.util.Iterator;
import java.util.Map;
Expand Down
@@ -1,4 +1,4 @@
package com.shinemo.mpush.test.push.client;
package com.shinemo.mpush.push.client;



Expand All @@ -9,8 +9,8 @@
import com.shinemo.mpush.common.message.ErrorMessage;
import com.shinemo.mpush.netty.client.ChannelClientHandler;
import com.shinemo.mpush.netty.connection.NettyConnection;
import com.shinemo.mpush.test.push.PushRequest;
import com.shinemo.mpush.test.push.PushRequestBus;
import com.shinemo.mpush.push.PushRequest;
import com.shinemo.mpush.push.PushRequestBus;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
Expand Down
@@ -1,4 +1,4 @@
package com.shinemo.mpush.test.push.manage.impl;
package com.shinemo.mpush.push.manage.impl;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -16,7 +16,7 @@
import com.shinemo.mpush.common.manage.ServerManage;
import com.shinemo.mpush.netty.client.NettyClient;
import com.shinemo.mpush.netty.client.NettyClientFactory;
import com.shinemo.mpush.test.push.client.ClientChannelHandler;
import com.shinemo.mpush.push.client.ClientChannelHandler;

public class GatewayServerManage implements ServerManage<GatewayServerApplication>{

Expand Down
@@ -1,4 +1,4 @@
package com.shinemo.mpush.test.push.zk.listener.impl;
package com.shinemo.mpush.push.zk.listener.impl;

import com.shinemo.mpush.common.app.impl.GatewayServerApplication;
import com.shinemo.mpush.common.manage.ServerManage;
Expand Down
@@ -0,0 +1 @@
gatewayServerManage=com.shinemo.mpush.push.manage.impl.GatewayServerManage
Expand Up @@ -2,7 +2,6 @@

import com.shinemo.mpush.api.connection.Connection;
import com.shinemo.mpush.common.message.ByteBufMessage;
import com.shinemo.mpush.api.protocol.Command;
import com.shinemo.mpush.api.protocol.Packet;
import io.netty.buffer.ByteBuf;

Expand Down
Expand Up @@ -49,9 +49,9 @@ public void dataChanged(CuratorFramework client, TreeCacheEvent event, String pa
}

public void initData() {
log.warn("start init "+ this.getClass().getSimpleName()+"server data");
log.warn(zkRegister.getClient().getNamespace()+" start init "+ this.getClass().getSimpleName()+" server data");
_initData();
log.warn("end init "+ this.getClass().getSimpleName()+"server data");
log.warn(zkRegister.getClient().getNamespace()+" end init "+ this.getClass().getSimpleName()+" server data");
}

public abstract String getRegisterPath();
Expand Down
Expand Up @@ -174,17 +174,19 @@ private void tryFastConnect(final SecurityNettyClient securityNettyClient) {
}
}

String cipher = sessionTickets.get("cipherStr");
final String cipher = sessionTickets.get("cipherStr");

FastConnectMessage message = new FastConnectMessage(securityNettyClient.getConnection());
message.deviceId = securityNettyClient.getDeviceId();
message.sessionId = sessionId;
securityNettyClient.setCipher(cipher);
message.send(new ChannelFutureListener() {

message.sendRaw(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
handshake(securityNettyClient);
if (channelFuture.isSuccess()) {
securityNettyClient.setCipher(cipher);
}else{
handshake(securityNettyClient);
}
}
});
Expand Down

This file was deleted.

14 changes: 7 additions & 7 deletions mpush-cs/src/main/resources/config.properties
Expand Up @@ -9,13 +9,13 @@ max_heartbeat = 1800000
##
max_hb_timeout_times = 2
##
private_key = MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=
private_key = ${private_key}
##
public_key = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
public_key = ${public_key}
##
gateway_server_port = 4000
gateway_server_port = ${gateway_server_port}
##
connection_server_port = 3000
connection_server_port = ${connection_server_port}
##
aes_key_length = 16
##
Expand All @@ -25,10 +25,10 @@ session_expired_time = 86400

## zk ip
zk_ip = ${zk_ip}
zk_namespace = mpush
zk_digest = shinemoIpo
zk_namespace = ${zk_namespace}
zk_digest = ${zk_digest}


##redis_group = 127.0.0.1:6379:shinemoIpo,127.0.0.1:6380:shinemoIpo;127.0.0.1:6381:shinemoIpo
redis_group = ${redis_group}
force_write_redis_group_info = true
force_write_redis_group_info = ${force_write_redis_group_info}
4 changes: 4 additions & 0 deletions mpush-test/pom.xml
Expand Up @@ -38,6 +38,10 @@
<groupId>com.shinemo.mpush</groupId>
<artifactId>mpush-log</artifactId>
</dependency>
<dependency>
<groupId>com.shinemo.mpush</groupId>
<artifactId>mpush-client</artifactId>
</dependency>
</dependencies>

<!-- 编译配置 -->
Expand Down
@@ -1,6 +1,8 @@
package com.shinemo.mpush.test.push;

import com.shinemo.mpush.api.PushSender;
import com.shinemo.mpush.push.PushClient;
import com.shinemo.mpush.push.PushContent;
import com.shinemo.mpush.tools.Jsons;

import java.util.Arrays;
Expand All @@ -11,7 +13,7 @@
*/
public class Main {
public static void main(String[] args) throws Exception {
GatewayClientMain client = new GatewayClientMain();
PushClient client = new PushClient();
client.start();
Thread.sleep(1000);
for (int i = 0; i < 100; i++) {
Expand Down
Expand Up @@ -13,7 +13,7 @@ private_key = MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO
##
public_key = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
##
gateway_server_port = 4000
gateway_server_port = 20882
##
connection_server_port = 3000
##
Expand All @@ -24,7 +24,7 @@ ras_key_length = 1024
session_expired_time = 86400

zk_ip = 127.0.0.1:2181
zk_namespace = mpush
zk_namespace = mpush-daily
zk_digest = shinemoIpo

##redis_group = 127.0.0.1:6379:shinemoIpo,127.0.0.1:6380:shinemoIpo;127.0.0.1:6381:shinemoIpo
Expand Down
File renamed without changes.
Expand Up @@ -15,7 +15,7 @@ public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exc
if (path.isEmpty()) {
return;
}
LoggerManage.log(LogType.ZK, "DataChangeListener:%s,%s", path,listenerPath());
LoggerManage.log(LogType.ZK, "DataChangeListener:%s,%s,namespace:%s", path,listenerPath(),client.getNamespace());
if(path.startsWith(listenerPath())){
dataChanged(client, event, path);
}
Expand Down

0 comments on commit 4929e5a

Please sign in to comment.