01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.protocol.http.modifier;
20:
21: import java.io.Serializable;
22: import java.util.HashMap;
23: import java.util.Iterator;
24: import java.util.List;
25: import java.util.Map;
26:
27: import org.apache.jorphan.logging.LoggingManager;
28: import org.apache.log.Logger;
29:
30: /**
31: * This module controls the Sequence in which user details are returned. This
32: * module uses round robin allocation of users.
33: *
34: * @author Mark Walsh
35: * @version $Revision: 493789 $
36: */
37: public class UserSequence implements Serializable {
38: private static final Logger log = LoggingManager
39: .getLoggerForClass();
40:
41: // -------------------------------------------
42: // Constants and Data Members
43: // -------------------------------------------
44: private List allUsers;
45:
46: private transient Iterator indexOfUsers;
47:
48: // -------------------------------------------
49: // Constructors
50: // -------------------------------------------
51:
52: public UserSequence() {
53: }
54:
55: /**
56: * Load all user and parameter data into the sequence module.
57: * <P>
58: * ie a Set of Mapped "parameter names and parameter values" for each user
59: * to be loaded into the sequencer.
60: */
61: public UserSequence(List allUsers) {
62: this .allUsers = allUsers;
63:
64: // initalise pointer to first user
65: indexOfUsers = allUsers.iterator();
66: }
67:
68: // -------------------------------------------
69: // Methods
70: // -------------------------------------------
71:
72: /**
73: * Returns the parameter data for the next user in the sequence
74: *
75: * @return a Map object of parameter names and matching parameter values for
76: * the next user
77: */
78: public synchronized Map getNextUserMods() {
79: // Use round robin allocation of user details
80: if (!indexOfUsers.hasNext()) {
81: indexOfUsers = allUsers.iterator();
82: }
83:
84: Map user;
85: if (indexOfUsers.hasNext()) {
86: user = (Map) indexOfUsers.next();
87: log
88: .debug("UserSequence.getNextuserMods(): current parameters will be "
89: + "changed to: " + user);
90: } else {
91: // no entries in all users, therefore create an empty Map object
92: user = new HashMap();
93: }
94:
95: return user;
96: }
97: }
|