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.engine;
020:
021: import java.rmi.RemoteException;
022: import java.util.Iterator;
023:
024: import org.apache.jmeter.samplers.RemoteListenerWrapper;
025: import org.apache.jmeter.samplers.RemoteSampleListener;
026: import org.apache.jmeter.samplers.RemoteSampleListenerImpl;
027: import org.apache.jmeter.samplers.RemoteSampleListenerWrapper;
028: import org.apache.jmeter.samplers.RemoteTestListenerWrapper;
029: import org.apache.jmeter.samplers.Remoteable;
030: import org.apache.jmeter.samplers.SampleListener;
031: import org.apache.jmeter.testelement.TestListener;
032: import org.apache.jmeter.threads.ThreadGroup;
033: import org.apache.jorphan.collections.HashTree;
034: import org.apache.jorphan.collections.HashTreeTraverser;
035: import org.apache.jorphan.logging.LoggingManager;
036: import org.apache.log.Logger;
037:
038: /**
039: * @author mstover
040: */
041: public class ConvertListeners implements HashTreeTraverser {
042: private static final Logger log = LoggingManager
043: .getLoggerForClass();
044:
045: /*
046: * (non-Javadoc)
047: *
048: * @see HashTreeTraverser#addNode(Object, HashTree)
049: */
050: public void addNode(Object node, HashTree subTree) {
051: Iterator iter = subTree.list().iterator();
052: while (iter.hasNext()) {
053: Object item = iter.next();
054: if (item instanceof ThreadGroup) {
055: log.info("num threads = "
056: + ((ThreadGroup) item).getNumThreads());
057: }
058: if (item instanceof Remoteable
059: && (item instanceof TestListener || item instanceof SampleListener)) {
060: try {
061: RemoteSampleListener rtl = new RemoteSampleListenerImpl(
062: item);
063: if (item instanceof TestListener
064: && item instanceof SampleListener) {
065: RemoteListenerWrapper wrap = new RemoteListenerWrapper(
066: rtl);
067: subTree.replace(item, wrap);
068: } else if (item instanceof TestListener) {
069: RemoteTestListenerWrapper wrap = new RemoteTestListenerWrapper(
070: rtl);
071: subTree.replace(item, wrap);
072: } else {
073: RemoteSampleListenerWrapper wrap = new RemoteSampleListenerWrapper(
074: rtl);
075: subTree.replace(item, wrap);
076: }
077: } catch (RemoteException e) {
078: log.error("", e); // $NON-NLS-1$
079: }
080: }
081: }
082: }
083:
084: /*
085: * (non-Javadoc)
086: *
087: * @see HashTreeTraverser#subtractNode()
088: */
089: public void subtractNode() {
090: }
091:
092: /*
093: * (non-Javadoc)
094: *
095: * @see HashTreeTraverser#processPath()
096: */
097: public void processPath() {
098: }
099:
100: }
|