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 30, 2015
1 parent
3af301e
commit e6e36f9
Showing
15 changed files
with
100 additions
and
32 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
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
17 changes: 17 additions & 0 deletions
17
mpush-common/src/main/java/com/shinemo/mpush/common/ErrorCode.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,17 @@ | |||
package com.shinemo.mpush.common; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/30. | |||
*/ | |||
public enum ErrorCode { | |||
OFFLINE(1, "user offline"), | |||
PUSH_CLIENT_FAILURE(2, "push to client failure"),; | |||
|
|||
ErrorCode(int code, String errorMsg) { | |||
this.errorMsg = errorMsg; | |||
this.errorCode = (byte) code; | |||
} | |||
|
|||
public final byte errorCode; | |||
public final String errorMsg; | |||
} |
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
30 changes: 27 additions & 3 deletions
30
mpush-common/src/main/java/com/shinemo/mpush/common/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 |
---|---|---|---|
@@ -1,25 +1,49 @@ | |||
package com.shinemo.mpush.common.router; | package com.shinemo.mpush.common.router; | ||
|
|
||
import com.google.common.cache.Cache; | |||
import com.google.common.cache.CacheBuilder; | |||
import com.shinemo.mpush.api.router.RouterManager; | import com.shinemo.mpush.api.router.RouterManager; | ||
|
|
||
import java.util.concurrent.TimeUnit; | |||
|
|||
/** | /** | ||
* Created by ohun on 2015/12/23. | * Created by ohun on 2015/12/23. | ||
*/ | */ | ||
public class RemoteRouterManager implements RouterManager<RemoteRouter> { | public class RemoteRouterManager implements RouterManager<RemoteRouter> { | ||
// TODO: 2015/12/30 add local cache | // TODO: 2015/12/30 可以增加一层本地缓存,防止疯狂查询redis, 但是要注意失效问题及数据不一致问题 | ||
private final Cache<String, RemoteRouter> cache = CacheBuilder | |||
.newBuilder() | |||
.expireAfterWrite(5, TimeUnit.MINUTES) | |||
.expireAfterAccess(5, TimeUnit.MINUTES) | |||
.build(); | |||
|
|||
|
|
||
@Override | @Override | ||
public RemoteRouter register(String userId, RemoteRouter route) { | public RemoteRouter register(String userId, RemoteRouter route) { | ||
return null; | RemoteRouter old = cache.getIfPresent(userId); | ||
cache.put(userId, route); | |||
return old; | |||
} | } | ||
|
|
||
@Override | @Override | ||
public boolean unRegister(String userId) { | public boolean unRegister(String userId) { | ||
cache.invalidate(userId); | |||
return true; | return true; | ||
} | } | ||
|
|
||
@Override | @Override | ||
public RemoteRouter lookup(String userId) { | public RemoteRouter lookup(String userId) { | ||
return null; | return cache.getIfPresent(userId); | ||
} | |||
|
|||
/** | |||
* 如果推送失败,可能是缓存不一致了,可以让本地缓存失效 | |||
* <p> | |||
* 失效对应的本地缓存 | |||
* | |||
* @param userId | |||
*/ | |||
public void invalidateLocalCache(String userId) { | |||
cache.invalidate(userId); | |||
} | } | ||
} | } |
8 changes: 8 additions & 0 deletions
8
mpush-core/src/main/java/com/shinemo/mpush/core/client/GatewayClient.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,8 @@ | |||
package com.shinemo.mpush.core.client; | |||
|
|||
/** | |||
* Created by ohun on 2015/12/30. | |||
*/ | |||
public class GatewayClient { | |||
|
|||
} |
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
2 changes: 1 addition & 1 deletion
2
...nemo/mpush/core/ServerChannelHandler.java → ...ush/core/server/ServerChannelHandler.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
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