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
Dec 23, 2015
1 parent
5fa11df
commit cb85f28
Showing
24 changed files
with
283 additions
and
13 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
mpush-api/src/main/java/com/shinemo/mpush/api/Constants.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
package com.shinemo.mpush.api; | |||
|
|||
import java.nio.charset.Charset; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public interface Constants { | |||
Charset UTF_8 = Charset.forName("UTF-8"); | |||
} |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
package com.shinemo.mpush.api; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public interface Router { | |||
|
|||
Connection getConnect(); | |||
|
|||
RouterInfo getRouterInfo(); | |||
} |
20 changes: 20 additions & 0 deletions
20
mpush-api/src/main/java/com/shinemo/mpush/api/RouterInfo.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
package com.shinemo.mpush.api; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class RouterInfo { | |||
private String ip; | |||
|
|||
public RouterInfo(String ip) { | |||
this.ip = ip; | |||
} | |||
|
|||
public String getIp() { | |||
return ip; | |||
} | |||
|
|||
public void setIp(String ip) { | |||
this.ip = ip; | |||
} | |||
} |
13 changes: 13 additions & 0 deletions
13
mpush-api/src/main/java/com/shinemo/mpush/api/RouterManager.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
package com.shinemo.mpush.api; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public interface RouterManager { | |||
|
|||
boolean publish(long userId, Router route); | |||
|
|||
boolean unPublish(long userId); | |||
|
|||
Router getRouter(long userId); | |||
} |
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
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
3 changes: 2 additions & 1 deletion
3
mpush-core/src/main/java/com/shinemo/mpush/core/ConnectionManager.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
3 changes: 1 addition & 2 deletions
3
mpush-core/src/main/java/com/shinemo/mpush/core/handler/BaseMessageHandler.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
23 changes: 23 additions & 0 deletions
23
mpush-core/src/main/java/com/shinemo/mpush/core/handler/BindHandler.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
package com.shinemo.mpush.core.handler; | |||
|
|||
import com.shinemo.mpush.api.Constants; | |||
import com.shinemo.mpush.api.Request; | |||
import com.shinemo.mpush.api.protocol.Packet; | |||
import com.shinemo.mpush.gateway.router.RouterCenter; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class BindHandler extends BaseMessageHandler<String> { | |||
@Override | |||
public String decodeBody(Packet packet) { | |||
return new String(packet.body, Constants.UTF_8); | |||
} | |||
|
|||
@Override | |||
public void handle(String body, Request request) { | |||
long userId = Long.parseLong(body); | |||
boolean success = RouterCenter.INSTANCE.publish(userId, request.getConnection()); | |||
request.getResponse().send(new byte[]{success ? (byte) 1 : (byte) 0}); | |||
} | |||
} |
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
7 changes: 7 additions & 0 deletions
7
mpush-gateway/src/main/java/com/shinemo/mpush/gateway/GatewayServer.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
package com.shinemo.mpush.gateway; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class GatewayServer { | |||
} |
24 changes: 24 additions & 0 deletions
24
mpush-gateway/src/main/java/com/shinemo/mpush/gateway/router/LocalRouter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
package com.shinemo.mpush.gateway.router; | |||
|
|||
import com.shinemo.mpush.api.Connection; | |||
import com.shinemo.mpush.api.Router; | |||
import com.shinemo.mpush.api.RouterInfo; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class LocalRouter implements Router { | |||
private final Connection connection; | |||
|
|||
public LocalRouter(Connection connection) { | |||
this.connection = connection; | |||
} | |||
|
|||
public Connection getConnect() { | |||
return connection; | |||
} | |||
|
|||
public RouterInfo getRouterInfo() { | |||
return null; | |||
} | |||
} |
28 changes: 28 additions & 0 deletions
28
mpush-gateway/src/main/java/com/shinemo/mpush/gateway/router/LocalRouterManager.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
package com.shinemo.mpush.gateway.router; | |||
|
|||
import com.shinemo.mpush.api.Router; | |||
import com.shinemo.mpush.api.RouterManager; | |||
|
|||
import java.util.Map; | |||
import java.util.concurrent.ConcurrentHashMap; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class LocalRouterManager implements RouterManager { | |||
private final Map<Long, Router> routerMap = new ConcurrentHashMap<Long, Router>(); | |||
|
|||
public boolean publish(long userId, Router route) { | |||
routerMap.put(userId, route); | |||
return true; | |||
} | |||
|
|||
public boolean unPublish(long userId) { | |||
routerMap.remove(userId); | |||
return true; | |||
} | |||
|
|||
public Router getRouter(long userId) { | |||
return routerMap.get(userId); | |||
} | |||
} |
24 changes: 24 additions & 0 deletions
24
mpush-gateway/src/main/java/com/shinemo/mpush/gateway/router/RemoteRouter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
package com.shinemo.mpush.gateway.router; | |||
|
|||
import com.shinemo.mpush.api.Connection; | |||
import com.shinemo.mpush.api.Router; | |||
import com.shinemo.mpush.api.RouterInfo; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class RemoteRouter implements Router { | |||
private final RouterInfo routerInfo; | |||
|
|||
public RemoteRouter(RouterInfo routerInfo) { | |||
this.routerInfo = routerInfo; | |||
} | |||
|
|||
public Connection getConnect() { | |||
return null; | |||
} | |||
|
|||
public RouterInfo getRouterInfo() { | |||
return null; | |||
} | |||
} |
22 changes: 22 additions & 0 deletions
22
mpush-gateway/src/main/java/com/shinemo/mpush/gateway/router/RemoteRouterManager.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
package com.shinemo.mpush.gateway.router; | |||
|
|||
import com.shinemo.mpush.api.Router; | |||
import com.shinemo.mpush.api.RouterManager; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class RemoteRouterManager implements RouterManager { | |||
|
|||
public boolean publish(long userId, Router route) { | |||
return true; | |||
} | |||
|
|||
public boolean unPublish(long userId) { | |||
return true; | |||
} | |||
|
|||
public Router getRouter(long userId) { | |||
return null; | |||
} | |||
} |
34 changes: 34 additions & 0 deletions
34
mpush-gateway/src/main/java/com/shinemo/mpush/gateway/router/RouterCenter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
package com.shinemo.mpush.gateway.router; | |||
|
|||
import com.shinemo.mpush.api.Connection; | |||
import com.shinemo.mpush.api.Router; | |||
import com.shinemo.mpush.api.RouterInfo; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/23. | |||
*/ | |||
public class RouterCenter { | |||
public static final RouterCenter INSTANCE = new RouterCenter(); | |||
|
|||
private final LocalRouterManager localRouterManager = new LocalRouterManager(); | |||
private final RemoteRouterManager remoteRouterManager = new RemoteRouterManager(); | |||
|
|||
public boolean publish(long userId, Connection connection) { | |||
localRouterManager.publish(userId, new LocalRouter(connection)); | |||
remoteRouterManager.publish(userId, new RemoteRouter(new RouterInfo("127.0.0.1"))); | |||
return true; | |||
} | |||
|
|||
public boolean unPublish(long userId) { | |||
localRouterManager.unPublish(userId); | |||
remoteRouterManager.unPublish(userId); | |||
return true; | |||
} | |||
|
|||
public Router lookup(long userId) { | |||
Router local = localRouterManager.getRouter(userId); | |||
if (local != null) return local; | |||
Router remote = remoteRouterManager.getRouter(userId); | |||
return remote; | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<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"> | |||
<parent> | |||
<artifactId>mpush</artifactId> | |||
<groupId>com.shinemo.mpush</groupId> | |||
<version>1.0-SNAPSHOT</version> | |||
</parent> | |||
<modelVersion>4.0.0</modelVersion> | |||
|
|||
<artifactId>mpush-tools</artifactId> | |||
|
|||
|
|||
</project> |
Oops, something went wrong.