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

(-)xdocs/usermanual/component_reference.xml (-2 / +7 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="Yes">Enable/disable SO_LINGER option of the socket when it is created.</property>
3746
  <property name="LINGER Timeout" required="No">LINGER Timeout.</property>
3747
  <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</property>
3743
  <property name="Connect Timeout" required="No">Connect Timeout (milliseconds, 0 disables).</property>
3748
  <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>
3749
  <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>
3750
  <property name="Set Nodelay" required="">Should the nodelay property be set?</property>
(-)src/core/org/apache/jmeter/resources/messages.properties (+3 lines)
Lines 800-805 Link Here
800
retobj=Return object
800
retobj=Return object
801
return_code_config_box_title=Return Code Configuration
801
return_code_config_box_title=Return Code Configuration
802
reuseconnection=Re-use connection
802
reuseconnection=Re-use connection
803
closeconnection=Close connection
804
solinger=SO_LINGER, LINGER Timeout:
805
eolbyte=End of line(EOL) byte value: 
803
revert_project=Revert
806
revert_project=Revert
804
revert_project?=Revert project?
807
revert_project?=Revert project?
805
root=Root
808
root=Root
(-)src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java (-31 / +111 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 JCheckBox soLinger;
60
    
61
    private JTextField soLingerTimeout;
62
    
63
    private JTextField eolByte;
64
    
52
    private JTextArea requestData;
65
    private JTextArea requestData;
53
66
54
    private boolean displayName = true;
67
    private boolean displayName = true;
55
68
69
    private boolean displayOptionsPanelForSampler = false;
70
    
56
    public TCPConfigGui() {
71
    public TCPConfigGui() {
57
        this(true);
72
        this(true);
58
    }
73
    }
59
74
60
    public TCPConfigGui(boolean displayName) {
75
    public TCPConfigGui(boolean displayName) {
76
        this(displayName, false);
77
    }
78
79
    public TCPConfigGui(boolean displayName, boolean displayOptionsPanelForSampler) {
61
        this.displayName = displayName;
80
        this.displayName = displayName;
81
        this.displayOptionsPanelForSampler = displayOptionsPanelForSampler;
62
        init();
82
        init();
63
    }
83
    }
64
84
Lines 73-86 Link Here
73
        // N.B. this will be a config element, so we cannot use the getXXX() methods
93
        // N.B. this will be a config element, so we cannot use the getXXX() methods
74
        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
94
        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
75
        serverPanel.setServer(element.getPropertyAsString(TCPSampler.SERVER));
95
        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));
96
        serverPanel.setPort(element.getPropertyAsString(TCPSampler.PORT));
79
        // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
97
        // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
80
        serverPanel.setResponseTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT));
98
        serverPanel.setResponseTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT));
81
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
99
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
82
        setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
83
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
100
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
101
102
        if (displayOptionsPanelForSampler) {
103
            // Default to original behaviour, i.e. re-use connection
104
            reUseConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.RE_USE_CONNECTION, true));
105
            closeConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.CLOSE_CONNECTION, false));
106
            setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
107
        }else{
108
            soLinger.setSelected(element.getPropertyAsBoolean(TCPSampler.SO_LINGER, false));
109
            soLingerTimeout.setText(element.getPropertyAsString(TCPSampler.SO_LINGER_TIMEOUT));
110
            eolByte.setText(element.getPropertyAsString(TCPSampler.EOL_BYTE));
111
        }
84
    }
112
    }
85
113
86
    @Override
114
    @Override
Lines 101-113 Link Here
101
        // N.B. this will be a config element, so we cannot use the setXXX() methods
129
        // N.B. this will be a config element, so we cannot use the setXXX() methods
102
        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
130
        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
103
        element.setProperty(TCPSampler.SERVER, serverPanel.getServer());
131
        element.setProperty(TCPSampler.SERVER, serverPanel.getServer());
104
        element.setProperty(TCPSampler.RE_USE_CONNECTION, reUseConnection.isSelected());
105
        element.setProperty(TCPSampler.PORT, serverPanel.getPort());
132
        element.setProperty(TCPSampler.PORT, serverPanel.getPort());
106
        // element.setProperty(TCPSampler.FILENAME, filename.getText());
133
        // element.setProperty(TCPSampler.FILENAME, filename.getText());
107
        element.setProperty(TCPSampler.NODELAY, setNoDelay.isSelected());
108
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
134
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
109
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(),"");
135
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(), "");
110
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
136
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
137
138
        if (displayOptionsPanelForSampler) {
139
            element.setProperty(TCPSampler.RE_USE_CONNECTION, reUseConnection.isSelected());
140
            element.setProperty(TCPSampler.CLOSE_CONNECTION, closeConnection.isSelected());
141
            element.setProperty(TCPSampler.NODELAY, setNoDelay.isSelected());
142
        }else{
143
            element.setProperty(TCPSampler.SO_LINGER, soLinger.isSelected());
144
            element.setProperty(TCPSampler.SO_LINGER_TIMEOUT, soLingerTimeout.getText());
145
            element.setProperty(TCPSampler.EOL_BYTE, eolByte.getText());
146
        }
111
    }
147
    }
112
148
113
    /**
149
    /**
Lines 120-163 Link Here
120
        serverPanel.clear();
156
        serverPanel.clear();
121
        classname.setText(""); //$NON-NLS-1$
157
        classname.setText(""); //$NON-NLS-1$
122
        requestData.setText(""); //$NON-NLS-1$
158
        requestData.setText(""); //$NON-NLS-1$
123
        reUseConnection.setSelected(true);
124
        setNoDelay.setSelected(false);
125
    }
126
159
160
        if (displayOptionsPanelForSampler) {
161
            reUseConnection.setSelected(true);
162
            closeConnection.setSelected(false);
163
            setNoDelay.setSelected(false);
164
        }else{
165
            soLinger.setSelected(false);
166
            soLingerTimeout.setText(""); //$NON-NLS-1$
167
            eolByte.setText(""); //$NON-NLS-1$
168
        }
169
    }
127
170
128
    private JPanel createNoDelayPanel() {
171
    private JPanel createNoDelayPanel() {
129
        JLabel label = new JLabel(JMeterUtils.getResString("tcp_nodelay")); // $NON-NLS-1$
172
        setNoDelay = new JCheckBox(JMeterUtils.getResString("tcp_nodelay")); // $NON-NLS-1$
130
173
        JPanel nodelayPanel = new JPanel();
131
        setNoDelay = new JCheckBox();
174
        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;
175
        return nodelayPanel;
138
    }
176
    }
139
177
140
    private JPanel createClosePortPanel() {
178
    private JPanel createClosePortPanel() {
141
        JLabel label = new JLabel(JMeterUtils.getResString("reuseconnection")); //$NON-NLS-1$
179
        reUseConnection = new JCheckBox(JMeterUtils.getResString("reuseconnection"), true); //$NON-NLS-1$
142
180
        reUseConnection.addItemListener(new ItemListener() {
143
        reUseConnection = new JCheckBox("", true);
181
            @Override
144
        label.setLabelFor(reUseConnection);
182
            public void itemStateChanged(final ItemEvent e) {
183
                if (e.getStateChange() == ItemEvent.SELECTED) {
184
                    closeConnection.setEnabled(true);
185
                } else {
186
                    closeConnection.setEnabled(false);
187
                    closeConnection.setSelected(true);
188
                }
189
            }
190
        });
145
191
146
        JPanel closePortPanel = new JPanel(new BorderLayout(5, 0));
192
        JPanel closePortPanel = new JPanel();
147
        closePortPanel.add(label, BorderLayout.WEST);
193
        closePortPanel.add(reUseConnection);
148
        closePortPanel.add(reUseConnection, BorderLayout.CENTER);
149
        return closePortPanel;
194
        return closePortPanel;
150
    }
195
    }
151
196
197
    private JPanel createCloseConnectionPanel() {
198
        closeConnection = new JCheckBox(JMeterUtils.getResString("closeconnection"), false); //$NON-NLS-1$
199
200
        JPanel closeConnectionPanel = new JPanel();
201
        closeConnectionPanel.add(closeConnection);
202
        return closeConnectionPanel;
203
    }
204
205
    private JPanel createSoLingerPanel() {
206
        soLinger = new JCheckBox(JMeterUtils.getResString("solinger"), false); //$NON-NLS-1$
207
        soLingerTimeout = new JTextField(5); // 5 columns size
208
        soLingerTimeout.setMaximumSize(new Dimension(50, 20));
209
210
        JPanel soLingerPanel = new JPanel();
211
        soLingerPanel.add(soLinger);
212
        soLingerPanel.add(soLingerTimeout);
213
        return soLingerPanel;
214
    }
215
    
216
    private JPanel createEolBytePanel() {
217
        JLabel eolByteLabel = new JLabel(JMeterUtils.getResString("eolbyte")); //$NON-NLS-1$ 
218
        eolByte = new JTextField(3); // 3 columns size 
219
        eolByteLabel.setLabelFor(eolByte);
220
        
221
        JPanel eolBytePanel = new JPanel();
222
        eolBytePanel.add(eolByteLabel);
223
        eolBytePanel.add(eolByte);
224
        return eolBytePanel;
225
    }
226
152
    private JPanel createRequestPanel() {
227
    private JPanel createRequestPanel() {
153
        JLabel reqLabel = new JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$
154
        requestData = new JTextArea(3, 0);
228
        requestData = new JTextArea(3, 0);
155
        requestData.setLineWrap(true);
229
        requestData.setLineWrap(true);
156
        reqLabel.setLabelFor(requestData);
157
230
158
        JPanel reqDataPanel = new JPanel(new BorderLayout(5, 0));
231
        final JPanel reqDataPanel = new VerticalPanel();
159
        reqDataPanel.add(reqLabel, BorderLayout.WEST);
232
        reqDataPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("tcp_request_data"))); // $NON-NLS-1$
160
        reqDataPanel.add(requestData, BorderLayout.CENTER);
233
        reqDataPanel.add(requestData);
161
        return reqDataPanel;
234
        return reqDataPanel;
162
    }
235
    }
163
236
Lines 192-203 Link Here
192
        mainPanel.add(serverPanel);
265
        mainPanel.add(serverPanel);
193
        
266
        
194
        HorizontalPanel optionsPanel = new HorizontalPanel();
267
        HorizontalPanel optionsPanel = new HorizontalPanel();
195
        optionsPanel.add(createClosePortPanel());
268
        if (displayOptionsPanelForSampler) {
196
        optionsPanel.add(createNoDelayPanel());
269
            optionsPanel.add(createClosePortPanel());
270
            optionsPanel.add(createCloseConnectionPanel());
271
            optionsPanel.add(createNoDelayPanel());
272
        }else{
273
            optionsPanel.add(createSoLingerPanel());
274
            optionsPanel.add(createEolBytePanel());
275
        }
197
        mainPanel.add(optionsPanel);
276
        mainPanel.add(optionsPanel);
198
        mainPanel.add(createRequestPanel());
277
        mainPanel.add(createRequestPanel());
199
278
200
        // mainPanel.add(createFilenamePanel());
279
        // mainPanel.add(createFilenamePanel());
201
        add(mainPanel, BorderLayout.CENTER);
280
        add(mainPanel, BorderLayout.CENTER);
202
    }
281
    }
282
203
}
283
}
(-)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 / +50 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 SO_LINGER_TIMEOUT = "TCPSampler.soLingerTimeout"; //$NON-NLS-1$
91
    
92
    public static final String EOL_BYTE = "TCPSampler.EolByte"; //$NON-NLS-1$
85
    //-- JMX file constants - do not change
93
    //-- JMX file constants - do not change
86
94
87
    private static final String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap
95
    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)
176
                closeSocket(socketKey); // Bug 44910 - close previous socket (if any)
169
                SocketAddress sockaddr = new InetSocketAddress(getServer(), getPort());
177
                SocketAddress sockaddr = new InetSocketAddress(getServer(), getPort());
170
                con = new Socket();
178
                con = new Socket();
179
                if(isSoLinger()){
180
                	con.setSoLinger(isSoLinger(), getSoLingerTimeut());
181
                }
171
                con.connect(sockaddr, getConnectTimeout());
182
                con.connect(sockaddr, getConnectTimeout());
172
                if(log.isDebugEnabled()) {
183
                if(log.isDebugEnabled()) {
173
                    log.debug("Created new connection " + con); //$NON-NLS-1$
184
                    log.debug("Created new connection " + con); //$NON-NLS-1$
Lines 227-232 Link Here
227
    public boolean isReUseConnection() {
238
    public boolean isReUseConnection() {
228
        return getPropertyAsBoolean(RE_USE_CONNECTION);
239
        return getPropertyAsBoolean(RE_USE_CONNECTION);
229
    }
240
    }
241
    
242
    public void setCloseConnection(String close) {
243
    	this.setProperty(CLOSE_CONNECTION, close);
244
    }
245
    
246
    public boolean isCloseConnection() {
247
    	return getPropertyAsBoolean(CLOSE_CONNECTION);
248
    }
249
    
250
    public void setSoLinger(String soLinger) {
251
    	this.setProperty(SO_LINGER, soLinger);
252
    }
253
    
254
    public boolean isSoLinger() {
255
    	return getPropertyAsBoolean(SO_LINGER);
256
    }
257
    
258
    public void setSoLingerTimeout(String soLingerTimeout) {
259
    	this.setProperty(SO_LINGER_TIMEOUT, soLingerTimeout, "");
260
    }
261
    
262
    public int getSoLingerTimeut() {
263
    	return getPropertyAsInt(SO_LINGER_TIMEOUT,0);
264
    }
265
    
266
    public void setEolByte(String eol) {
267
        this.setProperty(EOL_BYTE, eol);
268
    }
269
    
270
    public int getEolByte() {
271
        return getPropertyAsInt(EOL_BYTE);
272
    }
273
    
230
274
231
    public void setPort(String newFilename) {
275
    public void setPort(String newFilename) {
232
        this.setProperty(PORT, newFilename);
276
        this.setProperty(PORT, newFilename);
Lines 323-328 Link Here
323
        }
367
        }
324
        try {
368
        try {
325
            TCPClient = (TCPClient) javaClass.newInstance();
369
            TCPClient = (TCPClient) javaClass.newInstance();
370
            if (!"".equals(getPropertyAsString(EOL_BYTE,""))){
371
                TCPClient.setEolByte(getEolByte());
372
                log.info("Using eolByte=" + getEolByte());
373
            }
374
326
            if (log.isDebugEnabled()) {
375
            if (log.isDebugEnabled()) {
327
                log.debug(this + "Created: " + getClassname() + "@" + Integer.toHexString(TCPClient.hashCode())); //$NON-NLS-1$
376
                log.debug(this + "Created: " + getClassname() + "@" + Integer.toHexString(TCPClient.hashCode())); //$NON-NLS-1$
328
            }
377
            }
Lines 381-387 Link Here
381
            // Set if we were successful or not
430
            // Set if we were successful or not
382
            res.setSuccessful(isSuccessful);
431
            res.setSuccessful(isSuccessful);
383
432
384
            if (!isReUseConnection()) {
433
            if (!isReUseConnection() || isCloseConnection()) {
385
                closeSocket(socketKey);
434
                closeSocket(socketKey);
386
            }
435
            }
387
        }
436
        }

Return to bug 54230