View | Details | Raw Unified | Return to bug 54230
Collapse All | Expand All

(-)xdocs/usermanual/component_reference.xml (-2 / +6 lines)
Lines 1255-1263 Link Here
1255
		If "Re-use connection" is selected, connections are shared between Samplers in the same thread,
1255
		If "Re-use connection" is selected, connections are shared between Samplers in the same thread,
1256
		provided that the exact same host name string and port are used. 
1256
		provided that the exact same host name string and port are used. 
1257
		Different hosts/port combinations will use different connections, as will different threads. 
1257
		Different hosts/port combinations will use different connections, as will different threads. 
1258
		And both of "Re-use connection" and "Close connetion" are selected, the socket will be closed after running the sampler. 
1259
		On the next sampler, another socket will be created. You may want to close a socket at the end of each thread loop.
1258
		<br></br>
1260
		<br></br>
1259
		If an error is detected - or "Re-use connection" is not selected - the socket is closed. 
1261
		If an error is detected - or "Re-use connection" is not selected - the socket is closed. 
1260
		Another socket will be reopened on the next sample.
1262
		Also another socket will be reopened on the next sample.
1261
		<br></br>
1263
		<br></br>
1262
		The following properties can be used to control its operation:
1264
		The following properties can be used to control its operation:
1263
		</p>
1265
		</p>
Lines 1329-1334 Link Here
1329
  <property name="ServerName or IP" required="Yes">Name or IP of TCP server</property>
1331
  <property name="ServerName or IP" required="Yes">Name or IP of TCP server</property>
1330
  <property name="Port Number" required="Yes">Port to be used</property>
1332
  <property name="Port Number" required="Yes">Port to be used</property>
1331
  <property name="Re-use connection" required="Yes">If selected, the connection is kept open. Otherwise it is closed when the data has been read.</property>
1333
  <property name="Re-use connection" required="Yes">If selected, the connection is kept open. Otherwise it is closed when the data has been read.</property>
1334
  <property name="Close connection" required="Yes">If selected, the connection will be closed after running the sampler.</property>
1332
  <property name="Connect Timeout" required="No">Connect Timeout (milliseconds, 0 disables).</property>
1335
  <property name="Connect Timeout" required="No">Connect Timeout (milliseconds, 0 disables).</property>
1333
  <property name="Response Timeout" required="No">Response Timeout (milliseconds, 0 disables).</property>
1336
  <property name="Response Timeout" required="No">Response Timeout (milliseconds, 0 disables).</property>
1334
  <property name="Set Nodelay" required="Yes">See java.net.Socket.setTcpNoDelay().
1337
  <property name="Set Nodelay" required="Yes">See java.net.Socket.setTcpNoDelay().
Lines 3739-3745 Link Here
3739
  <property name="TCPClient classname" required="No">Name of the TCPClient class. Defaults to the property tcp.handler, failing that TCPClientImpl.</property>
3742
  <property name="TCPClient classname" required="No">Name of the TCPClient class. Defaults to the property tcp.handler, failing that TCPClientImpl.</property>
3740
  <property name="ServerName or IP" required="">Name or IP of TCP server</property>
3743
  <property name="ServerName or IP" required="">Name or IP of TCP server</property>
3741
  <property name="Port Number" required="">Port to be used</property>
3744
  <property name="Port Number" required="">Port to be used</property>
3742
  <property name="Re-use connection" required="Yes">If selected, the connection is kept open. Otherwise it is closed when the data has been read.</property>
3745
  <property name="SO_LINGER" required="No">Enable/disable SO_LINGER with the specified linger time in seconds when a socket is created. If you set "SO_LINGER" value as 0, you may prevent large numbers of sockets sitting around with a TIME_WAIT status.</property>
3746
  <property name="End of line(EOL) byte value" required="No">Byte value for end of line, set this to a value outside the range -128 to +127 to skip eol checking. You may set this in jmeter.properties file as well with eolByte property. If you set this in TCP Sampler Config and in jmeter.properties file at the same time, the setting value in the TCP Sampler Config will be used.</property>
3743
  <property name="Connect Timeout" required="No">Connect Timeout (milliseconds, 0 disables).</property>
3747
  <property name="Connect Timeout" required="No">Connect Timeout (milliseconds, 0 disables).</property>
3744
  <property name="Response Timeout" required="No">Response Timeout (milliseconds, 0 disables).</property>
3748
  <property name="Response Timeout" required="No">Response Timeout (milliseconds, 0 disables).</property>
3745
  <property name="Set Nodelay" required="">Should the nodelay property be set?</property>
3749
  <property name="Set Nodelay" required="">Should the nodelay property be set?</property>
(-)src/core/org/apache/jmeter/resources/messages.properties (+3 lines)
Lines 801-806 Link Here
801
retobj=Return object
801
retobj=Return object
802
return_code_config_box_title=Return Code Configuration
802
return_code_config_box_title=Return Code Configuration
803
reuseconnection=Re-use connection
803
reuseconnection=Re-use connection
804
closeconnection=Close connection
805
solinger=SO_LINGER:
806
eolbyte=End of line(EOL) byte value: 
804
revert_project=Revert
807
revert_project=Revert
805
revert_project?=Revert project?
808
revert_project?=Revert project?
806
root=Root
809
root=Root
(-)src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java (-31 / +106 lines)
Lines 19-29 Link Here
19
package org.apache.jmeter.protocol.tcp.config.gui;
19
package org.apache.jmeter.protocol.tcp.config.gui;
20
20
21
import java.awt.BorderLayout;
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23
import java.awt.event.ItemEvent;
24
import java.awt.event.ItemListener;
22
25
26
import javax.swing.BorderFactory;
23
import javax.swing.JCheckBox;
27
import javax.swing.JCheckBox;
24
import javax.swing.JLabel;
28
import javax.swing.JLabel;
25
import javax.swing.JPanel;
29
import javax.swing.JPanel;
26
import javax.swing.JTextArea;
30
import javax.swing.JTextArea;
31
import javax.swing.JTextField;
27
32
28
import org.apache.jmeter.config.ConfigTestElement;
33
import org.apache.jmeter.config.ConfigTestElement;
29
import org.apache.jmeter.config.gui.AbstractConfigGui;
34
import org.apache.jmeter.config.gui.AbstractConfigGui;
Lines 49-64 Link Here
49
54
50
    private JCheckBox setNoDelay;
55
    private JCheckBox setNoDelay;
51
56
57
    private JCheckBox closeConnection;
58
    
59
    private JTextField soLinger;
60
    
61
    private JTextField eolByte;
62
    
52
    private JTextArea requestData;
63
    private JTextArea requestData;
53
64
54
    private boolean displayName = true;
65
    private boolean displayName = true;
55
66
67
    private boolean displayOptionsPanelForSampler = false;
68
    
56
    public TCPConfigGui() {
69
    public TCPConfigGui() {
57
        this(true);
70
        this(true);
58
    }
71
    }
59
72
60
    public TCPConfigGui(boolean displayName) {
73
    public TCPConfigGui(boolean displayName) {
74
        this(displayName, false);
75
    }
76
77
    public TCPConfigGui(boolean displayName, boolean displayOptionsPanelForSampler) {
61
        this.displayName = displayName;
78
        this.displayName = displayName;
79
        this.displayOptionsPanelForSampler = displayOptionsPanelForSampler;
62
        init();
80
        init();
63
    }
81
    }
64
82
Lines 73-86 Link Here
73
        // N.B. this will be a config element, so we cannot use the getXXX() methods
91
        // N.B. this will be a config element, so we cannot use the getXXX() methods
74
        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
92
        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
75
        serverPanel.setServer(element.getPropertyAsString(TCPSampler.SERVER));
93
        serverPanel.setServer(element.getPropertyAsString(TCPSampler.SERVER));
76
        // Default to original behaviour, i.e. re-use connection
77
        reUseConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.RE_USE_CONNECTION,true));
78
        serverPanel.setPort(element.getPropertyAsString(TCPSampler.PORT));
94
        serverPanel.setPort(element.getPropertyAsString(TCPSampler.PORT));
79
        // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
95
        // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
80
        serverPanel.setResponseTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT));
96
        serverPanel.setResponseTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT));
81
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
97
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
82
        setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
83
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
98
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
99
100
        if (displayOptionsPanelForSampler) {
101
            // Default to original behaviour, i.e. re-use connection
102
            reUseConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.RE_USE_CONNECTION, true));
103
            closeConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.CLOSE_CONNECTION, false));
104
            setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
105
        }else{
106
            soLinger.setText(element.getPropertyAsString(TCPSampler.SO_LINGER));
107
            eolByte.setText(element.getPropertyAsString(TCPSampler.EOL_BYTE));
108
        }
84
    }
109
    }
85
110
86
    @Override
111
    @Override
Lines 101-113 Link Here
101
        // N.B. this will be a config element, so we cannot use the setXXX() methods
126
        // N.B. this will be a config element, so we cannot use the setXXX() methods
102
        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
127
        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
103
        element.setProperty(TCPSampler.SERVER, serverPanel.getServer());
128
        element.setProperty(TCPSampler.SERVER, serverPanel.getServer());
104
        element.setProperty(TCPSampler.RE_USE_CONNECTION, reUseConnection.isSelected());
105
        element.setProperty(TCPSampler.PORT, serverPanel.getPort());
129
        element.setProperty(TCPSampler.PORT, serverPanel.getPort());
106
        // element.setProperty(TCPSampler.FILENAME, filename.getText());
130
        // element.setProperty(TCPSampler.FILENAME, filename.getText());
107
        element.setProperty(TCPSampler.NODELAY, setNoDelay.isSelected());
108
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
131
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
109
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(),"");
132
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(), "");
110
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
133
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
134
135
        if (displayOptionsPanelForSampler) {
136
            element.setProperty(TCPSampler.RE_USE_CONNECTION, reUseConnection.isSelected());
137
            element.setProperty(TCPSampler.CLOSE_CONNECTION, closeConnection.isSelected());
138
            element.setProperty(TCPSampler.NODELAY, setNoDelay.isSelected());
139
        }else{
140
            element.setProperty(TCPSampler.SO_LINGER, soLinger.getText());
141
            element.setProperty(TCPSampler.EOL_BYTE, eolByte.getText());
142
        }
111
    }
143
    }
112
144
113
    /**
145
    /**
Lines 120-163 Link Here
120
        serverPanel.clear();
152
        serverPanel.clear();
121
        classname.setText(""); //$NON-NLS-1$
153
        classname.setText(""); //$NON-NLS-1$
122
        requestData.setText(""); //$NON-NLS-1$
154
        requestData.setText(""); //$NON-NLS-1$
123
        reUseConnection.setSelected(true);
124
        setNoDelay.setSelected(false);
125
    }
126
155
156
        if (displayOptionsPanelForSampler) {
157
            reUseConnection.setSelected(true);
158
            closeConnection.setSelected(false);
159
            setNoDelay.setSelected(false);
160
        }else{
161
            soLinger.setText(""); //$NON-NLS-1$
162
            eolByte.setText(""); //$NON-NLS-1$
163
        }
164
    }
127
165
128
    private JPanel createNoDelayPanel() {
166
    private JPanel createNoDelayPanel() {
129
        JLabel label = new JLabel(JMeterUtils.getResString("tcp_nodelay")); // $NON-NLS-1$
167
        setNoDelay = new JCheckBox(JMeterUtils.getResString("tcp_nodelay")); // $NON-NLS-1$
130
168
        JPanel nodelayPanel = new JPanel();
131
        setNoDelay = new JCheckBox();
169
        nodelayPanel.add(setNoDelay);
132
        label.setLabelFor(setNoDelay);
133
134
        JPanel nodelayPanel = new JPanel(new BorderLayout(5, 0));
135
        nodelayPanel.add(label, BorderLayout.WEST);
136
        nodelayPanel.add(setNoDelay, BorderLayout.CENTER);
137
        return nodelayPanel;
170
        return nodelayPanel;
138
    }
171
    }
139
172
140
    private JPanel createClosePortPanel() {
173
    private JPanel createClosePortPanel() {
141
        JLabel label = new JLabel(JMeterUtils.getResString("reuseconnection")); //$NON-NLS-1$
174
        reUseConnection = new JCheckBox(JMeterUtils.getResString("reuseconnection"), true); //$NON-NLS-1$
142
175
        reUseConnection.addItemListener(new ItemListener() {
143
        reUseConnection = new JCheckBox("", true);
176
            @Override
144
        label.setLabelFor(reUseConnection);
177
            public void itemStateChanged(final ItemEvent e) {
178
                if (e.getStateChange() == ItemEvent.SELECTED) {
179
                    closeConnection.setEnabled(true);
180
                } else {
181
                    closeConnection.setEnabled(false);
182
                    closeConnection.setSelected(true);
183
                }
184
            }
185
        });
145
186
146
        JPanel closePortPanel = new JPanel(new BorderLayout(5, 0));
187
        JPanel closePortPanel = new JPanel();
147
        closePortPanel.add(label, BorderLayout.WEST);
188
        closePortPanel.add(reUseConnection);
148
        closePortPanel.add(reUseConnection, BorderLayout.CENTER);
149
        return closePortPanel;
189
        return closePortPanel;
150
    }
190
    }
151
191
192
    private JPanel createCloseConnectionPanel() {
193
        closeConnection = new JCheckBox(JMeterUtils.getResString("closeconnection"), false); //$NON-NLS-1$
194
195
        JPanel closeConnectionPanel = new JPanel();
196
        closeConnectionPanel.add(closeConnection);
197
        return closeConnectionPanel;
198
    }
199
200
    private JPanel createSoLingerPanel() {
201
        JLabel soLingerLable = new JLabel(JMeterUtils.getResString("solinger")); //$NON-NLS-1$ 
202
        soLinger = new JTextField(5); // 5 columns size
203
        soLinger.setMaximumSize(new Dimension(50, 20));
204
        soLingerLable.setLabelFor(soLinger);
205
        JPanel soLingerPanel = new JPanel();
206
        soLingerPanel.add(soLingerLable);
207
        soLingerPanel.add(soLinger);
208
        return soLingerPanel;
209
    }
210
    
211
    private JPanel createEolBytePanel() {
212
        JLabel eolByteLabel = new JLabel(JMeterUtils.getResString("eolbyte")); //$NON-NLS-1$ 
213
        eolByte = new JTextField(3); // 3 columns size 
214
        eolByteLabel.setLabelFor(eolByte);
215
        
216
        JPanel eolBytePanel = new JPanel();
217
        eolBytePanel.add(eolByteLabel);
218
        eolBytePanel.add(eolByte);
219
        return eolBytePanel;
220
    }
221
152
    private JPanel createRequestPanel() {
222
    private JPanel createRequestPanel() {
153
        JLabel reqLabel = new JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$
154
        requestData = new JTextArea(3, 0);
223
        requestData = new JTextArea(3, 0);
155
        requestData.setLineWrap(true);
224
        requestData.setLineWrap(true);
156
        reqLabel.setLabelFor(requestData);
157
225
158
        JPanel reqDataPanel = new JPanel(new BorderLayout(5, 0));
226
        final JPanel reqDataPanel = new VerticalPanel();
159
        reqDataPanel.add(reqLabel, BorderLayout.WEST);
227
        reqDataPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("tcp_request_data"))); // $NON-NLS-1$
160
        reqDataPanel.add(requestData, BorderLayout.CENTER);
228
        reqDataPanel.add(requestData);
161
        return reqDataPanel;
229
        return reqDataPanel;
162
    }
230
    }
163
231
Lines 192-203 Link Here
192
        mainPanel.add(serverPanel);
260
        mainPanel.add(serverPanel);
193
        
261
        
194
        HorizontalPanel optionsPanel = new HorizontalPanel();
262
        HorizontalPanel optionsPanel = new HorizontalPanel();
195
        optionsPanel.add(createClosePortPanel());
263
        if (displayOptionsPanelForSampler) {
196
        optionsPanel.add(createNoDelayPanel());
264
            optionsPanel.add(createClosePortPanel());
265
            optionsPanel.add(createCloseConnectionPanel());
266
            optionsPanel.add(createNoDelayPanel());
267
        }else{
268
            optionsPanel.add(createSoLingerPanel());
269
            optionsPanel.add(createEolBytePanel());
270
        }
197
        mainPanel.add(optionsPanel);
271
        mainPanel.add(optionsPanel);
198
        mainPanel.add(createRequestPanel());
272
        mainPanel.add(createRequestPanel());
199
273
200
        // mainPanel.add(createFilenamePanel());
274
        // mainPanel.add(createFilenamePanel());
201
        add(mainPanel, BorderLayout.CENTER);
275
        add(mainPanel, BorderLayout.CENTER);
202
    }
276
    }
277
203
}
278
}
(-)src/protocol/tcp/org/apache/jmeter/protocol/tcp/control/gui/TCPSamplerGui.java (-1 / +1 lines)
Lines 92-98 Link Here
92
92
93
        VerticalPanel mainPanel = new VerticalPanel();
93
        VerticalPanel mainPanel = new VerticalPanel();
94
94
95
        tcpDefaultPanel = new TCPConfigGui(false);
95
        tcpDefaultPanel = new TCPConfigGui(false, true);
96
        mainPanel.add(tcpDefaultPanel);
96
        mainPanel.add(tcpDefaultPanel);
97
97
98
        loginPanel = new LoginConfigGui(false);
98
        loginPanel = new LoginConfigGui(false);
(-)src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java (-1 / +40 lines)
Lines 82-87 Link Here
82
    public static final String REQUEST = "TCPSampler.request"; //$NON-NLS-1$
82
    public static final String REQUEST = "TCPSampler.request"; //$NON-NLS-1$
83
83
84
    public static final String RE_USE_CONNECTION = "TCPSampler.reUseConnection"; //$NON-NLS-1$
84
    public static final String RE_USE_CONNECTION = "TCPSampler.reUseConnection"; //$NON-NLS-1$
85
    
86
    public static final String CLOSE_CONNECTION = "TCPSampler.closeConnection"; //$NON-NLS-1$
87
    
88
    public static final String SO_LINGER = "TCPSampler.soLinger"; //$NON-NLS-1$
89
    
90
    public static final String EOL_BYTE = "TCPSampler.EolByte"; //$NON-NLS-1$
85
    //-- JMX file constants - do not change
91
    //-- JMX file constants - do not change
86
92
87
    private static final String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap
93
    private static final String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap
Lines 168-173 Link Here
168
                closeSocket(socketKey); // Bug 44910 - close previous socket (if any)
174
                closeSocket(socketKey); // Bug 44910 - close previous socket (if any)
169
                SocketAddress sockaddr = new InetSocketAddress(getServer(), getPort());
175
                SocketAddress sockaddr = new InetSocketAddress(getServer(), getPort());
170
                con = new Socket();
176
                con = new Socket();
177
                if (!"".equals(getPropertyAsString(SO_LINGER,""))){
178
                	con.setSoLinger(true, getSoLinger());
179
                }
171
                con.connect(sockaddr, getConnectTimeout());
180
                con.connect(sockaddr, getConnectTimeout());
172
                if(log.isDebugEnabled()) {
181
                if(log.isDebugEnabled()) {
173
                    log.debug("Created new connection " + con); //$NON-NLS-1$
182
                    log.debug("Created new connection " + con); //$NON-NLS-1$
Lines 227-232 Link Here
227
    public boolean isReUseConnection() {
236
    public boolean isReUseConnection() {
228
        return getPropertyAsBoolean(RE_USE_CONNECTION);
237
        return getPropertyAsBoolean(RE_USE_CONNECTION);
229
    }
238
    }
239
    
240
    public void setCloseConnection(String close) {
241
    	this.setProperty(CLOSE_CONNECTION, close);
242
    }
243
    
244
    public boolean isCloseConnection() {
245
    	return getPropertyAsBoolean(CLOSE_CONNECTION);
246
    }
247
    
248
    public void setSoLinger(String soLinger) {
249
    	this.setProperty(SO_LINGER, soLinger, "");
250
    }
251
    
252
    public int getSoLinger() {
253
    	return getPropertyAsInt(SO_LINGER,0);
254
    }
255
    
256
    public void setEolByte(String eol) {
257
        this.setProperty(EOL_BYTE, eol);
258
    }
259
    
260
    public int getEolByte() {
261
        return getPropertyAsInt(EOL_BYTE);
262
    }
263
    
230
264
231
    public void setPort(String newFilename) {
265
    public void setPort(String newFilename) {
232
        this.setProperty(PORT, newFilename);
266
        this.setProperty(PORT, newFilename);
Lines 323-328 Link Here
323
        }
357
        }
324
        try {
358
        try {
325
            TCPClient = (TCPClient) javaClass.newInstance();
359
            TCPClient = (TCPClient) javaClass.newInstance();
360
            if (!"".equals(getPropertyAsString(EOL_BYTE,""))){
361
                TCPClient.setEolByte(getEolByte());
362
                log.info("Using eolByte=" + getEolByte());
363
            }
364
326
            if (log.isDebugEnabled()) {
365
            if (log.isDebugEnabled()) {
327
                log.debug(this + "Created: " + getClassname() + "@" + Integer.toHexString(TCPClient.hashCode())); //$NON-NLS-1$
366
                log.debug(this + "Created: " + getClassname() + "@" + Integer.toHexString(TCPClient.hashCode())); //$NON-NLS-1$
328
            }
367
            }
Lines 381-387 Link Here
381
            // Set if we were successful or not
420
            // Set if we were successful or not
382
            res.setSuccessful(isSuccessful);
421
            res.setSuccessful(isSuccessful);
383
422
384
            if (!isReUseConnection()) {
423
            if (!isReUseConnection() || isCloseConnection()) {
385
                closeSocket(socketKey);
424
                closeSocket(socketKey);
386
            }
425
            }
387
        }
426
        }

Return to bug 54230