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 (-32 / +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.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-58 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 HorizontalPanel optionsPanel;
68
    
56
    public TCPConfigGui() {
69
    public TCPConfigGui() {
57
        this(true);
70
        this(true);
58
    }
71
    }
Lines 73-86 Link Here
73
        // N.B. this will be a config element, so we cannot use the getXXX() methods
86
        // N.B. this will be a config element, so we cannot use the getXXX() methods
74
        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
87
        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
75
        serverPanel.setServer(element.getPropertyAsString(TCPSampler.SERVER));
88
        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));
89
        serverPanel.setPort(element.getPropertyAsString(TCPSampler.PORT));
79
        // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
90
        // filename.setText(element.getPropertyAsString(TCPSampler.FILENAME));
80
        serverPanel.setResponseTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT));
91
        serverPanel.setResponseTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT));
81
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
92
        serverPanel.setConnectTimeout(element.getPropertyAsString(TCPSampler.TIMEOUT_CONNECT));
82
        setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
83
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
93
        requestData.setText(element.getPropertyAsString(TCPSampler.REQUEST));
94
95
        // Default to original behaviour, i.e. re-use connection
96
        reUseConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.RE_USE_CONNECTION, true));
97
        closeConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.CLOSE_CONNECTION, false));
98
        setNoDelay.setSelected(element.getPropertyAsBoolean(TCPSampler.NODELAY));
99
        soLinger.setText(element.getPropertyAsString(TCPSampler.SO_LINGER));
100
        eolByte.setText(element.getPropertyAsString(TCPSampler.EOL_BYTE));
84
    }
101
    }
85
102
86
    @Override
103
    @Override
Lines 101-113 Link Here
101
        // N.B. this will be a config element, so we cannot use the setXXX() methods
118
        // N.B. this will be a config element, so we cannot use the setXXX() methods
102
        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
119
        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
103
        element.setProperty(TCPSampler.SERVER, serverPanel.getServer());
120
        element.setProperty(TCPSampler.SERVER, serverPanel.getServer());
104
        element.setProperty(TCPSampler.RE_USE_CONNECTION, reUseConnection.isSelected());
105
        element.setProperty(TCPSampler.PORT, serverPanel.getPort());
121
        element.setProperty(TCPSampler.PORT, serverPanel.getPort());
106
        // element.setProperty(TCPSampler.FILENAME, filename.getText());
122
        // element.setProperty(TCPSampler.FILENAME, filename.getText());
107
        element.setProperty(TCPSampler.NODELAY, setNoDelay.isSelected());
108
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
123
        element.setProperty(TCPSampler.TIMEOUT, serverPanel.getResponseTimeout());
109
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(),"");
124
        element.setProperty(TCPSampler.TIMEOUT_CONNECT, serverPanel.getConnectTimeout(), "");
110
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
125
        element.setProperty(TCPSampler.REQUEST, requestData.getText());
126
127
        element.setProperty(TCPSampler.RE_USE_CONNECTION, reUseConnection.isSelected());
128
        element.setProperty(TCPSampler.CLOSE_CONNECTION, closeConnection.isSelected());
129
        element.setProperty(TCPSampler.NODELAY, setNoDelay.isSelected());
130
        element.setProperty(TCPSampler.SO_LINGER, soLinger.getText());
131
        element.setProperty(TCPSampler.EOL_BYTE, eolByte.getText());
111
    }
132
    }
112
133
113
    /**
134
    /**
Lines 121-163 Link Here
121
        classname.setText(""); //$NON-NLS-1$
142
        classname.setText(""); //$NON-NLS-1$
122
        requestData.setText(""); //$NON-NLS-1$
143
        requestData.setText(""); //$NON-NLS-1$
123
        reUseConnection.setSelected(true);
144
        reUseConnection.setSelected(true);
145
        closeConnection.setSelected(false);
124
        setNoDelay.setSelected(false);
146
        setNoDelay.setSelected(false);
147
        soLinger.setText(""); //$NON-NLS-1$
148
        eolByte.setText(""); //$NON-NLS-1$
125
    }
149
    }
126
150
127
151
    private void addNoDelayOption() {
128
    private JPanel createNoDelayPanel() {
152
        setNoDelay = new JCheckBox(JMeterUtils.getResString("tcp_nodelay")); // $NON-NLS-1$
129
        JLabel label = new JLabel(JMeterUtils.getResString("tcp_nodelay")); // $NON-NLS-1$
153
        optionsPanel.add(setNoDelay);
154
    }
130
155
131
        setNoDelay = new JCheckBox();
156
    private void addClosePortOption() {
132
        label.setLabelFor(setNoDelay);
157
        reUseConnection = new JCheckBox(JMeterUtils.getResString("reuseconnection"), true); //$NON-NLS-1$
158
        reUseConnection.addItemListener(new ItemListener() {
159
            @Override
160
            public void itemStateChanged(final ItemEvent e) {
161
                if (e.getStateChange() == ItemEvent.SELECTED) {
162
                    closeConnection.setEnabled(true);
163
                } else {
164
                    closeConnection.setEnabled(false);
165
                    closeConnection.setSelected(true);
166
                }
167
            }
168
        });
133
169
134
        JPanel nodelayPanel = new JPanel(new BorderLayout(5, 0));
170
        optionsPanel.add(reUseConnection);
135
        nodelayPanel.add(label, BorderLayout.WEST);
136
        nodelayPanel.add(setNoDelay, BorderLayout.CENTER);
137
        return nodelayPanel;
138
    }
171
    }
139
172
140
    private JPanel createClosePortPanel() {
173
    private void addCloseConnectionOption() {
141
        JLabel label = new JLabel(JMeterUtils.getResString("reuseconnection")); //$NON-NLS-1$
174
        closeConnection = new JCheckBox(JMeterUtils.getResString("closeconnection"), false); //$NON-NLS-1$
142
175
        optionsPanel.add(closeConnection);
143
        reUseConnection = new JCheckBox("", true);
176
    }
144
        label.setLabelFor(reUseConnection);
145
177
146
        JPanel closePortPanel = new JPanel(new BorderLayout(5, 0));
178
    private void addSoLingerOption() {
147
        closePortPanel.add(label, BorderLayout.WEST);
179
        JLabel soLingerLable = new JLabel(JMeterUtils.getResString("solinger")); //$NON-NLS-1$ 
148
        closePortPanel.add(reUseConnection, BorderLayout.CENTER);
180
        soLinger = new JTextField(5); // 5 columns size
149
        return closePortPanel;
181
        soLinger.setMaximumSize(new Dimension(50, 20));
182
        soLingerLable.setLabelFor(soLinger);
183
        optionsPanel.add(soLingerLable);
184
        optionsPanel.add(soLinger);
185
    }
186
    
187
    private void addEolByteOption() {
188
        JLabel eolByteLabel = new JLabel(JMeterUtils.getResString("eolbyte")); //$NON-NLS-1$ 
189
        eolByte = new JTextField(3); // 3 columns size
190
        eolByte.setMaximumSize(new Dimension(30, 20));
191
        eolByteLabel.setLabelFor(eolByte);
192
        optionsPanel.add(eolByteLabel);
193
        optionsPanel.add(eolByte);
150
    }
194
    }
151
195
152
    private JPanel createRequestPanel() {
196
    private JPanel createRequestPanel() {
153
        JLabel reqLabel = new JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$
154
        requestData = new JTextArea(3, 0);
197
        requestData = new JTextArea(3, 0);
155
        requestData.setLineWrap(true);
198
        requestData.setLineWrap(true);
156
        reqLabel.setLabelFor(requestData);
157
199
158
        JPanel reqDataPanel = new JPanel(new BorderLayout(5, 0));
200
        final JPanel reqDataPanel = new VerticalPanel();
159
        reqDataPanel.add(reqLabel, BorderLayout.WEST);
201
        reqDataPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("tcp_request_data"))); // $NON-NLS-1$
160
        reqDataPanel.add(requestData, BorderLayout.CENTER);
202
        reqDataPanel.add(requestData);
161
        return reqDataPanel;
203
        return reqDataPanel;
162
    }
204
    }
163
205
Lines 191-203 Link Here
191
        mainPanel.add(classname);
233
        mainPanel.add(classname);
192
        mainPanel.add(serverPanel);
234
        mainPanel.add(serverPanel);
193
        
235
        
194
        HorizontalPanel optionsPanel = new HorizontalPanel();
236
        optionsPanel = new HorizontalPanel();
195
        optionsPanel.add(createClosePortPanel());
237
        addClosePortOption();
196
        optionsPanel.add(createNoDelayPanel());
238
        addCloseConnectionOption();
239
        addNoDelayOption();
240
        addSoLingerOption();
241
        addEolByteOption();
242
        
197
        mainPanel.add(optionsPanel);
243
        mainPanel.add(optionsPanel);
198
        mainPanel.add(createRequestPanel());
244
        mainPanel.add(createRequestPanel());
199
245
200
        // mainPanel.add(createFilenamePanel());
246
        // mainPanel.add(createFilenamePanel());
201
        add(mainPanel, BorderLayout.CENTER);
247
        add(mainPanel, BorderLayout.CENTER);
202
    }
248
    }
249
203
}
250
}
(-)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