Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 060b6c9

Browse files
committed
add jConnection.defaultMsgDecoder.as(JEventManager)
1 parent c8fecab commit 060b6c9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

JSC/JConnection/src/main/java/jsc/jConnection/JConnection.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jsc.jConnection;
22

3+
import jsc.jEventManager.JEventManager;
34
import jsc.jMessageHandler.JMessageConsumer;
45

56
import java.io.DataInputStream;
@@ -22,12 +23,26 @@ public JConnection(Socket socket, JMessageConsumer msgDecoder) throws IOExceptio
2223
messageDecoder = msgDecoder;
2324
}
2425

25-
public JConnection(){}
26+
public JConnection(Socket socket) throws IOException {
27+
this(socket, new JEventManager());
28+
}
29+
30+
public JConnection(){
31+
messageDecoder = new JEventManager();
32+
}
2633

2734
public JConnection(String connectionIP, int connectionPort, JMessageConsumer msgDecoder) throws IOException{
2835
this(new Socket(connectionIP, connectionPort), msgDecoder);
2936
}
3037

38+
public JConnection(String connectionIP, int connectionPort) throws IOException {
39+
this(connectionIP, connectionPort, new JEventManager());
40+
}
41+
42+
public JConnection(String connectionID, Socket socket) throws IOException {
43+
this(connectionID, socket, new JEventManager());
44+
}
45+
3146
public JConnection(String connectionID, Socket socket, JMessageConsumer msgDecoder) throws IOException {
3247
this(socket, msgDecoder);
3348
setConnectionID(connectionID);
@@ -119,6 +134,18 @@ public void setMessageDecoder(JMessageConsumer messageDecoder) {
119134
this.messageDecoder = messageDecoder;
120135
}
121136

137+
138+
/**
139+
* Only applicable when @see #messageDecoder is set to JEventManager
140+
* @return JEventConsumer
141+
*/
142+
public JEventManager getJEventManager(){
143+
if(messageDecoder instanceof JEventManager){
144+
return (JEventManager) messageDecoder;
145+
}
146+
return null;
147+
}
148+
122149
public void accept(String msg) {
123150
if(messageDecoder!=null){
124151
messageDecoder.accept(msg);

0 commit comments

Comments
 (0)