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 4, 2016
1 parent
315f4f4
commit 87f9f45
Showing
13 changed files
with
239 additions
and
89 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
mpush-api/src/main/java/com/shinemo/mpush/api/event/RouterChangeEvent.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,16 @@ | |||
package com.shinemo.mpush.api.event; | |||
|
|||
import com.shinemo.mpush.api.router.Router; | |||
|
|||
/** | |||
* Created by ohun on 2016/1/4. | |||
*/ | |||
public class RouterChangeEvent implements Event { | |||
public final String userId; | |||
public final Router<?> router; | |||
|
|||
public RouterChangeEvent(String userId, Router<?> router) { | |||
this.userId = userId; | |||
this.router = router; | |||
} | |||
} |
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
49 changes: 49 additions & 0 deletions
49
mpush-common/src/main/java/com/shinemo/mpush/common/router/ConnectionRouterManager.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,49 @@ | |||
package com.shinemo.mpush.common.router; | |||
|
|||
import com.google.common.cache.Cache; | |||
import com.google.common.cache.CacheBuilder; | |||
|
|||
import java.util.concurrent.TimeUnit; | |||
|
|||
/** | |||
* Created by ohun on 2016/1/4. | |||
*/ | |||
public class ConnectionRouterManager extends RemoteRouterManager { | |||
public static final ConnectionRouterManager INSTANCE = new ConnectionRouterManager(); | |||
// TODO: 2015/12/30 可以增加一层本地缓存,防止疯狂查询redis, 但是要注意失效问题及数据不一致问题 | |||
private final Cache<String, RemoteRouter> cache = CacheBuilder | |||
.newBuilder() | |||
.expireAfterWrite(5, TimeUnit.MINUTES) | |||
.expireAfterAccess(5, TimeUnit.MINUTES) | |||
.build(); | |||
|
|||
|
|||
@Override | |||
public RemoteRouter register(String userId, RemoteRouter route) { | |||
RemoteRouter old = cache.getIfPresent(userId); | |||
cache.put(userId, route); | |||
return old; | |||
} | |||
|
|||
@Override | |||
public boolean unRegister(String userId) { | |||
cache.invalidate(userId); | |||
return true; | |||
} | |||
|
|||
@Override | |||
public RemoteRouter lookup(String userId) { | |||
return cache.getIfPresent(userId); | |||
} | |||
|
|||
/** | |||
* 如果推送失败,可能是缓存不一致了,可以让本地缓存失效 | |||
* <p> | |||
* 失效对应的本地缓存 | |||
* | |||
* @param userId | |||
*/ | |||
public void invalidateLocalCache(String userId) { | |||
cache.invalidate(userId); | |||
} | |||
} |
29 changes: 2 additions & 27 deletions
29
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,49 +1,24 @@ | |||
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 可以增加一层本地缓存,防止疯狂查询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) { | ||
RemoteRouter old = cache.getIfPresent(userId); | return null; | ||
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 cache.getIfPresent(userId); | return null; | ||
} | |||
|
|||
/** | |||
* 如果推送失败,可能是缓存不一致了,可以让本地缓存失效 | |||
* <p> | |||
* 失效对应的本地缓存 | |||
* | |||
* @param userId | |||
*/ | |||
public void invalidateLocalCache(String userId) { | |||
cache.invalidate(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
19 changes: 19 additions & 0 deletions
19
mpush-core/src/main/java/com/shinemo/mpush/core/router/KickRemoteMsg.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,19 @@ | |||
package com.shinemo.mpush.core.router; | |||
|
|||
/** | |||
* Created by ohun on 2016/1/4. | |||
*/ | |||
public class KickRemoteMsg { | |||
public String userId; | |||
public String deviceId; | |||
public String srcServer; | |||
|
|||
@Override | |||
public String toString() { | |||
return "KickRemoteMsg{" + | |||
"userId='" + userId + '\'' + | |||
", deviceId='" + deviceId + '\'' + | |||
", srcServer='" + srcServer + '\'' + | |||
'}'; | |||
} | |||
} |
2 changes: 1 addition & 1 deletion
2
...nemo/mpush/common/router/LocalRouter.java → ...hinemo/mpush/core/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
2 changes: 1 addition & 1 deletion
2
...ush/common/router/LocalRouterManager.java → ...mpush/core/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
Oops, something went wrong.