-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
53 changed files
with
2,562 additions
and
529 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"jin*ling2asdfadfjlkasdjfzjkcv |
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 @@ | ||
protoc ./Message.proto --java_out=./ |
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 @@ | ||
syntax = "proto3"; | ||
option java_package = "org.mchat.io.message"; | ||
option java_outer_classname = "MessageBuf"; | ||
|
||
message Message{ | ||
|
||
MessageType type=1; | ||
int32 version=2; | ||
int64 from = 3; | ||
int64 to = 4; | ||
|
||
enum MessageType{ | ||
TEXT = 0; | ||
LOCATION = 1; | ||
VOICE = 2; | ||
IMAGE = 3; | ||
ACK = 4; | ||
ERROR = 5; | ||
} | ||
|
||
|
||
repeated bytes data=5; | ||
|
||
int32 flag = 6; | ||
int32 hash = 7; | ||
|
||
|
||
} |
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,22 @@ | ||
package org.mchat.io.object; | ||
import com.google.protobuf.ByteString; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mchat.io.message.MessageBuf; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* Created by jingli on 16/5/25. | ||
*/ | ||
public class TestMessage { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
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,11 @@ | ||
import java.math.BigDecimal; | ||
|
||
/** | ||
* Created by jingli on 16/6/18. | ||
*/ | ||
public class a { | ||
|
||
public void main(){ | ||
BigDecimal d = null; | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.mchat.io; | ||
|
||
/** | ||
* Created by jingli on 16/6/22. | ||
*/ | ||
public class a { | ||
|
||
public static void main(String[] args){ | ||
System.out.println(Long.MAX_VALUE); | ||
} | ||
} |
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,59 @@ | ||
package org.mchat.io.chatServer; | ||
|
||
import io.netty.channel.Channel; | ||
import org.mchat.io.chatServer.message.Message; | ||
import org.mchat.util.StringUtil; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
|
||
/** | ||
* Created by jingli on 16/6/22. | ||
*/ | ||
public class BigPool { | ||
|
||
final LinkedBlockingQueue<Message> messageQueue; | ||
final ConcurrentHashMap<String,Channel> hostChannelMap; | ||
final ConcurrentHashMap<Long,Channel> localUserChannelMap; | ||
final ConcurrentHashMap<Long,String> remoteUserHostMap; | ||
|
||
|
||
|
||
public BigPool(){ | ||
this.messageQueue = new LinkedBlockingQueue(); | ||
hostChannelMap = new ConcurrentHashMap<String, Channel>(); | ||
localUserChannelMap = new ConcurrentHashMap<Long, Channel>(); | ||
remoteUserHostMap = new ConcurrentHashMap<Long, String>(); | ||
} | ||
|
||
public Channel getLocalUserChannel(Long user){ | ||
return localUserChannelMap.get(user); | ||
} | ||
|
||
public Channel getRemoteUserChannel(Long user){ | ||
String hostKey = remoteUserHostMap.get(user); | ||
if(hostKey!=null) | ||
return hostChannelMap.get(hostKey); | ||
return null; | ||
} | ||
|
||
public Channel getBackUpChannel(){ | ||
return null; | ||
} | ||
|
||
public LinkedBlockingQueue<Message> getMessageQueue(){ return this.messageQueue;} | ||
|
||
|
||
public Channel getChannel(String host,int port){ | ||
String key = StringUtil.hostKey(host, port); | ||
return hostChannelMap.get(key); | ||
} | ||
|
||
public Channel getChannel(String host, String port) { | ||
String key = StringUtil.hostKey(host, port); | ||
return hostChannelMap.get(key); | ||
} | ||
|
||
|
||
|
||
} |
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
43 changes: 0 additions & 43 deletions
43
io/src/main/java/org/mchat/io/chatServer/ChatSubscribeListener.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
io/src/main/java/org/mchat/io/chatServer/message/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,11 @@ | ||
package org.mchat.io.chatServer.message; | ||
|
||
/** | ||
* Created by jingli on 16/6/22. | ||
*/ | ||
public interface Message { | ||
|
||
public Long getFrom(); | ||
public Long getto(); | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...hat/io/message/MessageFlagCodeNaming.java → ...Server/message/MessageFlagCodeNaming.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 org.mchat.io.message; | ||
package org.mchat.io.chatServer.message; | ||
|
||
/** | ||
* Created by jingli on 16/5/28. | ||
|
27 changes: 27 additions & 0 deletions
27
io/src/main/java/org/mchat/io/chatServer/router/DefaultRouter.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 org.mchat.io.chatServer.router; | ||
|
||
import io.netty.channel.Channel; | ||
import org.mchat.io.chatServer.message.Message; | ||
import org.mchat.io.chatServer.BigPool; | ||
|
||
/** | ||
* Created by jingli on 16/6/23. | ||
*/ | ||
public class DefaultRouter extends Router { | ||
|
||
public DefaultRouter(BigPool pool) { | ||
super(pool); | ||
} | ||
|
||
void forward(Message message){ | ||
long to = message.getto(); | ||
Channel channel = pool.getLocalUserChannel(to); | ||
if(channel == null) | ||
channel = pool.getRemoteUserChannel(to); | ||
if(channel == null) | ||
channel = pool.getBackUpChannel(); | ||
if(channel == null) | ||
throw new RuntimeException("fetal error , no channel is available"); | ||
channel.writeAndFlush(message); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
io/src/main/java/org/mchat/io/chatServer/router/Router.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,33 @@ | ||
package org.mchat.io.chatServer.router; | ||
|
||
import org.mchat.io.chatServer.message.Message; | ||
import org.mchat.io.chatServer.BigPool; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Created by jingli on 16/6/22. | ||
*/ | ||
public abstract class Router implements Callable<java.lang.Boolean> { | ||
|
||
final BigPool pool; | ||
private boolean state; | ||
|
||
public Router(BigPool pool){ | ||
this.pool = pool; | ||
state = true; | ||
} | ||
|
||
@Override | ||
public java.lang.Boolean call() throws Exception { | ||
while(state){ | ||
Message message = pool.getMessageQueue().take(); | ||
if(message != null){ | ||
forward(message); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
abstract void forward(Message message); | ||
} |
Oops, something went wrong.