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
黄志磊
committed
Jan 16, 2016
1 parent
dda4738
commit 5283ecf
Showing
14 changed files
with
205 additions
and
224 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
2 changes: 1 addition & 1 deletion
2
...a/com/shinemo/mpush/core/Application.java → ...com/shinemo/mpush/common/Application.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,4 +1,4 @@ | ||
package com.shinemo.mpush.core; | ||
package com.shinemo.mpush.common; | ||
|
||
|
||
/** | ||
|
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
134 changes: 67 additions & 67 deletions
134
mpush-core/src/test/java/com/shinemo/mpush/core/netty/NettyClientTest.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,67 +1,67 @@ | ||
package com.shinemo.mpush.core.netty; | ||
|
||
|
||
import com.shinemo.mpush.api.Client; | ||
import com.shinemo.mpush.netty.client.NettyClientFactory; | ||
import com.shinemo.mpush.tools.Jsons; | ||
import com.shinemo.mpush.tools.Strings; | ||
import com.shinemo.mpush.tools.spi.ServiceContainer; | ||
import com.shinemo.mpush.tools.zk.ZKPath; | ||
import com.shinemo.mpush.tools.zk.ServerApp; | ||
import com.shinemo.mpush.tools.zk.ZkRegister; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by ohun on 2015/12/24. | ||
*/ | ||
public class NettyClientTest { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClientTest.class); | ||
|
||
private static final ZkRegister zkRegister = ServiceContainer.getInstance(ZkRegister.class); | ||
|
||
public void setUp() throws Exception { | ||
} | ||
|
||
private List<ServerApp> getAllServers() { | ||
List<String> list = zkRegister.getChildrenKeys(ZKPath.CONNECTION_SERVER.getPath()); | ||
if (list == null || list.isEmpty()) return Collections.EMPTY_LIST; | ||
List<ServerApp> servers = new ArrayList<>(); | ||
for (String name : list) { | ||
String json = zkRegister.get(ZKPath.CONNECTION_SERVER.getFullPath(name)); | ||
if (Strings.isBlank(json)) continue; | ||
ServerApp server = Jsons.fromJson(json, ServerApp.class); | ||
if (server != null) servers.add(server); | ||
} | ||
return servers; | ||
} | ||
|
||
public void testClient() throws Exception { | ||
List<ServerApp> serverApps = getAllServers(); | ||
if (serverApps == null || serverApps.isEmpty()) return; | ||
int index = (int) ((Math.random() % serverApps.size()) * serverApps.size()); | ||
ServerApp server = serverApps.get(index); | ||
ClientChannelHandler handler = new ClientChannelHandler(); | ||
final Client client = NettyClientFactory.INSTANCE.createGet(server.getIp(), server.getPort(), handler); | ||
client.init(); | ||
Thread t = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
client.start(); | ||
} | ||
}); | ||
t.setDaemon(false); | ||
t.start(); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
NettyClientTest test = new NettyClientTest(); | ||
test.setUp(); | ||
test.testClient(); | ||
} | ||
} | ||
//package com.shinemo.mpush.core.netty; | ||
// | ||
// | ||
//import com.shinemo.mpush.api.Client; | ||
//import com.shinemo.mpush.netty.client.NettyClientFactory; | ||
//import com.shinemo.mpush.tools.Jsons; | ||
//import com.shinemo.mpush.tools.Strings; | ||
//import com.shinemo.mpush.tools.spi.ServiceContainer; | ||
//import com.shinemo.mpush.tools.zk.ZKPath; | ||
//import com.shinemo.mpush.tools.zk.ServerApp; | ||
//import com.shinemo.mpush.tools.zk.ZkRegister; | ||
// | ||
//import org.slf4j.Logger; | ||
//import org.slf4j.LoggerFactory; | ||
// | ||
//import java.util.ArrayList; | ||
//import java.util.Collections; | ||
//import java.util.List; | ||
// | ||
///** | ||
// * Created by ohun on 2015/12/24. | ||
// */ | ||
//public class NettyClientTest { | ||
// private static final Logger LOGGER = LoggerFactory.getLogger(NettyClientTest.class); | ||
// | ||
// private static final ZkRegister zkRegister = ServiceContainer.getInstance(ZkRegister.class); | ||
// | ||
// public void setUp() throws Exception { | ||
// } | ||
// | ||
// private List<ServerApp> getAllServers() { | ||
// List<String> list = zkRegister.getChildrenKeys(ZKPath.CONNECTION_SERVER.getPath()); | ||
// if (list == null || list.isEmpty()) return Collections.EMPTY_LIST; | ||
// List<ServerApp> servers = new ArrayList<>(); | ||
// for (String name : list) { | ||
// String json = zkRegister.get(ZKPath.CONNECTION_SERVER.getFullPath(name)); | ||
// if (Strings.isBlank(json)) continue; | ||
// ServerApp server = Jsons.fromJson(json, ServerApp.class); | ||
// if (server != null) servers.add(server); | ||
// } | ||
// return servers; | ||
// } | ||
// | ||
// public void testClient() throws Exception { | ||
// List<ServerApp> serverApps = getAllServers(); | ||
// if (serverApps == null || serverApps.isEmpty()) return; | ||
// int index = (int) ((Math.random() % serverApps.size()) * serverApps.size()); | ||
// ServerApp server = serverApps.get(index); | ||
// ClientChannelHandler handler = new ClientChannelHandler(); | ||
// final Client client = NettyClientFactory.INSTANCE.createGet(server.getIp(), server.getPort(), handler); | ||
// client.init(); | ||
// Thread t = new Thread(new Runnable() { | ||
// @Override | ||
// public void run() { | ||
// client.start(); | ||
// } | ||
// }); | ||
// t.setDaemon(false); | ||
// t.start(); | ||
// } | ||
// | ||
// public static void main(String[] args) throws Exception { | ||
// NettyClientTest test = new NettyClientTest(); | ||
// test.setUp(); | ||
// test.testClient(); | ||
// } | ||
//} |
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
2 changes: 1 addition & 1 deletion
2
mpush-cs/src/main/java/com/shinemo/mpush/cs/GatewayServerApplication.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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ava/com/shinemo/mpush/core/zk/ZkTest.java → ...est/java/com/shinemo/mpush/zk/ZkTest.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,4 +1,4 @@ | ||
package com.shinemo.mpush.core.zk; | ||
package com.shinemo.mpush.zk; | ||
|
||
import org.junit.Test; | ||
|
||
|
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
25 changes: 0 additions & 25 deletions
25
mpush-tools/src/main/java/com/shinemo/mpush/tools/zk/ServerApp.java
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
|
||
@SPI("zkRegister") | ||
public interface ZkRegister<T> { | ||
public interface ZkRegister { | ||
|
||
public void init(); | ||
|
||
|
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
Oops, something went wrong.