001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.http.control;
020:
021: import org.apache.jmeter.config.ConfigElement;
022: import org.apache.jmeter.control.GenericController;
023: import org.apache.jmeter.testelement.property.IntegerProperty;
024: import org.apache.jmeter.util.JMeterUtils;
025:
026: //For unit tests, @see TestHttpMirrorControl
027:
028: public class HttpMirrorControl extends GenericController {
029:
030: private transient HttpMirrorServer server;
031:
032: private static final int DEFAULT_PORT = 8080;
033:
034: // and as a string
035: public static final String DEFAULT_PORT_S = Integer
036: .toString(DEFAULT_PORT);// Used by GUI
037:
038: public static final String PORT = "HttpMirrorControlGui.port"; // $NON-NLS-1$
039:
040: public HttpMirrorControl() {
041: initPort(DEFAULT_PORT);
042: }
043:
044: public HttpMirrorControl(int port) {
045: initPort(port);
046: }
047:
048: private void initPort(int port) {
049: setProperty(new IntegerProperty(PORT, port));
050: }
051:
052: public void setPort(int port) {
053: initPort(port);
054: }
055:
056: public void setPort(String port) {
057: setProperty(PORT, port);
058: }
059:
060: public String getClassLabel() {
061: return JMeterUtils.getResString("httpmirror_title"); //$NON-NLS-1$
062: }
063:
064: public int getPort() {
065: return getPropertyAsInt(PORT);
066: }
067:
068: public String getPortString() {
069: return getPropertyAsString(PORT);
070: }
071:
072: public int getDefaultPort() {
073: return DEFAULT_PORT;
074: }
075:
076: public Class getGuiClass() {
077: return org.apache.jmeter.protocol.http.control.gui.HttpMirrorControlGui.class;
078: }
079:
080: public void addConfigElement(ConfigElement config) {
081: }
082:
083: public void startHttpMirror() {
084: server = new HttpMirrorServer(getPort());
085: server.start();
086: }
087:
088: public void stopHttpMirror() {
089: if (server != null) {
090: server.stopServer();
091: try {
092: server.join(1000); // wait for server to stop
093: } catch (InterruptedException e) {
094: }
095: server = null;
096: }
097: }
098:
099: public boolean canRemove() {
100: return null == server;
101: }
102:
103: public boolean isServerAlive() {
104: return server != null && server.isAlive();
105: }
106: }
|