forked from tonybase/netty-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重构序列化问题,去除了entity中的版本号,使用header的协议版本号控制,添加mongodb数据配置,添加用户登录逻辑,添加消息转发…
…MessageHandler。
- Loading branch information
Tony
committed
Feb 20, 2015
1 parent
de6af28
commit 8349a74
Showing
49 changed files
with
1,869 additions
and
844 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
27 changes: 27 additions & 0 deletions
27
chat-biz/src/main/java/io/ganguo/chat/biz/ApplicationConfig.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.ganguo.chat.biz; | ||
|
||
import com.mongodb.Mongo; | ||
import com.mongodb.MongoClient; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.config.AbstractMongoConfiguration; | ||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; | ||
|
||
/** | ||
* Created by Tony on 2/19/15. | ||
*/ | ||
@Configuration | ||
@ComponentScan | ||
@EnableMongoRepositories | ||
public class ApplicationConfig extends AbstractMongoConfiguration { | ||
|
||
@Override | ||
public Mongo mongo() throws Exception { | ||
return new MongoClient(); | ||
} | ||
|
||
@Override | ||
protected String getDatabaseName() { | ||
return "CHAT_DB"; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
chat-biz/src/main/java/io/ganguo/chat/biz/bean/ClientType.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.ganguo.chat.biz.bean; | ||
|
||
/** | ||
* Created by Tony on 2/19/15. | ||
*/ | ||
public enum ClientType { | ||
|
||
WINDOWS(0), MAC(1), LINUX(2), IOS(3), ANDROID(4), WINPHONE(5), UNKNOUWN(-1); | ||
|
||
private byte mValue = 0; | ||
|
||
public byte getValue() { | ||
return mValue; | ||
} | ||
|
||
ClientType(int value) { | ||
mValue = (byte) value; | ||
} | ||
|
||
public static ClientType valueOfRaw(byte value) { | ||
for (ClientType clientType : ClientType.values()) { | ||
if (clientType.getValue() == value) { | ||
return clientType; | ||
} | ||
} | ||
return UNKNOUWN; | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
chat-biz/src/main/java/io/ganguo/chat/biz/entity/BaseEntity.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.ganguo.chat.biz.entity; | ||
|
||
import org.springframework.data.annotation.Id; | ||
|
||
import java.math.BigInteger; | ||
|
||
/** | ||
* Created by Tony on 2/19/15. | ||
*/ | ||
public abstract class BaseEntity { | ||
|
||
@Id | ||
protected String id; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
BaseEntity that = (BaseEntity) o; | ||
|
||
if (id != null ? !id.equals(that.id) : that.id != null) return false; | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return id != null ? id.hashCode() : 0; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
chat-biz/src/main/java/io/ganguo/chat/biz/entity/Login.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.ganguo.chat.biz.entity; | ||
|
||
import io.ganguo.chat.biz.bean.ClientType; | ||
import org.springframework.data.mongodb.core.index.Indexed; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
/** | ||
* Created by Tony on 2/20/15. | ||
*/ | ||
@Document | ||
public class Login extends BaseEntity { | ||
@Indexed(unique = true) | ||
private long uin; | ||
private String authToken; | ||
private long activeTime; | ||
|
||
public long getUin() { | ||
return uin; | ||
} | ||
|
||
public void setUin(long uin) { | ||
this.uin = uin; | ||
} | ||
|
||
public String getAuthToken() { | ||
return authToken; | ||
} | ||
|
||
public void setAuthToken(String authToken) { | ||
this.authToken = authToken; | ||
} | ||
|
||
public long getActiveTime() { | ||
return activeTime; | ||
} | ||
|
||
public void setActiveTime(long activeTime) { | ||
this.activeTime = activeTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Login{" + | ||
"uin=" + uin + | ||
", authToken='" + authToken + '\'' + | ||
", activeTime=" + activeTime + | ||
'}'; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
chat-biz/src/main/java/io/ganguo/chat/biz/entity/Message.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package io.ganguo.chat.biz.entity; | ||
|
||
|
||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
/** | ||
* Created by Tony on 2/20/15. | ||
*/ | ||
@Document | ||
public class Message extends BaseEntity { | ||
// uin | ||
private long to; | ||
private long from; | ||
private byte type; | ||
private String message; | ||
private long createAt; | ||
|
||
public long getTo() { | ||
return to; | ||
} | ||
|
||
public void setTo(long to) { | ||
this.to = to; | ||
} | ||
|
||
public long getFrom() { | ||
return from; | ||
} | ||
|
||
public void setFrom(long from) { | ||
this.from = from; | ||
} | ||
|
||
public byte getType() { | ||
return type; | ||
} | ||
|
||
public void setType(byte type) { | ||
this.type = type; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public long getCreateAt() { | ||
return createAt; | ||
} | ||
|
||
public void setCreateAt(long createAt) { | ||
this.createAt = createAt; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Message{" + | ||
"to=" + to + | ||
", from=" + from + | ||
", type=" + type + | ||
", message='" + message + '\'' + | ||
", createAt=" + createAt + | ||
'}'; | ||
} | ||
|
||
public enum Type { | ||
SESSION_MSG(0), // 临时会话消息 | ||
BUDDY_MSG(1), // 好友消息 | ||
GROUP_MSG(2); // 群消息 | ||
|
||
private byte mValue = 0; | ||
|
||
public byte getValue() { | ||
return mValue; | ||
} | ||
|
||
Type(int value) { | ||
mValue = (byte) value; | ||
} | ||
|
||
public static Type valueOfRaw(byte value) { | ||
for (Type type : Type.values()) { | ||
if (type.getValue() == value) { | ||
return type; | ||
} | ||
} | ||
return SESSION_MSG; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.