Skip to content

Commit 2737e2f

Browse files
committed
Consolidated TCP and UPD out events to a single event NETWORK_MESSAGE
1 parent 7c7b9f2 commit 2737e2f

File tree

1 file changed

+34
-32
lines changed
  • jetclient/src/main/java/org/menacheri/jetclient/event

1 file changed

+34
-32
lines changed

jetclient/src/main/java/org/menacheri/jetclient/event/Events.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.menacheri.jetclient.event;
22

3+
import org.menacheri.jetclient.communication.IDeliveryGuaranty;
4+
import org.menacheri.jetclient.event.impl.AbstractSessionEventHandler;
35
import org.menacheri.jetclient.event.impl.ChangeAttributeEvent;
46
import org.menacheri.jetclient.event.impl.Event;
5-
import org.menacheri.jetclient.event.impl.AbstractSessionEventHandler;
7+
import org.menacheri.jetclient.event.impl.NetworkEvent;
68
/**
79
* Defines the event constants. Server and client communicate to each other
810
* using these constants. However, since Netty can be used to support any binary
@@ -58,31 +60,11 @@ public class Events
5860
public final static byte SESSION_MESSAGE = 0x1c;
5961

6062
/**
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.
6965
*/
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+
8668
public final static byte CHANGE_ATTRIBUTE = 0x20;
8769

8870
/**
@@ -91,21 +73,41 @@ public class Events
9173
public final static byte DISCONNECT = 0x22;
9274
public final static byte EXCEPTION = 0x24;
9375

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)
9588
{
96-
return event(source,CLIENT_OUT_TCP);
89+
return networkEvent(source,IDeliveryGuaranty.DeliveryGuaranty.RELIABLE);
9790
}
9891

9992
/**
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.
10196
*
10297
* @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}
105104
*/
106-
public static IEvent clientOutUDP(Object source)
105+
public static INetworkEvent networkEvent(Object source, IDeliveryGuaranty deliveryGuaranty)
107106
{
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;
109111
}
110112

111113
public static IEvent event(Object source, int eventType)

0 commit comments

Comments
 (0)