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

(-)xdocs/usermanual/component_reference.xml (-1 / +9 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>
1335
  <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>
1336
  <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>
1332
  <property name="Connect Timeout" required="No">Connect Timeout (milliseconds, 0 disables).</property>
1337
  <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>
1338
  <property name="Response Timeout" required="No">Response Timeout (milliseconds, 0 disables).</property>
1334
  <property name="Set Nodelay" required="Yes">See java.net.Socket.setTcpNoDelay().
1339
  <property name="Set Nodelay" required="Yes">See java.net.Socket.setTcpNoDelay().
Lines 3740-3745 Link Here
3740
  <property name="ServerName or IP" required="">Name or IP of TCP server</property>
3745
  <property name="ServerName or IP" required="">Name or IP of TCP server</property>
3741
  <property name="Port Number" required="">Port to be used</property>
3746
  <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>
3747
  <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>
3748
  <property name="Close connection" required="Yes">If selected, the connection will be closed after running the sampler.</property>  
3749
  <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>
3750
  <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>
3751
  <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>
3752
  <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>
3753
  <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 (-6 / +79 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.FlowLayout;
24
import java.awt.event.ItemEvent;
25
import java.awt.event.ItemListener;
22
26
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-54 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;
Lines 81-86 Link Here
81
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
92
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
82
        setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
93
        setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
83
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
94
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
95
        closeConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.CLOSE_CONNECTION, false));
96
        soLinger.setText(element.getPropertyAsString(TCPSampler.SO_LINGER));
97
        eolByte.setText(element.getPropertyAsString(TCPSampler.EOL_BYTE));
84
    }
98
    }
85
99
86
    @Override
100
    @Override
Lines 108-113 Link Here
108
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
122
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
109
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(),"");
123
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(),"");
110
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
124
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
125
        element.setProperty(TCPSampler.CLOSE_CONNECTION, closeConnection.isSelected());
126
        element.setProperty(TCPSampler.SO_LINGER, soLinger.getText());
127
        element.setProperty(TCPSampler.EOL_BYTE, eolByte.getText());
111
    }
128
    }
112
129
113
    /**
130
    /**
Lines 122-127 Link Here
122
        requestData.setText(""); //$NON-NLS-1$
139
        requestData.setText(""); //$NON-NLS-1$
123
        reUseConnection.setSelected(true);
140
        reUseConnection.setSelected(true);
124
        setNoDelay.setSelected(false);
141
        setNoDelay.setSelected(false);
142
        closeConnection.setSelected(false);
143
        soLinger.setText(""); //$NON-NLS-1$
144
        eolByte.setText(""); //$NON-NLS-1$
125
    }
145
    }
126
146
127
147
Lines 131-139 Link Here
131
        setNoDelay = new JCheckBox();
151
        setNoDelay = new JCheckBox();
132
        label.setLabelFor(setNoDelay);
152
        label.setLabelFor(setNoDelay);
133
153
134
        JPanel nodelayPanel = new JPanel(new BorderLayout(5, 0));
154
        JPanel nodelayPanel = new JPanel(new FlowLayout());
135
        nodelayPanel.add(label, BorderLayout.WEST);
155
        nodelayPanel.add(label);
136
        nodelayPanel.add(setNoDelay, BorderLayout.CENTER);
156
        nodelayPanel.add(setNoDelay);
137
        return nodelayPanel;
157
        return nodelayPanel;
138
    }
158
    }
139
159
Lines 141-153 Link Here
141
        JLabel label = new JLabel(JMeterUtils.getResString("reuseconnection")); //$NON-NLS-1$
161
        JLabel label = new JLabel(JMeterUtils.getResString("reuseconnection")); //$NON-NLS-1$
142
162
143
        reUseConnection = new JCheckBox("", true);
163
        reUseConnection = new JCheckBox("", true);
164
        reUseConnection.addItemListener(new ItemListener() {
165
            @Override
166
            public void itemStateChanged(final ItemEvent e) {
167
                if (e.getStateChange() == ItemEvent.SELECTED) {
168
                    closeConnection.setEnabled(true);
169
                } else {
170
                    closeConnection.setEnabled(false);
171
                    closeConnection.setSelected(true);
172
                }
173
            }
174
        });
144
        label.setLabelFor(reUseConnection);
175
        label.setLabelFor(reUseConnection);
145
176
146
        JPanel closePortPanel = new JPanel(new BorderLayout(5, 0));
177
        JPanel closePortPanel = new JPanel(new FlowLayout());
147
        closePortPanel.add(label, BorderLayout.WEST);
178
        closePortPanel.add(label);
148
        closePortPanel.add(reUseConnection, BorderLayout.CENTER);
179
        closePortPanel.add(reUseConnection);
149
        return closePortPanel;
180
        return closePortPanel;
150
    }
181
    }
182
    
183
    private JPanel createCloseConnectionPanel() {
184
        JLabel label = new JLabel(JMeterUtils.getResString("closeconnection")); // $NON-NLS-1$
185
186
        closeConnection = new JCheckBox("", false);
187
        label.setLabelFor(closeConnection);
188
189
        JPanel closeConnectionPanel = new JPanel(new FlowLayout());
190
        closeConnectionPanel.add(label);
191
        closeConnectionPanel.add(closeConnection);
192
        return closeConnectionPanel;
193
    }
194
195
    private JPanel createSoLingerOption() {
196
        JLabel label = new JLabel(JMeterUtils.getResString("solinger")); //$NON-NLS-1$ 
197
        
198
        soLinger = new JTextField(5); // 5 columns size
199
        soLinger.setMaximumSize(new Dimension(soLinger.getPreferredSize()));
200
        label.setLabelFor(soLinger);
201
        
202
        JPanel soLingerPanel = new JPanel(new FlowLayout());
203
        soLingerPanel.add(label);
204
        soLingerPanel.add(soLinger);
205
        return soLingerPanel;
206
    }
207
    
208
    private JPanel createEolBytePanel() {
209
        JLabel label = new JLabel(JMeterUtils.getResString("eolbyte")); //$NON-NLS-1$ 
210
        
211
        eolByte = new JTextField(3); // 3 columns size
212
        eolByte.setMaximumSize(new Dimension(eolByte.getPreferredSize()));
213
        label.setLabelFor(eolByte);
214
        
215
        JPanel eolBytePanel = new JPanel(new FlowLayout());
216
        eolBytePanel.add(label);
217
        eolBytePanel.add(eolByte);
218
        return eolBytePanel;
219
    }
151
220
152
    private JPanel createRequestPanel() {
221
    private JPanel createRequestPanel() {
153
        JLabel reqLabel = new JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$
222
        JLabel reqLabel = new JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$
Lines 193-203 Link Here
193
        
262
        
194
        HorizontalPanel optionsPanel = new HorizontalPanel();
263
        HorizontalPanel optionsPanel = new HorizontalPanel();
195
        optionsPanel.add(createClosePortPanel());
264
        optionsPanel.add(createClosePortPanel());
265
        optionsPanel.add(createCloseConnectionPanel());
196
        optionsPanel.add(createNoDelayPanel());
266
        optionsPanel.add(createNoDelayPanel());
267
        optionsPanel.add(createSoLingerOption());
268
        optionsPanel.add(createEolBytePanel());
197
        mainPanel.add(optionsPanel);
269
        mainPanel.add(optionsPanel);
198
        mainPanel.add(createRequestPanel());
270
        mainPanel.add(createRequestPanel());
199
271
200
        // mainPanel.add(createFilenamePanel());
272
        // mainPanel.add(createFilenamePanel());
201
        add(mainPanel, BorderLayout.CENTER);
273
        add(mainPanel, BorderLayout.CENTER);
202
    }
274
    }
275
203
}
276
}
(-)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