KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > modifier > UserSequence


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/modifier/UserSequence.java,v 1.6 2004/02/12 00:29:49 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
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: 1.6 $
36  */

37 public class UserSequence implements Serializable JavaDoc
38 {
39     transient private static Logger log = LoggingManager.getLoggerForClass();
40
41     //-------------------------------------------
42
// Constants and Data Members
43
//-------------------------------------------
44
private List JavaDoc allUsers;
45     private Iterator JavaDoc indexOfUsers;
46
47     //-------------------------------------------
48
// Constructors
49
//-------------------------------------------
50

51     public UserSequence()
52     {
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 JavaDoc allUsers)
62     {
63         this.allUsers = allUsers;
64
65         // initalise pointer to first user
66
indexOfUsers = allUsers.iterator();
67     }
68
69     //-------------------------------------------
70
// Methods
71
//-------------------------------------------
72

73     /**
74      * Returns the parameter data for the next user in the sequence
75      * @return a Map object of parameter names and matching parameter
76      * values for the next user
77      */

78     public synchronized Map JavaDoc getNextUserMods()
79     {
80         // Use round robin allocation of user details
81
if (!indexOfUsers.hasNext())
82         {
83             indexOfUsers = allUsers.iterator();
84         }
85
86         Map JavaDoc user;
87         if (indexOfUsers.hasNext())
88         {
89             user = (Map JavaDoc) indexOfUsers.next();
90             log.debug(
91                 "UserSequence.getNextuserMods(): current parameters will be "
92                     + "changed to: "
93                     + user);
94         }
95         else
96         {
97             // no entries in all users, therefore create an empty Map object
98
user = new HashMap JavaDoc();
99         }
100
101         return user;
102     }
103 }
104
Popular Tags