1
1
package org .menacheri .jetclient .event ;
2
2
3
+ import org .menacheri .jetclient .communication .IDeliveryGuaranty ;
4
+ import org .menacheri .jetclient .event .impl .AbstractSessionEventHandler ;
3
5
import org .menacheri .jetclient .event .impl .ChangeAttributeEvent ;
4
6
import org .menacheri .jetclient .event .impl .Event ;
5
- import org .menacheri .jetclient .event .impl .AbstractSessionEventHandler ;
7
+ import org .menacheri .jetclient .event .impl .NetworkEvent ;
6
8
/**
7
9
* Defines the event constants. Server and client communicate to each other
8
10
* using these constants. However, since Netty can be used to support any binary
@@ -58,31 +60,11 @@ public class Events
58
60
public final static byte SESSION_MESSAGE = 0x1c ;
59
61
60
62
/**
61
- * Outgoing data from the server to a remote client using TCP as the socket
62
- * transport protocol
63
- */
64
- public final static byte SERVER_OUT_TCP = 0x1d ;
65
-
66
- /**
67
- * Outgoing data from the server to a remote client using UDP as the socket
68
- * transport protocol
63
+ * This event is used to send data from the current machine to remote
64
+ * machines using TCP or UDP transports. It is an out-going event.
69
65
*/
70
- public final static byte SERVER_OUT_UDP = 0x1e ;
71
-
72
- /**
73
- * Outgoing data from this client to the server using TCP as the socket
74
- * transport protocol. <b>Note</b> that the op-code is the same as
75
- * {@link #SERVER_OUT_TCP}, this variable is defined for use at client side.
76
- */
77
- public final static byte CLIENT_OUT_TCP = 0x1d ;
78
-
79
- /**
80
- * Outgoing data from the client to server using UDP as the socket transport
81
- * protocol. <b>Note</b> that the op-code is the same as
82
- * {@link #SERVER_OUT_UDP}, this variable is defined for use at client side.
83
- */
84
- public final static byte CLIENT_OUT_UDP = 0x1e ;
85
-
66
+ public static final byte NETWORK_MESSAGE = 0x1d ;
67
+
86
68
public final static byte CHANGE_ATTRIBUTE = 0x20 ;
87
69
88
70
/**
@@ -91,21 +73,41 @@ public class Events
91
73
public final static byte DISCONNECT = 0x22 ;
92
74
public final static byte EXCEPTION = 0x24 ;
93
75
94
- public static IEvent clientOutTCP (Object source )
76
+ /**
77
+ * Creates a network event with the source set to the object passed in as
78
+ * parameter and the {@link IDeliveryGuaranty} set to
79
+ * {@link DeliveryGuaranty#RELIABLE}. This method delegates to
80
+ * {@link #networkEvent(Object, IDeliveryGuaranty)}.
81
+ *
82
+ * @param source
83
+ * The payload of the event. This is the actual data that gets
84
+ * transmitted to remote machine.
85
+ * @return An instance of {@link INetworkEvent}
86
+ */
87
+ public static INetworkEvent networkEvent (Object source )
95
88
{
96
- return event (source ,CLIENT_OUT_TCP );
89
+ return networkEvent (source ,IDeliveryGuaranty . DeliveryGuaranty . RELIABLE );
97
90
}
98
91
99
92
/**
100
- * Creates an event with CLIENT_OUT_UDP( byte 0x1e) as its event type.
93
+ * Creates a network event with the source set to the object passed in as
94
+ * parameter and the {@link IDeliveryGuaranty} set to the incoming
95
+ * parameter.
101
96
*
102
97
* @param source
103
- * The payload to set on the created event.
104
- * @return The event instance created.
98
+ * The payload of the event. This is the actual data that gets
99
+ * transmitted to remote machine.
100
+ * @param deliveryGuaranty
101
+ * This decides which transport TCP or UDP to be used to send the
102
+ * message to remote machine.
103
+ * @return An instance of {@link INetworkEvent}
105
104
*/
106
- public static IEvent clientOutUDP (Object source )
105
+ public static INetworkEvent networkEvent (Object source , IDeliveryGuaranty deliveryGuaranty )
107
106
{
108
- return event (source , CLIENT_OUT_UDP );
107
+ IEvent event = event (source ,Events .NETWORK_MESSAGE );
108
+ INetworkEvent networkEvent = new NetworkEvent (event );
109
+ networkEvent .setDeliveryGuaranty (deliveryGuaranty );
110
+ return networkEvent ;
109
111
}
110
112
111
113
public static IEvent event (Object source , int eventType )
0 commit comments