Sample program source code:
1 | import java.io.BufferedOutputStream; |
Detailed explanation of source code:
SocketClient class
Line number 11
Creates a Socket object.
main method
Line numbers 30 to 38
The following data is obtained from the arguments at runtime:
Argument | Variable | Use |
---|---|---|
1 | hostName | CEP Server host name |
2 | port | Socket adapter port |
3 | dataType | Event data format |
4 | charSet | Character set |
5 | eventTypeId | Event type ID |
6 | data | Event data |
7 | lWait | Data transmission wait time |
8 | loop | Data transmission count |
9 | dataCount | Number of event data to send at a time |
Line number 40
Creates a SocketClient object.
Line number 41
Calls a method for sending event data.
The number of event data to send at a time, event data format, character set, event type ID, event data, data transmission count, and data transmission wait time are passed as arguments.
Line number 43
Outputs a response from the CEP Server.
SocketClient constructor
Line number 91
Creates InetSocketAddress from the arguments.
Line number 93
Sets the underlying size to be set in a network input/output buffer to be used.
Line 94
Connects the socket to the CEP Server.
sendMessage method
Line number 57
Creates DataOutPutStream from the socket.
Line numbers 60 to 85
Loop the number of loop times specified in the argument.
Line numbers 62 to 82
Loop of the number of event data to send at a time specified in the argument.
Line number 64
Replaces %COUNTER% contained in the event data with the loop count.
This sends different event data every time.
This example assumes that the following event data is used:
"STR0001","CPN0001",%COUNTER%,"30"
Line number 66
Requests the total size of event data (unique format).
Line number 68
Writes the total size of event data (unique format).
Line number 70
Writes the byte array of event data format.
Line number 72
Writes the size of event type ID.
Line number 73
Writes the byte array of event type ID.
Line number 75
Writes the size of character set.
Line number 76
Writes the byte array of character set.
Line number 78
Writes the size of event data.
Line number 79
Writes the byte array of event data.
Line number 81
Flushes DataOutputStream.
Line number 84
Waits until the next event data is sent.
Line number 92
Receives a send complete notification (0), and notifies the CEP Server that the event has been sent.
Line number 93
Flushes DataOutputStream.
readResponse method
Line number 98
Creates BufferedReader from the socket.
Line number 100
Reads a response message (one line).
Line number 101
Outputs the contents of the response message to the standard output.
An example of sample execution is shown below.
In this example, debug information is output to the engine log by using DebugLogListener.
Command execution result
# java -cp ./ SocketClient localhost 8001 CSV UTF-8 CSVEvent SOCKET,CSV,%COUNTER% 1 2 2 <ENTER>
RESPONSE:0000:6:Sending message completed normally.
Engine log output result
2012-07-29 13:27:49,410 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :0: String
ID :SOCKET: String
2012-07-29 13:27:49,422 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :1: String
ID :SOCKET: String
2012-07-29 13:27:49,427 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :2: String
ID :SOCKET: String
2012-07-29 13:27:49,428 [DEBUG] abc:length=1
abc[0]
operation :CSV: String
count :3: String
ID :SOCKET: String
An example of sample execution is shown below.
In this example, debug information is output to the engine log by using DebugLogListener.
Command execution result
# java -cp ./ SocketClient localhost 8001 XML UTF-8 XMLEvent '<?xml version="1.0"\ encoding="UTF-8"?><XMLEvent><ID>SOCKET</ID> <operation>XML</operation>\ <count>%COUNTER%</count></XMLEvent>' 1 2 2 <ENTER>
RESPONSE:0000:4:Sending message completed normally.
Note that in the command line example above, backslash ("\") and newlines have been added for readability only. The actual command line does not have backslash or newlines.
Engine log output result
2012-07-29 13:30:56,861 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :0: String
ID :SOCKET: String
2012-07-29 13:30:56,862 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :1: String
ID :SOCKET: String
2012-07-29 13:30:56,865 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :2: String
ID :SOCKET: String
2012-07-29 13:30:56,865 [DEBUG] abc--0:length=1
abc--0[0]
operation :XML: String
count :3: String
ID :SOCKET: String