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